Example #1
0
        public static void RemoveRecursively(string dir)
        {
            foreach (string file in Directory.GetFiles(dir))
            {
                MyFile.Delete(file);
            }

            foreach (string dirr in Directory.GetDirectories(dir))
            {
                MyDirectory.RemoveRecursively(dirr);
            }

            Directory.Delete(dir);
        }
Example #2
0
        private void UnpackFiles(string folder, string mod_path, string output_path, string game_path)
        {
            statusBar.Text = "Comparing files in \"" + folder + "\"...";
            bool check_again = false;

            //Think up a comment that describes what this block does
            string the_orig_path;

            if (Directory.Exists(Path.Combine(output_path, "orig", folder)))
            {
                the_orig_path = Path.Combine(output_path, "orig", folder);
            }
            else
            {
                the_orig_path = Path.Combine(game_path, folder);
            }

            string[] mod_files = Directory.GetFiles(Path.Combine(mod_path, folder), "*", SearchOption.AllDirectories);

            string[] game_files = Directory.GetFiles(the_orig_path, "*", SearchOption.AllDirectories);

            for (int i = 0; i < game_files.Length; i++)
            {
                game_files[i] = game_files[i].Substring(the_orig_path.Length + 1);
            }

            for (int i = 0; i < mod_files.Length; i++)
            {
                mod_files[i] = mod_files[i].Substring(mod_path.Length + folder.Length + 2);
            }

            foreach (string file in mod_files)
            {
                statusBar.Text = "Comparing files... (" + Path.Combine(folder, file) + ")";

                if (game_files.Contains(file))
                {
                    string orig_file        = Path.Combine(the_orig_path, file);
                    string output_orig_file = Path.Combine(output_path, "orig", folder, file);
                    string output_mod_file  = Path.Combine(output_path, folder, file);

                    if (!File.Exists(output_mod_file))
                    {
                        continue;
                    }

                    if (SHA.GetSHA512(output_mod_file) == SHA.GetSHA512(orig_file))
                    {
                        MyFile.Delete(output_mod_file);
                        check_again = true;
                    }
                    else
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(output_orig_file));
                        if (orig_file != output_orig_file)
                        {
                            File.Copy(orig_file, output_orig_file, true);
                        }

                        if (file.EndsWith(".AMB", StringComparison.OrdinalIgnoreCase))
                        {
                            Extract.AMB(output_mod_file);
                            MyFile.Delete(output_mod_file);
                            Directory.Move(output_mod_file + "_extracted", output_mod_file);

                            Extract.AMB(output_orig_file);
                            MyFile.Delete(output_orig_file);
                            Directory.Move(output_orig_file + "_extracted", output_orig_file);

                            check_again = true;
                        }
                        else if (file.EndsWith(".CSB", StringComparison.OrdinalIgnoreCase))
                        {
                            Extract.CSB(output_mod_file);
                            MyFile.Delete(output_mod_file);

                            Extract.CSB(output_orig_file);
                            MyFile.Delete(output_orig_file);

                            check_again = true;
                        }
                        else if (file.EndsWith(".CPK", StringComparison.OrdinalIgnoreCase))
                        {
                            if (!mod_files.Contains(file.Substring(0, file.Length - 4) + ".CBS"))
                            {
                                orig_file        = Path.Combine(game_path, folder, file.Substring(0, file.Length - 4) + ".CSB");
                                output_orig_file = output_orig_file.Substring(0, output_orig_file.Length - 4) + ".CSB";
                                output_mod_file  = output_mod_file.Substring(0, output_mod_file.Length - 4) + ".CSB";

                                File.Copy(orig_file, output_orig_file);
                                File.Copy(orig_file, output_mod_file);

                                Extract.CSB(output_mod_file);
                                MyFile.Delete(output_mod_file);
                                MyFile.Delete(output_mod_file.Substring(0, output_mod_file.Length - 4) + ".CPK");

                                Extract.CSB(output_orig_file);
                                MyFile.Delete(output_orig_file);
                                MyFile.Delete(output_orig_file.Substring(0, output_orig_file.Length - 4) + ".CPK");

                                check_again = true;
                            }
                        }
                    }
                }
            }

            if (check_again)
            {
                UnpackFiles(folder, output_path, output_path, game_path);
            }
        }