From 14dfefcf49c5c3a5380130ecbd5d84e1ecf99dae Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 4 May 2016 17:14:11 -0700 Subject: [PATCH] Fix 64-bit builds and add UncompressedSize --- SabreTools.sln | 10 ++ UncompressedSize/App.config | 6 ++ UncompressedSize/Properties/AssemblyInfo.cs | 36 +++++++ UncompressedSize/UncompressedSize.cs | 108 ++++++++++++++++++++ UncompressedSize/UncompressedSize.csproj | 86 ++++++++++++++++ 5 files changed, 246 insertions(+) create mode 100644 UncompressedSize/App.config create mode 100644 UncompressedSize/Properties/AssemblyInfo.cs create mode 100644 UncompressedSize/UncompressedSize.cs create mode 100644 UncompressedSize/UncompressedSize.csproj diff --git a/SabreTools.sln b/SabreTools.sln index 2e6966ad..b83b9f8a 100644 --- a/SabreTools.sln +++ b/SabreTools.sln @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DATFromDir", "DATFromDir\DA EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OfflineMerge", "OfflineMerge\OfflineMerge.csproj", "{88310DB9-3B64-4268-AD48-2E0358D4CA5F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UncompressedSize", "UncompressedSize\UncompressedSize.csproj", "{E21ABB36-C6D9-4FD6-802E-EC0D05284E0A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -72,6 +74,14 @@ Global {88310DB9-3B64-4268-AD48-2E0358D4CA5F}.Release|Any CPU.Build.0 = Release|Any CPU {88310DB9-3B64-4268-AD48-2E0358D4CA5F}.Release|x64.ActiveCfg = Release|x64 {88310DB9-3B64-4268-AD48-2E0358D4CA5F}.Release|x64.Build.0 = Release|x64 + {E21ABB36-C6D9-4FD6-802E-EC0D05284E0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E21ABB36-C6D9-4FD6-802E-EC0D05284E0A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E21ABB36-C6D9-4FD6-802E-EC0D05284E0A}.Debug|x64.ActiveCfg = Debug|x64 + {E21ABB36-C6D9-4FD6-802E-EC0D05284E0A}.Debug|x64.Build.0 = Debug|x64 + {E21ABB36-C6D9-4FD6-802E-EC0D05284E0A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E21ABB36-C6D9-4FD6-802E-EC0D05284E0A}.Release|Any CPU.Build.0 = Release|Any CPU + {E21ABB36-C6D9-4FD6-802E-EC0D05284E0A}.Release|x64.ActiveCfg = Release|x64 + {E21ABB36-C6D9-4FD6-802E-EC0D05284E0A}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/UncompressedSize/App.config b/UncompressedSize/App.config new file mode 100644 index 00000000..88fa4027 --- /dev/null +++ b/UncompressedSize/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/UncompressedSize/Properties/AssemblyInfo.cs b/UncompressedSize/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..2987ca0a --- /dev/null +++ b/UncompressedSize/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UncompressedSize")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UncompressedSize")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e21abb36-c6d9-4fd6-802e-ec0d05284e0a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UncompressedSize/UncompressedSize.cs b/UncompressedSize/UncompressedSize.cs new file mode 100644 index 00000000..c03a1fe9 --- /dev/null +++ b/UncompressedSize/UncompressedSize.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using SabreTools.Helper; + +namespace SabreTools +{ + public class UncompressedSize + { + public static void Main(string[] args) + { + List inputs = new List(); + + foreach (string arg in args) + { + if (File.Exists(arg.Replace("\"", ""))) + { + inputs.Add(arg.Replace("\"", "")); + } + if (Directory.Exists(arg.Replace("\"", ""))) + { + foreach (string file in Directory.GetFiles(arg.Replace("\"", ""), "*", SearchOption.AllDirectories)) + { + inputs.Add(file.Replace("\"", "")); + } + } + } + + Logger logger = new Logger(true, "uncompressedsize.log"); + logger.Start(); + + long size = 0; + foreach (string filename in inputs) + { + Dictionary> roms = new Dictionary>(); + roms = RomManipulation.ParseDict(filename, 0, 0, roms, logger); + foreach (List romlist in roms.Values) + { + foreach (RomData rom in romlist) + { + size += rom.Size; + } + } + } + + logger.Log("The total file size is: " + GetBytesReadable(size)); + logger.Close(); + } + + /// + /// Returns the human-readable file size for an arbitrary, 64-bit file size + /// The default format is "0.### XB", e.g. "4.2 KB" or "1.434 GB" + /// + /// + /// Human-readable file size + /// http://www.somacon.com/p576.php + public static string GetBytesReadable(long input) + { + // Get absolute value + long absolute_i = (input < 0 ? -input : input); + // Determine the suffix and readable value + string suffix; + double readable; + if (absolute_i >= 0x1000000000000000) // Exabyte + { + suffix = "EB"; + readable = (input >> 50); + } + else if (absolute_i >= 0x4000000000000) // Petabyte + { + suffix = "PB"; + readable = (input >> 40); + } + else if (absolute_i >= 0x10000000000) // Terabyte + { + suffix = "TB"; + readable = (input >> 30); + } + else if (absolute_i >= 0x40000000) // Gigabyte + { + suffix = "GB"; + readable = (input >> 20); + } + else if (absolute_i >= 0x100000) // Megabyte + { + suffix = "MB"; + readable = (input >> 10); + } + else if (absolute_i >= 0x400) // Kilobyte + { + suffix = "KB"; + readable = input; + } + else + { + return input.ToString("0 B"); // Byte + } + // Divide by 1024 to get fractional value + readable = (readable / 1024); + // Return formatted number with suffix + return readable.ToString("0.### ") + suffix; + } + } +} diff --git a/UncompressedSize/UncompressedSize.csproj b/UncompressedSize/UncompressedSize.csproj new file mode 100644 index 00000000..2b9c673a --- /dev/null +++ b/UncompressedSize/UncompressedSize.csproj @@ -0,0 +1,86 @@ + + + + + Debug + AnyCPU + {E21ABB36-C6D9-4FD6-802E-EC0D05284E0A} + Exe + Properties + UncompressedSize + UncompressedSize + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + ..\..\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + ..\..\Release\ + TRACE + prompt + 4 + + + true + ..\..\Debug-x64\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + ..\..\Release-x64\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + {225a1afd-0890-44e8-b779-7502665c23a5} + SabreHelper + + + + + \ No newline at end of file