private static int GetFileHashImpl(FileInfo file)
        {
            if (!file.Exists)
            {
                return(-1);
            }

            if (SB3UGS_Utils.FileIsAssetBundle(file))
            {
                try
                {
                    return(SB3UGS_Utils.HashFileContents(file.FullName));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed to get content hash with SB3UGS, falling back to full hash. File: " + file.FullName + " Exception: " + ex.Message);
                }
            }

            if (_crc == null)
            {
                _crc = new CRC32();
            }
            else
            {
                _crc.Reset();
            }

            using (var rs = file.OpenRead())
            {
                return(_crc.GetCrc32(rs));
            }
        }
示例#2
0
        private void CompressFiles(IReadOnlyList <FileInfo> files, bool randomizeCab)
        {
            if (!SB3UGS_Initializer.CheckIsAvailable())
            {
                MessageBox.Show(
                    "SB3UGS has not been found in KK Manager directory or it failed to be loaded. Reinstall KK Manager and try again.",
                    "Compress files", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            LoadingDialog.ShowDialog(this, "Compressing asset bundle files", dialogInterface =>
            {
                dialogInterface.SetMaximum(files.Count);

                var excs            = new ConcurrentBag <Exception>();
                long totalSizeSaved = 0;
                var count           = 0;

                Parallel.ForEach(files, file =>
                {
                    dialogInterface.SetProgress(count++, "Compressing " + file.Name);

                    try
                    {
                        var origSize = file.Length;
                        SB3UGS_Utils.CompressBundle(file.FullName, randomizeCab);
                        file.Refresh();
                        totalSizeSaved += origSize - file.Length;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Failed to compress file {file.FullName} - {ex.Message}");
                        excs.Add(ex);
                    }
                });

                if (excs.Any())
                {
                    MessageBox.Show($"Successfully compressed {files.Count - excs.Count} out of {files.Count} files, see log for details. Saved {FileSize.FromBytes(totalSizeSaved).ToString()}.", "Compress files", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    MessageBox.Show($"Successfully compressed {files.Count} files. Saved {FileSize.FromBytes(totalSizeSaved).ToString()}.", "Compress files", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            });
        }
示例#3
0
        private bool FileCanBeCompressed(FileInfo x, DirectoryInfo rootDirectory)
        {
            if (!SB3UGS_Utils.FileIsAssetBundle(x))
            {
                return(false);
            }

            // Files inside StreamingAssets are hash-checked so they can't be changed
            var isStreamingAsset = x.FullName.Substring(rootDirectory.FullName.Length)
                                   .Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)
                                   .Contains("StreamingAssets", StringComparer.OrdinalIgnoreCase);

            if (isStreamingAsset)
            {
                Console.WriteLine($"Skipping file {x.FullName} - Files inside StreamingAssets folder are hash-checked and can't be modified.");
                return(false);
            }

            return(true);
        }