Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/Apps
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-02-23 08:30:09 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-02-23 08:30:09 +0300
commiteed0039b675387362319d29500bd2402bca9b355 (patch)
tree2fb13a5a34a5c143adf343eb92b2cd1df84e6bef /Apps
parent6a27d18caab4c4eae5691971027982fe6d97fd2d (diff)
Compressing support done
Diffstat (limited to 'Apps')
-rw-r--r--Apps/NesMiniApplication.cs41
1 files changed, 26 insertions, 15 deletions
diff --git a/Apps/NesMiniApplication.cs b/Apps/NesMiniApplication.cs
index fe9d9df1..1d684f4b 100644
--- a/Apps/NesMiniApplication.cs
+++ b/Apps/NesMiniApplication.cs
@@ -21,7 +21,7 @@ namespace com.clusterrr.hakchi_gui
{
get { return code; }
}
- public const char DefaultPrefix = 'U';
+ public const char DefaultPrefix = 'Z';
public static Image DefaultCover { get { return Resources.blank_app; } }
internal const string DefaultApp = "/bin/path-to-your-app";
public virtual string GoogleSuffix
@@ -140,35 +140,46 @@ namespace com.clusterrr.hakchi_gui
if (import != null)
return (NesMiniApplication)import.Invoke(null, new object[] { fileName, rawRomData });
else
- return Import(fileName, rawRomData, appinfo.Prefix, appinfo.DefaultApp, appinfo.DefaultCover);
+ return Import(fileName, rawRomData, appinfo.Prefix, appinfo.DefaultApp, appinfo.DefaultCover, ConfigIni.Compress);
}
string application = extension.Length > 2 ? ("/bin/" + extension.Substring(1)) : DefaultApp;
return Import(fileName, rawRomData, DefaultPrefix, application, DefaultCover);
}
- private static NesMiniApplication Import(string fileName, byte[] rawRomData, char prefixCode, string application, Image defaultCover)
+ private static NesMiniApplication Import(string fileName, byte[] rawRomData, char prefixCode, string application, Image defaultCover, bool compress = false)
{
+ var crc32 = CRC32(rawRomData);
+ var code = GenerateCode(crc32, prefixCode);
+ var gamePath = Path.Combine(GamesDirectory, code);
bool sevenZipped = false;
- if (ConfigIni.Compress)
+ if (compress)
{
+ string temp = null;
try
{
- string temp = null;
- temp = Path.Combine(Path.GetTempPath(), fileName);
- File.WriteAllBytes(temp, rawRomData);
- rawRomData = Compress(temp);
- if (!string.IsNullOrEmpty(temp) && File.Exists(temp))
- File.Delete(temp);
- sevenZipped = true;
+ if (!File.Exists(fileName))
+ {
+ temp = Path.Combine(Path.GetTempPath(), Path.GetFileName(fileName));
+ File.WriteAllBytes(temp, rawRomData);
+ rawRomData = Compress(temp);
+ sevenZipped = true;
+ }
+ else
+ {
+ rawRomData = Compress(fileName);
+ sevenZipped = true;
+ }
}
catch (Exception ex)
{
Debug.WriteLine("Compression error: " + ex.Message + ex.Source);
}
+ finally
+ {
+ if (!string.IsNullOrEmpty(temp) && File.Exists(temp))
+ File.Delete(temp);
+ }
}
- var crc32 = CRC32(rawRomData);
- var code = GenerateCode(crc32, prefixCode);
- var gamePath = Path.Combine(GamesDirectory, code);
var romName = Regex.Replace(Path.GetFileName(fileName), @"[^A-Za-z0-9.-]", "_").Trim() + (sevenZipped ? ".7z" : "");
var romPath = Path.Combine(gamePath, romName);
if (Directory.Exists(gamePath))
@@ -513,7 +524,7 @@ namespace com.clusterrr.hakchi_gui
SevenZipExtractor.SetLibraryPath(Path.Combine(MainForm.BaseDirectory, IntPtr.Size == 8 ? @"tools\7z64.dll" : @"tools\7z.dll"));
var arch = new MemoryStream();
var compressor = new SevenZipCompressor();
- compressor.CompressionLevel = CompressionLevel.Ultra;
+ compressor.CompressionLevel = CompressionLevel.High;
compressor.CompressFiles(arch, filename);
arch.Seek(0, SeekOrigin.Begin);
var result = new byte[arch.Length];