Пример #1
0
        public bool Run(IFileHierarchyFile rarcFile, bool cleanup)
        {
            Asserts.True(
                rarcFile.Impl.Exists,
                $"Cannot dump RARC because it does not exist: {rarcFile}");

            var finalDirectoryPath = rarcFile.FullNameWithoutExtension;

            if (Directory.Exists(finalDirectoryPath))
            {
                return(false);
            }

            if (!MagicTextUtil.Verify(rarcFile, "RARC"))
            {
                return(false);
            }

            var directoryPath = rarcFile.FullName + "_dir";

            if (!Directory.Exists(directoryPath))
            {
                var logger = Logging.Create <RarcDump>();
                logger.LogInformation($"Dumping RARC {rarcFile.LocalPath}...");

                // TODO: Is this implementation right? It *seems* to only export the
                // first node in a RARC.
                Files.RunInDirectory(
                    rarcFile.Impl.GetParent() !,
                    () => {
                    ProcessUtil.ExecuteBlockingSilently(
                        GcnToolsConstants.RARCDUMP_EXE,
                        $"\"{rarcFile.FullName}\"");
                });
                Asserts.True(Directory.Exists(directoryPath),
                             $"Directory was not created: {directoryPath}");
            }

            Directory.Move(directoryPath, finalDirectoryPath);
            if (cleanup)
            {
                rarcFile.Impl.Info.Delete();
            }

            return(true);
        }
Пример #2
0
        public bool Run(IFileHierarchyFile file, bool cleanup)
        {
            Asserts.True(
                file.Exists,
                $"Cannot decrypt YAY0 because it does not exist: {file}");

            var finalRarcPath = file.FullNameWithoutExtension + ".rarc";

            if (File.Exists(finalRarcPath))
            {
                return(false);
            }

            if (!MagicTextUtil.Verify(file, "Yay0"))
            {
                return(false);
            }

            var rarcPath = file.FullName + " 0.rarc";

            if (!File.Exists(rarcPath))
            {
                var logger = Logging.Create <Yay0Dec>();
                Files.RunInDirectory(
                    file.Impl.GetParent() !,
                    () => {
                    ProcessUtil.ExecuteBlockingSilently(
                        GcnToolsConstants.YAY0DEC_EXE,
                        $"\"{file.FullName}\"");
                });
                Asserts.True(File.Exists(rarcPath),
                             $"File was not created: {rarcPath}");
            }

            File.Move(rarcPath, finalRarcPath);
            if (cleanup)
            {
                file.Impl.Info.Delete();
            }

            return(true);
        }
Пример #3
0
        public bool Run(
            IFileHierarchyFile rarcFile,
            bool cleanup,
            IReadOnlySet <string> junkTerms)
        {
            Asserts.True(
                rarcFile.Impl.Exists,
                $"Cannot dump RARC because it does not exist: {rarcFile}");

            if (!MagicTextUtil.Verify(rarcFile, "RARC"))
            {
                return(false);
            }

            var directoryPath = rarcFile.FullName + "_dir";

            if (!Directory.Exists(directoryPath))
            {
                var logger = Logging.Create <RarcDump>();
                logger.LogInformation($"Dumping RARC {rarcFile.LocalPath}...");

                Files.RunInDirectory(
                    rarcFile.Impl.GetParent() !,
                    () => {
                    ProcessUtil.ExecuteBlockingSilently(
                        GcnToolsConstants.RARCDUMP_EXE,
                        $"\"{rarcFile.FullName}\"");
                });
                Asserts.True(Directory.Exists(directoryPath),
                             $"Directory was not created: {directoryPath}");
            }

            // Determines final directory path from
            var directory = new FinDirectory(directoryPath);

            var subdir       = directory.GetExistingSubdirs().Single();
            var subdirName   = subdir.Name;
            var isSubdirJunk = junkTerms.Contains(subdirName);

            var rarcName   = rarcFile.NameWithoutExtension;
            var isRarcJunk = junkTerms.Contains(rarcName);

            string finalDirectoryName;

            // If only one is in the junk set, uses the other.
            if (isSubdirJunk && !isRarcJunk)
            {
                finalDirectoryName = rarcName;
            }
            else if (!isSubdirJunk && isRarcJunk)
            {
                finalDirectoryName = subdirName;
            }
            // If subdir has same name or is an abbreviation of the parent,
            // just collapses them with the parent name.
            else if ((subdirName.Length <= rarcName.Length &&
                      subdirName.ToLower() ==
                      rarcName.Substring(0, subdirName.Length).ToLower()) ||
                     (junkTerms?.Contains(subdirName) ?? false))
            {
                finalDirectoryName = rarcName;
            }
            // If parent has same name or is an abbreviation of the subdir,
            // just collapses them with the subdir name.
            else if (subdirName.Length >= rarcName.Length &&
                     subdirName.Substring(0, rarcName.Length).ToLower() ==
                     rarcName.ToLower())
            {
                finalDirectoryName = subdirName;
            }
            // If subdir has a different name, merges their names together and
            // collapses them.
            else
            {
                finalDirectoryName = $"{rarcName}_{subdirName}";
            }
            var finalDirectoryPath =
                Path.Join(Path.GetDirectoryName(directoryPath), finalDirectoryName);

            Asserts.True(!Directory.Exists(finalDirectoryPath));
            subdir.MoveTo(finalDirectoryPath);
            Directory.Delete(directoryPath);

            if (cleanup)
            {
                rarcFile.Impl.Info.Delete();
            }

            return(true);
        }