Exemplo n.º 1
0
        /// <summary>
        /// Cleans the output folder.
        /// </summary>
        private void CleanOutputFolder()
        {
            {
                if (Directory.Exists(_config.OutputPath))
                {
                    // Delete .tlk
                    if (File.Exists($"{_config.OutputPath}{Path.GetFileName(_config.TlkPath)}"))
                    {
                        File.Delete($"{_config.OutputPath}{Path.GetFileName(_config.TlkPath)}");
                    }

                    Parallel.ForEach(_config.HakList, hak =>
                    {
                        // Check whether .hak file exists
                        if (!File.Exists(_config.OutputPath + hak.Name + ".hak"))
                        {
                            Console.WriteLine(hak.Name + " needs to be built");
                            return;
                        }

                        var checksumFolder = ChecksumUtil.ChecksumFolder(hak.Path);
                        _checksumDictionary.Add(hak.Name, checksumFolder);

                        // Check whether .sha checksum file exists
                        if (!File.Exists(_config.OutputPath + hak.Name + ".md5"))
                        {
                            Console.WriteLine(hak.Name + " needs to be built");
                            return;
                        }

                        // When checksums are equal or hak folder doesn't exist -> remove hak from the list
                        var checksumFile = ChecksumUtil.ReadChecksumFile(_config.OutputPath + hak.Name + ".md5");
                        if (checksumFolder == checksumFile)
                        {
                            _haksToProcess.Remove(hak);
                            Console.WriteLine(hak.Name + " is up to date");
                        }
                    });

                    // Delete outdated haks and checksums
                    Parallel.ForEach(_haksToProcess, hak =>
                    {
                        var filePath = _config.OutputPath + hak.Name;
                        if (File.Exists(filePath + ".hak"))
                        {
                            File.Delete(filePath + ".hak");
                        }

                        if (File.Exists(filePath + ".md5"))
                        {
                            File.Delete(filePath + ".md5");
                        }
                    });
                }
                else
                {
                    Directory.CreateDirectory(_config.OutputPath);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Compiles files contained in a folder into a hakpak.
        /// </summary>
        /// <param name="hakName">The name of the hak without the .hak extension</param>
        /// <param name="folderPath">The folder where the assets are.</param>
        private void CompileHakpak(string hakName, string folderPath)
        {
            var command = $"nwn_erf -f \"{_config.OutputPath}{hakName}.hak\" -e HAK -c ./{folderPath}";

            Console.WriteLine($"Building hak: {hakName}.hak");

            using (var process = CreateProcess(command))
            {
                process.Start();

                process.StandardInput.Flush();
                process.StandardInput.Close();

                process.StandardOutput.ReadToEnd();

                process.WaitForExit();
            }

            if (!_checksumDictionary.TryGetValue(hakName, out var checksum))
            {
                checksum = ChecksumUtil.ChecksumFolder(folderPath);
            }

            ChecksumUtil.WriteChecksumFile(_config.OutputPath + hakName + ".md5", checksum);
        }