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-22 18:57:51 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-02-22 18:57:51 +0300
commit7e377a24fa91a08c0230d3883e1e4028a7d64381 (patch)
treed9ecad9a9aba694fcfd37aaff9ba8c3646554964 /Apps
parent34a4ceaa2b4a00c4dd6269bf3012abb77dcf25e4 (diff)
Compression
Diffstat (limited to 'Apps')
-rw-r--r--Apps/NesMiniApplication.cs33
1 files changed, 31 insertions, 2 deletions
diff --git a/Apps/NesMiniApplication.cs b/Apps/NesMiniApplication.cs
index b9e56646..0db8e9b5 100644
--- a/Apps/NesMiniApplication.cs
+++ b/Apps/NesMiniApplication.cs
@@ -1,4 +1,5 @@
using com.clusterrr.hakchi_gui.Properties;
+using SevenZip;
using System;
using System.Diagnostics;
using System.Drawing;
@@ -135,22 +136,38 @@ namespace com.clusterrr.hakchi_gui
var appinfo = AppTypeCollection.GetAppByExtension(extension);
if (appinfo != null)
{
+ if (ConfigIni.Compress)
+ {
+ string temp = null;
+ temp = Path.Combine(Path.GetTempPath(), fileName);
+ File.WriteAllBytes(temp, rawRomData);
+ rawRomData = Compress(temp);
+ fileName += ".7z";
+ if (!string.IsNullOrEmpty(temp) && File.Exists(temp))
+ File.Delete(temp);
+ }
var import = appinfo.Class.GetMethod("Import", new Type[] { typeof(string), typeof(byte[]) });
if (import != null)
return (NesMiniApplication)import.Invoke(null, new object[] { fileName, rawRomData });
else
return Import(fileName, rawRomData, appinfo.Prefix, appinfo.DefaultApp, appinfo.DefaultCover);
}
- string application = extension.Length > 2 ? ("/bin/" + extension.Substring(2)) : DefaultApp;
+ 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)
{
+ bool sevenZipped = false;
+ if (fileName.EndsWith(".7z"))
+ {
+ fileName = fileName.Substring(0, fileName.Length - 3);
+ sevenZipped = true;
+ }
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();
+ var romName = Regex.Replace(Path.GetFileName(fileName), @"[^A-Za-z0-9.-]", "_").Trim() + (sevenZipped ? ".7z" : "");
var romPath = Path.Combine(gamePath, romName);
Directory.CreateDirectory(gamePath);
File.WriteAllBytes(romPath, rawRomData);
@@ -486,6 +503,18 @@ namespace com.clusterrr.hakchi_gui
return new Bitmap(memoryStream);
}
}
+
+ private static byte[] Compress(string filename)
+ {
+ var arch = new MemoryStream();
+ var compressor = new SevenZipCompressor();
+ compressor.CompressionLevel = CompressionLevel.Ultra;
+ compressor.CompressFiles(arch, filename);
+ arch.Seek(0, SeekOrigin.Begin);
+ var result = new byte[arch.Length];
+ arch.Read(result, 0, result.Length);
+ return result;
+ }
}
}