示例#1
0
        /// <summary>
        /// Unpacks an NSZ file, specified by nszPath, into a new NSP file.
        /// </summary>
        /// <param name="nszPath">Path to the input NSZ file.</param>
        /// <param name="outDir">Directory in which to output the NCA file.</param>
        /// <returns>Decompressed file path if the operation succeeded, otherwise null.</returns>
        public static async Task <string> UnpackNSZ(string nszPath, string outDir)
        {
            string fName   = Path.GetFileNameWithoutExtension(nszPath);
            string outfile = FileUtils.BuildFilePath(outDir, fName, "nsp");

            string exe = (exePath);

            // NOTE: Using single quotes here instead of single quotes f***s up windows, it CANNOT handle single quotes
            // Anything surrounded in single quotes will throw an error because the file/folder isn't found
            // Must use escaped double quotes!
            string commandLine = $" -D --overwrite --verify" +
                                 $" --output \"{outDir}\"" +
                                 $" \"{nszPath}\"";


            try
            {
                return(await Task.Run(delegate
                {
                    ProcessStartInfo psi = new ProcessStartInfo()
                    {
                        FileName = exe,
                        WorkingDirectory = System.IO.Directory.GetCurrentDirectory(),
                        Arguments = commandLine,
                        UseShellExecute = false,
                        //RedirectStandardOutput = true,
                        //RedirectStandardError = true,
                        CreateNoWindow = true,
                    };
                    Process process = Process.Start(psi);

                    //string errors = hactool.StandardError.ReadToEnd();
                    //string output = hactool.StandardOutput.ReadToEnd();

                    process.WaitForExit();

                    if (!FileUtils.FileExists(outfile))
                    {
                        throw new Exception($"Decompressing NSZ failed, {outfile} is missing!");
                    }
                    return outfile;
                }));
            }
            catch (Exception e)
            {
                throw new Exception("Decompressing NSZ failed!", e);
            }
        }