Пример #1
0
 def check(self, gamedata_directory, modname):
     for wav in self.wavs:
         p = os.path.join(gamedata_directory, "Sounds", wav)
         if rfactortools.file_exists(p):
             print("%s: ok" % wav)
         else:
             p = os.path.join(gamedata_directory, "Sounds", modname, wav)
             if rfactortools.file_exists(p):
                 print("%s: ok with fix" % wav)
             else:
                 print("%s: failure" % wav)
Пример #2
0
 def check(self, gamedata_directory, modname):
     for wav in self.wavs:
         p = os.path.join(gamedata_directory, "Sounds", wav)
         if rfactortools.file_exists(p):
             print("%s: ok" % wav)
         else:
             p = os.path.join(gamedata_directory, "Sounds", modname, wav)
             if rfactortools.file_exists(p):
                 print("%s: ok with fix" % wav)
             else:
                 print("%s: failure" % wav)
Пример #3
0
    def convert_tga(self, source_file, target_file):
        is_vehicle_thumbnail = bool(source_file.lower().endswith("number.tga") and
                                    rfactortools.file_exists(source_file[:-10] + ".veh"))

        is_track_thumbnail = bool(source_file.lower().endswith("mini.tga") and
                                  rfactortools.file_exists(source_file[:-8] + ".gdb"))

        if is_vehicle_thumbnail:
            rfactortools.resize_to_fit_img_file_with_target(source_file, target_file, 252, 64)
        elif is_track_thumbnail:
            if not self.cfg.force_track_thumbnails:
                rfactortools.resize_to_fit_img_file_with_target(source_file, target_file, 252, 249)
        else:
            shutil.copy(source_file, target_file)
Пример #4
0
def try_fix_wav_path(gamedata, modname, wav_file):
    """Return either ``None`` to change nothing or a new wav path"""
    p = os.path.join(gamedata, "Sounds", wav_file)
    if rfactortools.file_exists(p):
        logging.debug("%s: file ok", wav_file)
        return None
    else:
        p = os.path.join(gamedata, "Sounds", modname, wav_file)
        if rfactortools.file_exists(p):
            r = os.path.join(modname, wav_file)
            logging.debug("%s: file ok", r)
            return r
        else:
            logging.error("%s: couldn't locate file", wav_file)
            return None
Пример #5
0
def try_fix_wav_path(gamedata, modname, wav_file):
    """Return either ``None`` to change nothing or a new wav path"""
    p = os.path.join(gamedata, "Sounds", wav_file)
    if rfactortools.file_exists(p):
        logging.debug("%s: file ok", wav_file)
        return None
    else:
        p = os.path.join(gamedata, "Sounds", modname, wav_file)
        if rfactortools.file_exists(p):
            r = os.path.join(modname, wav_file)
            logging.debug("%s: file ok", r)
            return r
        else:
            logging.error("%s: couldn't locate file", wav_file)
            return None
Пример #6
0
def gen_check_errors(search_path, mas_files, vehdir, teamdir, fout):
    def expand_path(p):
        p = re.sub(r'<VEHDIR>', (vehdir + "/").replace("\\", "\\\\"), p)
        p = re.sub(r'<TEAMDIR>', (teamdir + "/").replace("\\", "\\\\"), p)
        return p

    expanded_search_path = [expand_path(d) for d in search_path]

    errors = []
    warnings = []

    for p, d in zip(search_path, expanded_search_path):
        if not rfactortools.directory_exists(d) and d != ".":
            fout.write("warning: couldn't locate SearchPath %s\n" % p)
            warnings.append("warning: couldn't locate SearchPath %s" % p)

    default_mas_files = ["cmaps.mas"]
    for mas in mas_files:
        mas_found = False
        for d in expanded_search_path:
            f = os.path.join(d, mas)
            if rfactortools.file_exists(f):
                mas_found = True
                break
        if not mas_found and mas.lower() not in default_mas_files:
            fout.write("error: couldn't locate %s\n" % mas)
            errors.append("error: couldn't locate %s" % mas)

    return errors, warnings
Пример #7
0
    def convert_gdb(self, filename, target_file):
        with rfactortools.open_read(filename) as fin:
            lines = fin.readlines()

        with open(target_file, "wt", newline='\r\n', encoding="latin-1", errors="replace") as fout:
            for line in lines:
                line = re.sub(r'Filter Properties *=.*',
                              r'Filter Properties = %s' % self.cfg.track_filter_properties,
                              line, flags=re.IGNORECASE)

                if self.cfg.track_category:
                    line = re.sub(r'^(\s*)VenueName\s*=\s*(.*)',
                                  r'\1VenueName = %s, \2' % self.cfg.track_category,
                                  line, flags=re.IGNORECASE)

                fout.write(line)

        if self.cfg.copy_missing_textures:
            missing_textures = ["racegroove.dds", "skidhard.dds",
                                "sky00.dds", "sky01.dds", "sky02.dds",
                                "sky03.dds", "sky04.dds"]

            for tex in missing_textures:
                source_tex_file = os.path.join("data", tex)
                target_tex_file = os.path.join(os.path.dirname(target_file), tex)

                if not rfactortools.file_exists(target_tex_file):
                    try:
                        shutil.copy(source_tex_file, target_tex_file)
                    except Exception:
                        logging.exception("%s: %s: rfactortools.convert_gdb texture copy failed",
                                          source_tex_file, target_tex_file)
Пример #8
0
    def convert_jpg(self, source_file, target_file):
        is_track_loading = bool(source_file.lower().endswith("_loading.jpg") and
                                rfactortools.file_exists(source_file[:-12] + ".gdb"))

        if is_track_loading:
            rfactortools.resize_to_file(source_file, target_file, [(1024, 768), (800, 600)])
        else:
            shutil.copy(source_file, target_file)
Пример #9
0
    def convert_tga(self, source_file, target_file):
        is_vehicle_thumbnail = bool(
            source_file.lower().endswith("number.tga")
            and rfactortools.file_exists(source_file[:-10] + ".veh"))

        is_track_thumbnail = bool(
            source_file.lower().endswith("mini.tga")
            and rfactortools.file_exists(source_file[:-8] + ".gdb"))

        if is_vehicle_thumbnail:
            rfactortools.resize_to_fit_img_file_with_target(
                source_file, target_file, 252, 64)
        elif is_track_thumbnail:
            if not self.cfg.force_track_thumbnails:
                rfactortools.resize_to_fit_img_file_with_target(
                    source_file, target_file, 252, 249)
        else:
            shutil.copy(source_file, target_file)
Пример #10
0
    def convert_jpg(self, source_file, target_file):
        is_track_loading = bool(
            source_file.lower().endswith("_loading.jpg")
            and rfactortools.file_exists(source_file[:-12] + ".gdb"))

        if is_track_loading:
            rfactortools.resize_to_file(source_file, target_file, [(1024, 768),
                                                                   (800, 600)])
        else:
            shutil.copy(source_file, target_file)
Пример #11
0
def find_file_backwards(directory, gen):
    while True:
        filename = os.path.join(directory, gen)
        if rfactortools.file_exists(filename):
            return filename

        newdir = os.path.dirname(directory)
        if newdir == directory:  # reached the root of the path
            return None
        else:
            directory = newdir
Пример #12
0
    def convert_gdb(self, filename, target_file):
        with rfactortools.open_read(filename) as fin:
            lines = fin.readlines()

        with open(target_file,
                  "wt",
                  newline='\r\n',
                  encoding="latin-1",
                  errors="replace") as fout:
            for line in lines:
                line = re.sub(r'Filter Properties *=.*',
                              r'Filter Properties = %s' %
                              self.cfg.track_filter_properties,
                              line,
                              flags=re.IGNORECASE)

                if self.cfg.track_category:
                    line = re.sub(r'^(\s*)VenueName\s*=\s*(.*)',
                                  r'\1VenueName = %s, \2' %
                                  self.cfg.track_category,
                                  line,
                                  flags=re.IGNORECASE)

                fout.write(line)

        if self.cfg.copy_missing_textures:
            missing_textures = [
                "racegroove.dds", "skidhard.dds", "sky00.dds", "sky01.dds",
                "sky02.dds", "sky03.dds", "sky04.dds"
            ]

            for tex in missing_textures:
                source_tex_file = os.path.join("data", tex)
                target_tex_file = os.path.join(os.path.dirname(target_file),
                                               tex)

                if not rfactortools.file_exists(target_tex_file):
                    try:
                        shutil.copy(source_tex_file, target_tex_file)
                    except Exception:
                        logging.exception(
                            "%s: %s: rfactortools.convert_gdb texture copy failed",
                            source_tex_file, target_tex_file)
Пример #13
0
 def convert_scn(self, source_file, target_file, modname):
     if rfactortools.file_exists(source_file[:-4] + ".gdb"):
         self.convert_track_scn(source_file, target_file, modname)
Пример #14
0
 def convert_scn(self, source_file, target_file, modname):
     if rfactortools.file_exists(source_file[:-4] + ".gdb"):
         self.convert_track_scn(source_file, target_file, modname)