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
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-02-07 00:23:49 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-02-07 00:23:49 +0300
commit7217e5882968829703a13aedcff424c31ca24094 (patch)
tree7dd854020bdea41dd55e504c865bbe61faa9cfb2
parenta2197a6cb42d511747ccd2159cf1f4d29ef15f07 (diff)
Optimization, optimization, optimization
-rw-r--r--FelLib/Fel.cs14
-rw-r--r--NesMenuCollection.cs48
-rw-r--r--NesMenuFolder.cs74
-rw-r--r--Properties/Resources.ru-RU.resx4
-rw-r--r--TreeContructorForm.cs10
-rw-r--r--WorkerForm.cs290
6 files changed, 253 insertions, 187 deletions
diff --git a/FelLib/Fel.cs b/FelLib/Fel.cs
index bdf02435..7c195d4d 100644
--- a/FelLib/Fel.cs
+++ b/FelLib/Fel.cs
@@ -129,18 +129,20 @@ namespace com.clusterrr.FelLib
private void WriteToUSB(byte[] buffer)
{
-#if DEBUG
- Debug.WriteLine("-> " + BitConverter.ToString(buffer));
-#endif
+//#if DEBUG
+// Debug.WriteLine("-> " + BitConverter.ToString(buffer));
+//#endif
+ Debug.WriteLine(string.Format("-> {0} bytes" , buffer.Length));
device.Pipes[outEndp].Write(buffer);
}
private int ReadFromUSB(byte[] buffer, int offset, int length)
{
var data = device.Pipes[inEndp].Read(buffer, offset, length);
-#if DEBUG
- Debug.WriteLine("<- " + BitConverter.ToString(buffer));
-#endif
+//#if DEBUG
+// Debug.WriteLine("<- " + BitConverter.ToString(buffer));
+//#endif
+ Debug.WriteLine(string.Format("<- {0} bytes", length));
return data;
}
private byte[] ReadFromUSB(UInt32 length)
diff --git a/NesMenuCollection.cs b/NesMenuCollection.cs
index 60c087dd..e634e600 100644
--- a/NesMenuCollection.cs
+++ b/NesMenuCollection.cs
@@ -40,7 +40,7 @@ namespace com.clusterrr.hakchi_gui
root = new NesMenuCollection();
root.AddRange(this.Where(o => !(o is NesDefaultGame)));
this.RemoveAll(o => !(o is NesDefaultGame));
- this.Add(new NesMenuFolder() { Name = Resources.FolderNameMoreGames, First = false, Child = root });
+ this.Add(new NesMenuFolder() { Name = Resources.FolderNameMoreGames, Position = NesMenuFolder.Priority.End, Child = root });
}
var sorted = root.OrderBy(o => o.Name);
@@ -78,11 +78,9 @@ namespace com.clusterrr.hakchi_gui
var fname = alphaNum.Replace(coll.Where(o => (o is NesGame) || (o is NesDefaultGame)).First().Name.ToUpper(), "");
var lname = alphaNum.Replace(coll.Where(o => (o is NesGame) || (o is NesDefaultGame)).Last().Name.ToUpper(), "");
- var folder = new NesMenuFolder();
- folder.Child = coll;
- folder.NameParts = new string[] { fname, lname };
+ var folder = new NesMenuFolder() { Child = coll, NameParts = new string[] { fname, lname }, Position = NesMenuFolder.Priority.Left };
+ coll.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, Image = Resources.back, Position = NesMenuFolder.Priority.Back, Child = root });
root.Add(folder);
- coll.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, Image = Resources.back, Child = root });
}
TrimFolderNames(root);
}
@@ -93,24 +91,26 @@ namespace com.clusterrr.hakchi_gui
{
for (int j = i - 1; j >= 0; j--)
{
- var folder = new NesMenuFolder();
var fname = alphaNum.Replace(collections[j].Where(o => (o is NesGame) || (o is NesDefaultGame)).First().Name.ToUpper(), "");
var lname = alphaNum.Replace(collections[j].Where(o => (o is NesGame) || (o is NesDefaultGame)).Last().Name.ToUpper(), "");
- folder.Child = collections[j];
- folder.NameParts = new string[] { fname, lname };
- //folder.Initial = collections[j].Where(o => (o is NesGame) || (o is NesDefaultGame)).First().Code;
- folder.First = true;
+ var folder = new NesMenuFolder()
+ {
+ Child = j > 0 ? collections[j] : root,
+ NameParts = new string[] { fname, lname },
+ Position = NesMenuFolder.Priority.Left
+ };
collections[i].Insert(0, folder);
}
for (int j = i + 1; j < collections.Count; j++)
{
- var folder = new NesMenuFolder();
var fname = alphaNum.Replace(collections[j].Where(o => (o is NesGame) || (o is NesDefaultGame)).First().Name.ToUpper(), "");
var lname = alphaNum.Replace(collections[j].Where(o => (o is NesGame) || (o is NesDefaultGame)).Last().Name.ToUpper(), "");
- folder.Child = collections[j];
- folder.NameParts = new string[] { fname, lname };
- //folder.Initial = collections[j].Where(o => (o is NesGame) || (o is NesDefaultGame)).First().Code;
- folder.First = false;
+ var folder = new NesMenuFolder()
+ {
+ Child = j > 0 ? collections[j] : root,
+ NameParts = new string[] { fname, lname },
+ Position = NesMenuFolder.Priority.Right
+ };
collections[i].Insert(collections[i].Count, folder);
}
TrimFolderNames(collections[i]);
@@ -137,19 +137,19 @@ namespace com.clusterrr.hakchi_gui
foreach (var letter in letters.Keys)
if (letters[letter].Count > 0)
{
- var folder = new NesMenuFolder() { Child = letters[letter], Name = letter.ToString() };
+ var folder = new NesMenuFolder() { Child = letters[letter], Name = letter.ToString(), Position = NesMenuFolder.Priority.Left };
if (style == SplitStyle.FoldersAlphabetic_PagesEqual)
{
folder.Child.Split(SplitStyle.PagesEqual, false, maxElements);
- folder.Child.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, Image = Resources.back, Child = root });
+ folder.Child.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, Image = Resources.back, Position = NesMenuFolder.Priority.Back, Child = root });
foreach (NesMenuFolder f in folder.Child.Where(o => o is NesMenuFolder))
if (f.Child != root)
- f.Child.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, Image = Resources.back, Child = root });
+ f.Child.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, Image = Resources.back, Position = NesMenuFolder.Priority.Back, Child = root });
}
else if (style == SplitStyle.FoldersAlphabetic_FoldersEqual)
{
folder.Child.Split(SplitStyle.FoldersEqual, false, maxElements);
- folder.Child.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, Image = Resources.back, Child = root });
+ folder.Child.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, Image = Resources.back, Position = NesMenuFolder.Priority.Back, Child = root });
}
//folder.Initial = letters[letter].Where(o => (o is NesGame) || (o is NesDefaultGame)).First().Code;
root.Add(folder);
@@ -157,14 +157,12 @@ namespace com.clusterrr.hakchi_gui
}
if (originalToRoot)
{
- if (style != SplitStyle.FoldersEqual)
- root.Add(new NesMenuFolder() { Name = Resources.FolderNameOriginalGames, Image = Resources.back, Child = this });
+ if (style != SplitStyle.PagesEqual)
+ root.Add(new NesMenuFolder() { Name = Resources.FolderNameOriginalGames, Image = Resources.back, Position = NesMenuFolder.Priority.Back, Child = this });
else
{
- root.Add(new NesMenuFolder() { Name = Resources.FolderNameOriginalGames, Image = Resources.back, Child = this });
- foreach (NesMenuFolder f in root.Where(o => o is NesMenuFolder))
- if (f.Child != root)
- f.Child.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, Image = Resources.back, Child = root });
+ foreach(var collection in collections)
+ collection.Add(new NesMenuFolder() { Name = Resources.FolderNameOriginalGames, Image = Resources.back, Position = NesMenuFolder.Priority.Back, Child = this });
}
}
}
diff --git a/NesMenuFolder.cs b/NesMenuFolder.cs
index d7f76bf5..c227644c 100644
--- a/NesMenuFolder.cs
+++ b/NesMenuFolder.cs
@@ -14,7 +14,15 @@ namespace com.clusterrr.hakchi_gui
{
static Random rnd = new Random();
private string code = null;
- private bool first = true;
+ public enum Priority
+ {
+ Back = 0,
+ Left = 1,
+ Right = 2,
+ End = 3
+ }
+ private Priority position;
+ //private bool first = true;
public string Code
{
@@ -27,7 +35,24 @@ namespace com.clusterrr.hakchi_gui
{
get
{
- return (first ? ' ' : 'Я') + name;
+ char prefix;
+ switch (position)
+ {
+ case Priority.Back:
+ prefix = (char)1;
+ break;
+ default:
+ case Priority.Left:
+ prefix = (char)2;
+ break;
+ case Priority.Right:
+ prefix = 'Ю';
+ break;
+ case Priority.End:
+ prefix = 'Я';
+ break;
+ }
+ return prefix + name;
}
set
{
@@ -62,30 +87,43 @@ namespace com.clusterrr.hakchi_gui
string Publisher = new String('!', 10);
// It's workaround for sorting
- public bool First
+ public Priority Position
{
set
{
// Sort to left
- if (value)
- {
- Players = 2;
- Simultaneous = 1;
- ReleaseDate = "0000-00-00";
- Publisher = new String('!', 10);
- }
- else // Sort to right
+ position = value;
+ switch (position)
{
- Players = 1;
- Simultaneous = 0;
- ReleaseDate = "9999-99-99";
- Publisher = new String('Z', 10);
+ case Priority.Back:
+ Players = 2;
+ Simultaneous = 1;
+ ReleaseDate = "0000-00-00";
+ Publisher = new String((char)1, 10);
+ break;
+ case Priority.Left:
+ Players = 2;
+ Simultaneous = 1;
+ ReleaseDate = "1111-11-11";
+ Publisher = new String((char)2, 10);
+ break;
+ case Priority.Right:
+ Players = 1;
+ Simultaneous = 0;
+ ReleaseDate = "8888-88-88";
+ Publisher = new String('Y', 10);
+ break;
+ case Priority.End:
+ Players = 1;
+ Simultaneous = 0;
+ ReleaseDate = "9999-99-99";
+ Publisher = new String('Z', 10);
+ break;
}
- first = value;
}
get
{
- return first;
+ return position;
}
}
@@ -93,7 +131,7 @@ namespace com.clusterrr.hakchi_gui
{
Code = GenerateCode((uint)rnd.Next());
Name = "Folder";
- First = true;
+ Position = Priority.Left;
}
public Image Image
diff --git a/Properties/Resources.ru-RU.resx b/Properties/Resources.ru-RU.resx
index 9739b4d5..9b51880a 100644
--- a/Properties/Resources.ru-RU.resx
+++ b/Properties/Resources.ru-RU.resx
@@ -329,10 +329,10 @@
<value>Не найдено:</value>
</data>
<data name="ParticallyBody" xml:space="preserve">
- <value>Вы выбрали очень много игр. За один раз их закачать не получится. Будем закачивать в несколько заходов. Пожалуйста, подождите, пока погаснет светодиод, нажмите OK и следуйте инструкциям.</value>
+ <value>Вы выбрали очень много игр. Это не страшно, но за один раз их закачать не получится. Будем закачивать в несколько заходов. Пожалуйста, подождите, пока погаснет светодиод, нажмите OK и следуйте инструкциям.</value>
</data>
<data name="ParticallyTitle" xml:space="preserve">
- <value>Слишком много игр</value>
+ <value>Очень много игр</value>
</data>
<data name="LoadingGames" xml:space="preserve">
<value>Загружаем игры...</value>
diff --git a/TreeContructorForm.cs b/TreeContructorForm.cs
index 400ce3c1..af8df0a0 100644
--- a/TreeContructorForm.cs
+++ b/TreeContructorForm.cs
@@ -15,13 +15,15 @@ namespace com.clusterrr.hakchi_gui
{
InitializeComponent();
treeView.Nodes.Clear();
- var allFolders = new List<NesMenuCollection>();
- AddNodes(treeView.Nodes, nesMenuCollection, allFolders);
+ AddNodes(treeView.Nodes, nesMenuCollection);
}
- void AddNodes(TreeNodeCollection treeNodeCollection, NesMenuCollection nesMenuCollection, List<NesMenuCollection> usedFolders)
+ void AddNodes(TreeNodeCollection treeNodeCollection, NesMenuCollection nesMenuCollection, List<NesMenuCollection> usedFolders = null)
{
- if (usedFolders.Contains(nesMenuCollection)) return;
+ if (usedFolders == null)
+ usedFolders = new List<NesMenuCollection>();
+ if (usedFolders.Contains(nesMenuCollection))
+ return;
usedFolders.Add(nesMenuCollection);
var sorted = nesMenuCollection.OrderBy(o => o.Name);
foreach (var nesElement in sorted)
diff --git a/WorkerForm.cs b/WorkerForm.cs
index 66eccff9..015aea30 100644
--- a/WorkerForm.cs
+++ b/WorkerForm.cs
@@ -54,7 +54,7 @@ namespace com.clusterrr.hakchi_gui
readonly string argumentsFilePath;
readonly string gamesDirectory;
string[] correctKernels;
- const int maxRamfsSize = 40 * 1024 * 1024;
+ const long maxRamfsSize = 40 * 1024 * 1024;
DialogResult DeviceWaitResult = DialogResult.None;
DialogResult MessageBoxResult = DialogResult.None;
@@ -315,10 +315,9 @@ namespace com.clusterrr.hakchi_gui
SetProgress(progress, maxProgress);
byte[] kernel;
- int pos = 0, totalFiles;
if (!string.IsNullOrEmpty(Mod))
{
- kernel = CreatePatchedKernel(ref pos, out totalFiles);
+ kernel = CreatePatchedKernel();
progress += 5;
SetProgress(progress, maxProgress);
}
@@ -384,14 +383,14 @@ namespace com.clusterrr.hakchi_gui
public void Memboot()
{
- int pos = 0, totalFiles = 0;
int progress = 5;
SetProgress(progress, 300);
int maxProgress = -1;
+ var stats = new GamesTreeStats();
do
{
- if (pos > 0)
+ if (stats.GamesProceed > 0)
{
ShowMessage(Resources.ParticallyBody, Resources.ParticallyTitle);
DeviceWaitResult = DialogResult.None;
@@ -413,7 +412,7 @@ namespace com.clusterrr.hakchi_gui
byte[] kernel;
if (!string.IsNullOrEmpty(Mod))
- kernel = CreatePatchedKernel(ref pos, out totalFiles);
+ kernel = CreatePatchedKernel(stats);
else
kernel = File.ReadAllBytes(KernelDump);
var size = CalKernelSize(kernel);
@@ -431,8 +430,8 @@ namespace com.clusterrr.hakchi_gui
progress += 5;
if (maxProgress < 0)
{
- if (pos > 0)
- maxProgress = (kernel.Length / 67000 + 15) * totalFiles / pos + 75 * ((int)Math.Ceiling((float)totalFiles / (float)pos) - 1);
+ if (stats.GamesProceed > 0)
+ maxProgress = (kernel.Length / 67000 + 15) * stats.GamesTotal / stats.GamesProceed + 75 * ((int)Math.Ceiling((float)stats.GamesTotal / (float)stats.GamesProceed) - 1);
else
maxProgress = (kernel.Length / 67000 + 15);
}
@@ -456,92 +455,119 @@ namespace com.clusterrr.hakchi_gui
var bootCommand = string.Format("boota {0:x}", Fel.kernel_base_m);
SetStatus(Resources.ExecutingCommand + " " + bootCommand);
fel.RunUbootCmd(bootCommand, true);
- } while (pos < totalFiles);
+ } while (stats.GamesProceed < stats.GamesTotal);
SetStatus(Resources.Done);
SetProgress(maxProgress, maxProgress);
}
- private byte[] CreatePatchedKernel(ref int filesPos, out int totalFiles)
+ private byte[] CreatePatchedKernel(GamesTreeStats stats = null)
{
- bool first = filesPos == 0;
- bool partial = filesPos > 0;
+ if (stats == null) stats = new GamesTreeStats();
+ bool first = stats.GamesProceed == 0;
+ bool partial = stats.GamesProceed > 0;
SetStatus(Resources.BuildingCustom);
- if (Directory.Exists(tempDirectory))
- Directory.Delete(tempDirectory, true);
- Directory.CreateDirectory(tempDirectory);
- Directory.CreateDirectory(kernelDirectory);
- Directory.CreateDirectory(ramfsDirectory);
- if (!ExecuteTool("unpackbootimg.exe", string.Format("-i \"{0}\" -o \"{1}\"", KernelDump, kernelDirectory)))
- throw new Exception("Can't unpack kernel image");
- if (!ExecuteTool("lzop.exe", string.Format("-d \"{0}\" -o \"{1}\"",
- Path.Combine(kernelDirectory, "kernel.img-ramdisk.gz"), initramfs_cpio)))
- throw new Exception("Can't unpack ramdisk");
- ExecuteTool("cpio.exe", string.Format("-imd --no-preserve-owner --quiet -I \"{0}\"",
- @"..\initramfs.cpio"), ramfsDirectory);
- if (!File.Exists(Path.Combine(ramfsDirectory, "init"))) // cpio.exe fails on Windows XP for some reason. But working!
- throw new Exception("Can't unpack ramdisk 2");
- if (Directory.Exists(hakchiDirectory)) Directory.Delete(hakchiDirectory, true);
- DirectoryCopy(Path.Combine(modsDirectory, Mod), ramfsDirectory, true);
- var ramfsFiles = Directory.GetFiles(ramfsDirectory, "*.*", SearchOption.AllDirectories);
- foreach (var file in ramfsFiles)
- {
- var fInfo = new FileInfo(file);
- if (fInfo.Length > 10 && fInfo.Length < 100 && ((fInfo.Attributes & FileAttributes.System) == 0) &&
- (Encoding.ASCII.GetString(File.ReadAllBytes(file), 0, 10)) == "!<symlink>")
- fInfo.Attributes |= FileAttributes.System;
- }
+ if (first)
+ {
+ if (Directory.Exists(tempDirectory))
+ Directory.Delete(tempDirectory, true);
+ Directory.CreateDirectory(tempDirectory);
+ Directory.CreateDirectory(kernelDirectory);
+ Directory.CreateDirectory(ramfsDirectory);
+ if (!ExecuteTool("unpackbootimg.exe", string.Format("-i \"{0}\" -o \"{1}\"", KernelDump, kernelDirectory)))
+ throw new Exception("Can't unpack kernel image");
+ if (!ExecuteTool("lzop.exe", string.Format("-d \"{0}\" -o \"{1}\"",
+ Path.Combine(kernelDirectory, "kernel.img-ramdisk.gz"), initramfs_cpio)))
+ throw new Exception("Can't unpack ramdisk");
+ ExecuteTool("cpio.exe", string.Format("-imd --no-preserve-owner --quiet -I \"{0}\"",
+ @"..\initramfs.cpio"), ramfsDirectory);
+ if (!File.Exists(Path.Combine(ramfsDirectory, "init"))) // cpio.exe fails on Windows XP for some reason. But working!
+ throw new Exception("Can't unpack ramdisk 2");
+ if (Directory.Exists(hakchiDirectory)) Directory.Delete(hakchiDirectory, true);
+ DirectoryCopy(Path.Combine(modsDirectory, Mod), ramfsDirectory, true);
+ var ramfsFiles = Directory.GetFiles(ramfsDirectory, "*.*", SearchOption.AllDirectories);
+ foreach (var file in ramfsFiles)
+ {
+ var fInfo = new FileInfo(file);
+ if (fInfo.Length > 10 && fInfo.Length < 100 && ((fInfo.Attributes & FileAttributes.System) == 0) &&
+ (Encoding.ASCII.GetString(File.ReadAllBytes(file), 0, 10)) == "!<symlink>")
+ fInfo.Attributes |= FileAttributes.System;
+ }
- if (Games != null)
- AddMenu(Games);
- if (HiddenGames != null && HiddenGames.Length > 0)
- {
- StringBuilder h = new StringBuilder();
- foreach (var game in HiddenGames)
- h.Append(game + "\n");
- File.WriteAllText(hiddenPath, h.ToString());
- }
- if (Config != null && Config.ContainsKey("hakchi_clovercon_hack")
+ if (HiddenGames != null && HiddenGames.Length > 0)
+ {
+ StringBuilder h = new StringBuilder();
+ foreach (var game in HiddenGames)
+ h.Append(game + "\n");
+ File.WriteAllText(hiddenPath, h.ToString());
+ }
+
+ if (Config != null && Config.ContainsKey("hakchi_clovercon_hack")
&& Config["hakchi_clovercon_hack"] && File.Exists(cloverconDriverPath))
- {
- byte[] drv = File.ReadAllBytes(cloverconDriverPath);
- const string magicReset = "MAGIC_BUTTONS:";
- for (int i = 0; i < drv.Length - magicReset.Length; i++)
{
- if (Encoding.ASCII.GetString(drv, i, magicReset.Length) == magicReset)
+ byte[] drv = File.ReadAllBytes(cloverconDriverPath);
+ const string magicReset = "MAGIC_BUTTONS:";
+ for (int i = 0; i < drv.Length - magicReset.Length; i++)
{
- int pos = i + magicReset.Length;
- for (int b = 0; b < 8; b++)
- drv[pos + b] = (byte)((((byte)ResetCombination & (1 << b)) != 0) ? '1' : '0');
- break;
+ if (Encoding.ASCII.GetString(drv, i, magicReset.Length) == magicReset)
+ {
+ int pos = i + magicReset.Length;
+ for (int b = 0; b < 8; b++)
+ drv[pos + b] = (byte)((((byte)ResetCombination & (1 << b)) != 0) ? '1' : '0');
+ break;
+ }
}
- }
- const string magicAutofire = "MAGIC_AUTOFIRE:";
- for (int i = 0; i < drv.Length - magicAutofire.Length; i++)
- {
- if (Encoding.ASCII.GetString(drv, i, magicAutofire.Length) == magicAutofire)
+ const string magicAutofire = "MAGIC_AUTOFIRE:";
+ for (int i = 0; i < drv.Length - magicAutofire.Length; i++)
{
- int pos = i + magicAutofire.Length;
- drv[pos] = (byte)(AutofireHack ? '1' : '0');
- break;
+ if (Encoding.ASCII.GetString(drv, i, magicAutofire.Length) == magicAutofire)
+ {
+ int pos = i + magicAutofire.Length;
+ drv[pos] = (byte)(AutofireHack ? '1' : '0');
+ break;
+ }
}
- }
- const string magicFcStart = "MAGIC_FC_START:";
- for (int i = 0; i < drv.Length - magicFcStart.Length; i++)
- {
- if (Encoding.ASCII.GetString(drv, i, magicFcStart.Length) == magicFcStart)
+ const string magicFcStart = "MAGIC_FC_START:";
+ for (int i = 0; i < drv.Length - magicFcStart.Length; i++)
{
- int pos = i + magicFcStart.Length;
- drv[pos] = (byte)(FcStart ? '1' : '0');
- break;
+ if (Encoding.ASCII.GetString(drv, i, magicFcStart.Length) == magicFcStart)
+ {
+ int pos = i + magicFcStart.Length;
+ drv[pos] = (byte)(FcStart ? '1' : '0');
+ break;
+ }
}
+ File.WriteAllBytes(cloverconDriverPath, drv);
}
- File.WriteAllBytes(cloverconDriverPath, drv);
+ if (!string.IsNullOrEmpty(ExtraCommandLineArguments))
+ {
+ File.WriteAllText(argumentsFilePath, ExtraCommandLineArguments);
+ }
+ } // if first transfer
+ else // else clean games directory and extra files
+ {
+ if (Directory.Exists(tempGamesDirectory))
+ {
+ Debug.WriteLine("Clearing games directory");
+ Directory.Delete(tempGamesDirectory, true);
+ Directory.CreateDirectory(tempGamesDirectory);
+ }
+ var dirs = Directory.GetDirectories(hakchiDirectory);
+ foreach (var dir in dirs)
+ Directory.Delete(dir, true);
+ var files = from f in Directory.GetFiles(hakchiDirectory) where (Path.GetFileName(f) != "init" && Path.GetFileName(f) != "config") select f;
+ foreach (var file in files)
+ File.Delete(file);
}
- if (!string.IsNullOrEmpty(ExtraCommandLineArguments))
+
+ // Games!
+ if (Games != null)
{
- File.WriteAllText(argumentsFilePath, ExtraCommandLineArguments);
+ stats.Next();
+ AddMenu(Games, stats);
+ Debug.WriteLine(string.Format("Games copied: {0}/{1}, part size: {2}", stats.GamesProceed, stats.GamesTotal, stats.Size));
}
+ // Remove thumbnails
if (Config != null && Config.ContainsKey("hakchi_remove_thumbnails") && Config["hakchi_remove_thumbnails"])
{
var thumbnails = Directory.GetFiles(tempGamesDirectory, "*_small.png", SearchOption.AllDirectories);
@@ -549,43 +575,11 @@ namespace com.clusterrr.hakchi_gui
File.WriteAllBytes(t, new byte[0]);
}
- var romFiles = new List<string>();
- romFiles.AddRange(Directory.GetFiles(ramfsDirectory, "*.nes", SearchOption.AllDirectories));
- romFiles.AddRange(Directory.GetFiles(ramfsDirectory, "*.desktop", SearchOption.AllDirectories));
- romFiles.AddRange(Directory.GetFiles(ramfsDirectory, "*.png", SearchOption.AllDirectories));
- romFiles.AddRange(Directory.GetFiles(ramfsDirectory, NesGame.GameGenieFileName, SearchOption.AllDirectories));
- ramfsFiles = romFiles.OrderBy(o => o).ToArray();
- totalFiles = ramfsFiles.Length;
- for (int i = 0; i < filesPos; i++)
- File.Delete(ramfsFiles[i]);
- if (filesPos > 0) // No first transfer? Remove all files
- {
- foreach (var file in
- Directory.GetFiles(ramfsDirectory, "*.ko", SearchOption.AllDirectories))
- File.Delete(file);
- foreach (var file in
- Directory.GetFiles(ramfsDirectory, "*.fnt", SearchOption.AllDirectories))
- File.Delete(file);
- foreach (var file in
- Directory.GetFiles(ramfsDirectory, "*.wav", SearchOption.AllDirectories))
- File.Delete(file);
- }
-
- long size = 0;
- while (filesPos < totalFiles)
- {
- var fsize = new FileInfo(ramfsFiles[filesPos]).Length;
- if (size >= maxRamfsSize) break;
- size += fsize;
- filesPos++;
- }
- for (int i = filesPos; i < totalFiles; i++)
- File.Delete(ramfsFiles[i]);
-
+ // Writing config files
if (Config != null)
{
Config["hakchi_partial_first"] = first;
- Config["hakchi_partial_last"] = filesPos >= totalFiles;
+ Config["hakchi_partial_last"] = stats.GamesProceed >= stats.GamesTotal;
var config = new StringBuilder();
foreach (var key in Config.Keys)
@@ -593,7 +587,8 @@ namespace com.clusterrr.hakchi_gui
File.WriteAllText(configPath, config.ToString());
}
- if (Games != null && Games.Count > 0) // There is no reason to compress cryptsetup when we do not uploading games
+ // Building image
+ if (first && Games != null && Games.Count > 0) // There is no reason to compress cryptsetup when we do not uploading games
ExecuteTool("upx.exe", "--best sbin\\cryptsetup", ramfsDirectory);
byte[] ramdisk;
if (!ExecuteTool("mkbootfs.exe", string.Format("\"{0}\"", ramfsDirectory), out ramdisk))
@@ -668,28 +663,49 @@ namespace com.clusterrr.hakchi_gui
}
}
- private void AddMenu(NesMenuCollection menuCollection, List<NesMenuCollection> allMenus = null)
+ private class GamesTreeStats
{
- if (allMenus == null)
- allMenus = new List<NesMenuCollection>();
- if (!allMenus.Contains(menuCollection))
- allMenus.Add(menuCollection);
- int menuIndex = allMenus.IndexOf(menuCollection);
+ public List<NesMenuCollection> allMenus = new List<NesMenuCollection>();
+ public int GamesTotal = 0;
+ public int GamesStart = 0;
+ public int GamesProceed = 0;
+ public long Size = 0;
+
+ public void Next()
+ {
+ allMenus.Clear();
+ GamesStart = GamesProceed;
+ GamesTotal = 0;
+ GamesProceed = 0;
+ Size = 0;
+ }
+ }
+
+ private void AddMenu(NesMenuCollection menuCollection, GamesTreeStats stats = null)
+ {
+ if (stats == null)
+ stats = new GamesTreeStats();
+ if (!stats.allMenus.Contains(menuCollection))
+ stats.allMenus.Add(menuCollection);
+ int menuIndex = stats.allMenus.IndexOf(menuCollection);
string targetDirectory;
if (menuIndex == 0)
targetDirectory = tempGamesDirectory;
else
targetDirectory = Path.Combine(tempGamesDirectory, string.Format("sub{0:D3}", menuIndex));
- if (Directory.Exists(targetDirectory))
- return;
foreach (var element in menuCollection)
{
if (element is NesGame)
{
+ stats.GamesTotal++;
+ if (stats.Size >= maxRamfsSize) continue;
+ stats.GamesProceed++;
+ if (stats.GamesStart >= stats.GamesProceed) continue;
var game = element as NesGame;
var gameDir = Path.Combine(targetDirectory, game.Code);
- Debug.WriteLine(string.Format("Processing {0} ('{1}')", game.Code, game.Name));
- DirectoryCopy(game.GamePath, gameDir, true);
+ Debug.Write(string.Format("Processing {0} ('{1}'), #{2}", game.Code, game.Name, stats.GamesProceed));
+ stats.Size += DirectoryCopy(game.GamePath, gameDir, true);
+ Debug.WriteLine(string.Format(", total size: {0}", stats.Size));
if (!string.IsNullOrEmpty(game.GameGenie))
{
var codes = game.GameGenie.Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
@@ -724,19 +740,27 @@ namespace com.clusterrr.hakchi_gui
if (element is NesMenuFolder)
{
var folder = element as NesMenuFolder;
- if (!allMenus.Contains(folder.Child))
- allMenus.Add(folder.Child);
- int childIndex = allMenus.IndexOf(folder.Child);
- var folderDir = Path.Combine(targetDirectory, folder.Code);
- folder.Save(folderDir, childIndex);
- AddMenu(folder.Child, allMenus);
+ if (!stats.allMenus.Contains(folder.Child))
+ {
+ stats.allMenus.Add(folder.Child);
+ AddMenu(folder.Child, stats);
+ }
+ if (stats.GamesStart == 0)
+ {
+ int childIndex = stats.allMenus.IndexOf(folder.Child);
+ var folderDir = Path.Combine(targetDirectory, folder.Code);
+ folder.Save(folderDir, childIndex);
+ }
}
if (element is NesDefaultGame)
{
- var game = element as NesDefaultGame;
- var gfilePath = Path.Combine(tempGamesDirectory, string.Format("gpath-{0}-{1}", game.Code, menuIndex));
- Directory.CreateDirectory(Path.GetDirectoryName(gfilePath));
- File.WriteAllText(gfilePath, menuIndex == 0 ? "." : string.Format("sub{0:D3}", menuIndex));
+ if (stats.GamesStart == 0)
+ {
+ var game = element as NesDefaultGame;
+ var gfilePath = Path.Combine(tempGamesDirectory, string.Format("gpath-{0}-{1}", game.Code, menuIndex));
+ Directory.CreateDirectory(Path.GetDirectoryName(gfilePath));
+ File.WriteAllText(gfilePath, menuIndex == 0 ? "." : string.Format("sub{0:D3}", menuIndex));
+ }
}
}
}
@@ -798,8 +822,9 @@ namespace com.clusterrr.hakchi_gui
return pages * page_size;
}
- private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
+ private static long DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
+ long size = 0;
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
@@ -822,7 +847,7 @@ namespace com.clusterrr.hakchi_gui
foreach (FileInfo file in files)
{
string temppath = Path.Combine(destDirName, file.Name);
- file.CopyTo(temppath, true);
+ size += file.CopyTo(temppath, true).Length;
}
// If copying subdirectories, copy them and their contents to new location.
@@ -831,9 +856,10 @@ namespace com.clusterrr.hakchi_gui
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
- DirectoryCopy(subdir.FullName, temppath, copySubDirs);
+ size += DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
+ return size;
}
bool YesForAllPatches = false;