Beispiel #1
0
        public static void Restart(string modPath)
        {
            Console.WriteLine($"[INFO] Restoring directory to original state...");
            // Just in case its missing for some reason
            Directory.CreateDirectory($@"{modPath}\data");
            // Clear data directory
            Parallel.ForEach(Directory.GetFiles($@"{modPath}\data"), file =>
            {
                // Delete if not found in Original
                if (!FileIOWrapper.Exists($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{Path.GetFileName(file)}"))
                {
                    Console.WriteLine($@"[INFO] Deleting {file}...");
                    try
                    {
                        FileIOWrapper.Delete(file);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"[ERROR] Couldn't delete {file} ({e.Message})");
                    }
                }
                // Overwrite if file size/date modified are different
                else if (new FileInfo(file).Length != new FileInfo($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{Path.GetFileName(file)}").Length ||
                         FileIOWrapper.GetLastWriteTime(file) != FileIOWrapper.GetLastWriteTime($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{Path.GetFileName(file)}"))
                {
                    Console.WriteLine($@"[INFO] Reverting {file} to original...");
                    try
                    {
                        FileIOWrapper.Copy($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{Path.GetFileName(file)}", file, true);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"[ERROR] Couldn't overwrite {file} ({e.Message})");
                    }
                }
            });

            // Copy over original files that may have accidentally been deleted
            foreach (var file in original_data)
            {
                if (!FileIOWrapper.Exists($@"{modPath}\data\{file}") && FileIOWrapper.Exists($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{file}"))
                {
                    Console.WriteLine($"[INFO] Restoring {file}...");
                    try
                    {
                        FileIOWrapper.Copy($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{file}", $@"{modPath}\data\{file}", true);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"[ERROR] Couldn't copy over {file} ({e.Message})");
                    }
                }
            }

            // Copy over backed up original rdbs
            foreach (var file in Directory.GetFiles(modPath, "*.rdb"))
            {
                Console.WriteLine($@"[INFO] Reverting {file} to original...");
                try
                {
                    FileIOWrapper.Copy($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\{Path.GetFileName(file)}", file, true);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"[ERROR] Couldn't overwrite {file} ({e.Message})");
                }
            }
        }