示例#1
0
文件: scn.py 项目: titourreta/ktm
def modify_vehicle_file(gen, search_path, mas_files, vehdir, teamdir):
    strio = io.StringIO()
    sr_parser = rfactortools.SearchReplaceScnParser(strio)
    sr_parser.mas_files = mas_files
    sr_parser.search_path = search_path
    rfactortools.process_scnfile(gen, sr_parser)

    with open(gen, "wt", encoding="latin-1", newline='\r\n', errors="replace") as fout:
        fout.write(strio.getvalue())
示例#2
0
def process_gdb_file(gdb, fix, errors, fout):
    scn = os.path.splitext(gdb)[0] + ".scn"

    info = rfactortools.InfoScnParser()
    rfactortools.process_scnfile(scn, info)

    fout.write("[Track]\n")
    fout.write("  gdb: %s\n" % gdb)
    fout.write("  scn: %s\n" % scn)
    fout.write("  SearchPath: %s\n" % info.search_path)
    fout.write("    MasFiles: %s\n" % info.mas_files)
    fout.write("\n")
示例#3
0
def process_scn_veh_file(modname, veh_filename, scn_short_filename, vehdir, teamdir, fix, errors, fout):
    # resolve scn_filename to a proper path
    scn_filename = find_file_backwards(os.path.dirname(veh_filename), scn_short_filename)
    if not scn_filename:
        raise Exception("error: couldn't find .gen file '%s' '%s'" % (veh_filename, scn_short_filename))

    fout.write("gen: %s\n" % scn_filename)

    info = rfactortools.InfoScnParser()
    rfactortools.process_scnfile(scn_filename, info)

    fout.write("  SearchPath: %s\n" % info.search_path)
    fout.write("    MasFiles: %s\n" % info.mas_files)
    fout.write("\n")

    if not fix:
        orig_errs, orig_warns = rfactortools.gen_check_errors(info.search_path, info.mas_files, vehdir, teamdir, fout)
        append_errors(scn_filename, orig_errs, orig_warns, errors)
    else:
        # if there is a cmaps in the mod, use that instead of the one in <VEHDIR>
        cmaps = rfactortools.find_file(os.path.join(vehdir, modname), "cmaps.mas")
        if cmaps:
            cmaps = os.path.relpath(cmaps, vehdir)
            for i, m in enumerate(info.mas_files):
                if m.lower() == "cmaps.mas":
                    info.mas_files[i] = cmaps

        orig_errs, orig_warns = rfactortools.gen_check_errors(info.search_path, info.mas_files, vehdir, teamdir, fout)

        if orig_errs:
            # add modname to the SearchPath to avoid errors
            search_path = [re.sub(r'<VEHDIR>', r'<VEHDIR>/%s' % modname, p) for p in info.search_path]

            rel_teamdir = os.path.relpath(teamdir, vehdir)
            while rel_teamdir:
                search_path.append(os.path.join("<VEHDIR>", rel_teamdir))
                rel_teamdir = os.path.dirname(rel_teamdir)
            search_path.append("<VEHDIR>")
        else:
            search_path = info.search_path

        # make list items unique
        search_path = sorted(set(search_path))

        new_errs, new_warns = rfactortools.gen_check_errors(search_path, info.mas_files, vehdir, teamdir, fout)

        append_errors(scn_filename, new_errs, new_warns, errors)

        # write a new file if there are no or less errors
        if not new_errs or len(new_errs) < len(orig_errs):
            rfactortools.modify_vehicle_file(scn_filename, search_path, info.mas_files, vehdir, teamdir)
        elif cmaps:
            rfactortools.modify_vehicle_file(scn_filename, info.search_path, info.mas_files, vehdir, teamdir)
示例#4
0
def find_track_directory(gdb_filename):
    rest, ext = os.path.splitext(gdb_filename)
    scn_filename = rest + ".scn"
    scn_filename = rfactortools.lookup_path_icase(scn_filename)
    if not scn_filename:
        raise Exception("couldn't locate .scn file matching %s" % gdb_filename)
    else:
        info = rfactortools.InfoScnParser()
        rfactortools.process_scnfile(scn_filename, info)

        result = find_track_directory_from_searchpath(
            os.path.dirname(gdb_filename), info.search_path)
        return result
示例#5
0
def find_track_directory(gdb_filename):
    rest, ext = os.path.splitext(gdb_filename)
    scn_filename = rest + ".scn"
    scn_filename = rfactortools.lookup_path_icase(scn_filename)
    if not scn_filename:
        raise Exception("couldn't locate .scn file matching %s" % gdb_filename)
    else:
        info = rfactortools.InfoScnParser()
        rfactortools.process_scnfile(scn_filename, info)

        result = find_track_directory_from_searchpath(os.path.dirname(gdb_filename),
                                                      info.search_path)
        return result