Example #1
0
def main():
    parser = argparse.ArgumentParser(description="Race07 Tool")
    parser.add_argument('DIRECTORY',
                        action='store',
                        type=str,
                        help='directory containing .gen and .veh files')
    parser.add_argument('-c',
                        '--class-id',
                        action='store_true',
                        default=False,
                        help='list class ids')
    parser.add_argument('-m',
                        '--model-id',
                        action='store_true',
                        default=False,
                        help='list model ids')
    parser.add_argument('-i',
                        '--inverse',
                        action='store_true',
                        default=False,
                        help='list free ids, instead of occupied ones')
    args = parser.parse_args()

    if args.DIRECTORY:
        for fname in rfactortools.find_files(args.DIRECTORY):
            ext = os.path.splitext(fname)[1].lower()
            if ext == ".car" or ext == ".inccar":
                car = read_ids(fname)
                if not car.class_id and not car.model_id:
                    pass
                elif not car.class_id or not car.model_id:
                    print("%4s %4s %s" % (car.class_id, car.model_id, fname))
                else:
                    print("%4d %4d %s" % (car.class_id, car.model_id, fname))
Example #2
0
    def do_veh_check(self):
        path = self.target_directory.get()
        files = rfactortools.find_files(path, ".veh")
        vehs = [rfactortools.parse_vehfile(filename) for filename in files]

        sout = io.StringIO()
        rfactortools.print_veh_info(vehs, sout)

        self.app.show_text_window("rfactortools: .veh check", sout.getvalue())
Example #3
0
    def do_veh_check(self):
        path = self.target_directory.get()
        files = rfactortools.find_files(path, ".veh")
        vehs = [rfactortools.parse_vehfile(filename) for filename in files]

        sout = io.StringIO()
        rfactortools.print_veh_info(vehs, sout)

        self.app.show_text_window("rfactortools: .veh check", sout.getvalue())
Example #4
0
def process_directory(directory):
    for fname in rfactortools.find_files(directory):
        name, ext = os.path.splitext(fname)
        if ext.lower() == ".veh":
            img = os.path.join(name + "number.tga")
            if rfactortools.path_exists(img):
                rfactortools.resize_to_fit_img_file(img, 252, 64)

        elif ext.lower() == ".gdb":
            img = os.path.join(name + "mini.tga")
            if rfactortools.path_exists(img):
                rfactortools.resize_to_fit_img_file(img, 252, 249)
Example #5
0
def process_directory(directory):
    for fname in rfactortools.find_files(directory):
        name, ext = os.path.splitext(fname)
        if ext.lower() == ".veh":
            img = os.path.join(name + "number.tga")
            if rfactortools.path_exists(img):
                rfactortools.resize_to_fit_img_file(img, 252, 64)

        elif ext.lower() == ".gdb":
            img = os.path.join(name + "mini.tga")
            if rfactortools.path_exists(img):
                rfactortools.resize_to_fit_img_file(img, 252, 249)
Example #6
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    parser = argparse.ArgumentParser(description='rFactor .sfx processor')
    parser.add_argument('FILE', action='store', type=str, nargs='+',
                        help='.sfx file or directory containing .sfx files')
    parser.add_argument('-m', '--modify', action='store_true', default=False,
                        help="add PREFIX to the .wav path")
    parser.add_argument('-i', '--in-place', action='store_true', default=False,
                        help="overwrite origin files after changes")
    parser.add_argument('-b', '--backup', metavar='SUFFIX', type=str,
                        help="make backups by copying file to FILENAME+SUFFIX before changing")
    parser.add_argument('-g', '--gamedata', metavar='DIR', type=str,
                        help="Set GameData directory used for verification")
    args = parser.parse_args()

    files = []
    for path in args.FILE:
        if os.path.isdir(path):
            files += rfactortools.find_files(path, ".sfx")
        else:
            files.append(path)

    if args.gamedata:
        gamedata = args.gamedata
    else:
        gamedata = None

    if not args.modify:
        for filename in files:
            sfx = rfactortools.parse_sfxfile(filename)
            if gamedata:
                sfx.check(gamedata, "F1SR")
            else:
                for wav in sfx.wavs:
                    print(wav)
    else:
        if gamedata is None:
            raise Exception("--gamedata required")

        for filename in files:
            sout = io.StringIO()
            rfactortools.modify_sfxfile(sout, filename,
                                        lambda wav: rfactortools.try_fix_wav_path(gamedata, "F1SR", wav))

            if args.in_place:
                if args.backup:
                    os.rename(filename, filename + args.backup)
                with open(filename, "wt", newline='\r\n', encoding="latin-1", errors="replace") as fout:
                    fout.write(sout.getvalue())
            else:
                sys.stdout.write(sout.getvalue())
Example #7
0
def process_gen_directory(directory, fix, fout):
    gen_files = []
    veh_files = []
    gdb_files = []
    scn_files = []
    mas_files = []

    for fname in rfactortools.find_files(directory):
        ext = os.path.splitext(fname)[1].lower()
        if ext == ".gen":
            gen_files.append(fname)
        elif ext == ".veh":
            veh_files.append(fname)
        elif ext == ".scn":
            scn_files.append(fname)
        elif ext == ".gdb":
            gdb_files.append(fname)
        elif ext == ".mas":
            mas_files.append(fname)

    errors = []
    for gdb in sorted(gdb_files):
        try:
            rfactortools.process_gdb_file(gdb, fix, errors, fout)
        except Exception:
            e = traceback.format_exc()
            fout.write("error:\n%s\n\n" % e)
            errors.append(e)

    for veh in sorted(veh_files):
        try:
            rfactortools.process_veh_file(veh, fix, errors, fout)
        except Exception as e:
            e = traceback.format_exc()
            fout.write("raised error:\n%s\n\n" % e)
            errors.append(e)

    fout.write("[MASFiles]\n")
    for mas in sorted(mas_files):
        fout.write("  %s\n" % mas)
    fout.write("\n")

    if errors:
        fout.write("Error summary:\n")
        fout.write("==============\n")
        for e in errors:
            fout.write("error: %s\n" % e)
    else:
        fout.write("No errors\n")
Example #8
0
def main():
    parser = argparse.ArgumentParser(description="Race07 Tool")
    parser.add_argument('DIRECTORY', action='store', type=str,
                        help='directory containing .gen and .veh files')
    parser.add_argument('-c', '--class-id', action='store_true', default=False,
                        help='list class ids')
    parser.add_argument('-m', '--model-id', action='store_true', default=False,
                        help='list model ids')
    parser.add_argument('-i', '--inverse', action='store_true', default=False,
                        help='list free ids, instead of occupied ones')
    args = parser.parse_args()

    if args.DIRECTORY:
        for fname in rfactortools.find_files(args.DIRECTORY):
            ext = os.path.splitext(fname)[1].lower()
            if ext == ".car" or ext == ".inccar":
                car = read_ids(fname)
                if not car.class_id and not car.model_id:
                    pass
                elif not car.class_id or not car.model_id:
                    print("%4s %4s %s" % (car.class_id, car.model_id, fname))
                else:
                    print("%4d %4d %s" % (car.class_id, car.model_id, fname))
Example #9
0
import argparse
import os
import sys

import rfactortools


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='rFactor .veh/.gen processor')
    parser.add_argument('FILE', action='store', type=str, nargs='+',
                        help='.veh file or directory containing .veh files')
    parser.add_argument('-t', '--tree', action='store_true', default=False,
                        help="print tree")
    args = parser.parse_args()

    files = []
    for path in args.FILE:
        if os.path.isdir(path):
            files += rfactortools.find_files(path, ".veh")
        else:
            files.append(path)

    vehs = [rfactortools.parse_vehfile(filename) for filename in files]

    if args.tree:
        rfactortools.print_veh_tree(vehs, sys.stdout)
    else:
        rfactortools.print_veh_info(vehs, sys.stdout)

# EOF #
Example #10
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    parser = argparse.ArgumentParser(description='rFactor .sfx processor')
    parser.add_argument('FILE',
                        action='store',
                        type=str,
                        nargs='+',
                        help='.sfx file or directory containing .sfx files')
    parser.add_argument('-m',
                        '--modify',
                        action='store_true',
                        default=False,
                        help="add PREFIX to the .wav path")
    parser.add_argument('-i',
                        '--in-place',
                        action='store_true',
                        default=False,
                        help="overwrite origin files after changes")
    parser.add_argument(
        '-b',
        '--backup',
        metavar='SUFFIX',
        type=str,
        help="make backups by copying file to FILENAME+SUFFIX before changing")
    parser.add_argument('-g',
                        '--gamedata',
                        metavar='DIR',
                        type=str,
                        help="Set GameData directory used for verification")
    args = parser.parse_args()

    files = []
    for path in args.FILE:
        if os.path.isdir(path):
            files += rfactortools.find_files(path, ".sfx")
        else:
            files.append(path)

    if args.gamedata:
        gamedata = args.gamedata
    else:
        gamedata = None

    if not args.modify:
        for filename in files:
            sfx = rfactortools.parse_sfxfile(filename)
            if gamedata:
                sfx.check(gamedata, "F1SR")
            else:
                for wav in sfx.wavs:
                    print(wav)
    else:
        if gamedata is None:
            raise Exception("--gamedata required")

        for filename in files:
            sout = io.StringIO()
            rfactortools.modify_sfxfile(
                sout, filename, lambda wav: rfactortools.try_fix_wav_path(
                    gamedata, "F1SR", wav))

            if args.in_place:
                if args.backup:
                    os.rename(filename, filename + args.backup)
                with open(filename,
                          "wt",
                          newline='\r\n',
                          encoding="latin-1",
                          errors="replace") as fout:
                    fout.write(sout.getvalue())
            else:
                sys.stdout.write(sout.getvalue())