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-03-29 01:25:16 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-03-29 01:25:16 +0300
commit24145e9db04513d15b7cb60f033a9e9d863f5de7 (patch)
treeb7c6f4edd6b12f7439d65c6a3cbbc8bfc67bc212 /WorkerForm.cs
parent99ad7ec16c71750a577b7604206864ed4b23da76 (diff)
On-the-fly tar archiving, it's using not so much memory now. And faster.
Diffstat (limited to 'WorkerForm.cs')
-rw-r--r--WorkerForm.cs105
1 files changed, 34 insertions, 71 deletions
diff --git a/WorkerForm.cs b/WorkerForm.cs
index a7bc60e5..b13fa926 100644
--- a/WorkerForm.cs
+++ b/WorkerForm.cs
@@ -58,7 +58,6 @@ namespace com.clusterrr.hakchi_gui
//string originalGamesConfigDirectory;
//string hiddenPath;
string[] correctKernels;
- long maxRamfsSize = 40 * 1024 * 1024;
const long maxCompressedsRamfsSize = 30 * 1024 * 1024;
string selectedFile = null;
public NesMiniApplication[] addedApplications;
@@ -361,7 +360,7 @@ namespace com.clusterrr.hakchi_gui
}
);
- var size = CalKernelSize(kernel);
+ var size = CalcKernelSize(kernel);
if (size == 0 || size > Fel.kernel_max_size)
throw new Exception(Resources.InvalidKernelSize + " " + size);
if (kernel.Length > size)
@@ -416,7 +415,7 @@ namespace com.clusterrr.hakchi_gui
}
else
kernel = File.ReadAllBytes(KernelDump);
- var size = CalKernelSize(kernel);
+ var size = CalcKernelSize(kernel);
if (size > kernel.Length || size > Fel.kernel_max_size)
throw new Exception(Resources.InvalidKernelSize + " " + size);
@@ -534,8 +533,6 @@ namespace com.clusterrr.hakchi_gui
Directory.CreateDirectory(tempGamesDirectory);
Dictionary<string, string> originalGames = new Dictionary<string, string>();
var stats = new GamesTreeStats();
- maxRamfsSize = -1;
- stats.Next();
AddMenu(Games, originalGames, stats);
progress += 5;
SetProgress(progress, maxProgress);
@@ -551,32 +548,26 @@ namespace com.clusterrr.hakchi_gui
(MainForm.NandCUsed - MainForm.WritedGamesSize - MainForm.SaveStatesSize) / 1024.0 / 1024.0));
}
- byte[] gamesTar;
- if (Directory.GetDirectories(tempGamesDirectory).Count() > 0)
- {
- if (!ExecuteTool("tar.exe", "-c *", out gamesTar, tempGamesDirectory))
- throw new Exception("can't pack games");
- }
- else gamesTar = new byte[0];
- progress += 5;
- maxProgress = gamesTar.Length / 1024 / 1024 + 25 + originalGames.Count() * 2;
- SetProgress(progress, maxProgress);
-
- clovershell.ExecuteSimple(string.Format("umount {0}", gamesPath));
- clovershell.ExecuteSimple(string.Format("rm -rf {0}{1}/CLV-* {0}{1}/??? {2}/menu", rootFsPath, gamesPath, installPath), 5000, true);
int startProgress = progress;
- if (gamesTar.Length > 0)
+ using (var gamesTar = new TarStream(tempGamesDirectory))
{
- var gamesStream = new TrackableMemoryStream(gamesTar);
- gamesStream.OnReadProgress += delegate(long pos, long len)
+ maxProgress = (int)(gamesTar.Length / 1024 / 1024 + 20 + originalGames.Count() * 2);
+ SetProgress(progress, maxProgress);
+
+ clovershell.ExecuteSimple(string.Format("umount {0}", gamesPath));
+ clovershell.ExecuteSimple(string.Format("rm -rf {0}{1}/CLV-* {0}{1}/??? {2}/menu", rootFsPath, gamesPath, installPath), 5000, true);
+
+ if (gamesTar.Length > 0)
{
- progress = (int)(startProgress + pos / 1024 / 1024);
- SetProgress(progress, maxProgress);
- };
+ gamesTar.OnReadProgress += delegate(long pos, long len)
+ {
+ progress = (int)(startProgress + pos / 1024 / 1024);
+ SetProgress(progress, maxProgress);
+ };
- SetStatus(Resources.UploadingGames);
- clovershell.Execute(string.Format("tar -xvC {0}{1}", rootFsPath, gamesPath), gamesStream, null, null, 30000, true);
- gamesStream.Dispose();
+ SetStatus(Resources.UploadingGames);
+ clovershell.Execute(string.Format("tar -xvC {0}{1}", rootFsPath, gamesPath), gamesTar, null, null, 30000, true);
+ }
}
SetStatus(Resources.UploadingOriginalGames);
@@ -646,14 +637,10 @@ namespace com.clusterrr.hakchi_gui
byte[] kernel;
if (!string.IsNullOrEmpty(Mod))
- {
kernel = CreatePatchedKernel();
- if (kernel.Length > maxCompressedsRamfsSize)
- Debug.WriteLine(string.Format("Kernel size is too big: {0}MB, reducing max unpacked size to {1}MB", kernel.Length / 1024 / 1024, maxRamfsSize / 1024 / 1024));
- }
else
kernel = File.ReadAllBytes(KernelDump);
- var size = CalKernelSize(kernel);
+ var size = CalcKernelSize(kernel);
if (size > kernel.Length || size > Fel.kernel_max_size)
throw new Exception(Resources.InvalidKernelSize + " " + size);
size = (size + Fel.sector_size - 1) / Fel.sector_size;
@@ -827,22 +814,8 @@ namespace com.clusterrr.hakchi_gui
{
public List<NesMenuCollection> allMenus = new List<NesMenuCollection>();
public int TotalGames = 0;
- public int GamesStart = 0;
- public int GamesProceed = 0;
- public long Size = 0;
public long TotalSize = 0;
- public bool Stopped;
-
- public void Next()
- {
- allMenus.Clear();
- GamesStart = GamesProceed;
- TotalGames = 0;
- GamesProceed = 0;
- Size = 0;
- TotalSize = 0;
- Stopped = false;
- }
+ public long TransferSize = 0;
}
private void AddMenu(NesMenuCollection menuCollection, Dictionary<string, string> originalGames, GamesTreeStats stats = null)
@@ -864,19 +837,11 @@ namespace com.clusterrr.hakchi_gui
stats.TotalGames++;
var game = element as NesMiniApplication;
var gameSize = game.Size();
- if (maxRamfsSize > 0 && gameSize >= maxRamfsSize) throw new Exception(string.Format(Resources.GameTooBig, game.Name));
- stats.TotalSize += gameSize;
- if ((maxRamfsSize > 0) && (stats.Stopped || stats.Size + gameSize >= maxRamfsSize))
- {
- stats.Stopped = true;
- continue;
- }
- stats.GamesProceed++;
- if (stats.GamesStart >= stats.GamesProceed) continue;
- Debug.Write(string.Format("Processing {0} ('{1}'), #{2}", game.Code, game.Name, stats.GamesProceed));
+ Debug.WriteLine(string.Format("Processing {0} ('{1}'), size: {2}KB", game.Code, game.Name, gameSize / 1024));
var gameCopy = game.CopyTo(targetDirectory);
- stats.Size += gameSize;
- Debug.WriteLine(string.Format(", total size: {0}", stats.Size));
+ stats.TotalSize += gameSize;
+ stats.TransferSize += gameSize;
+ stats.TotalGames++;
try
{
if (gameCopy is NesGame && File.Exists((gameCopy as NesGame).GameGeniePath))
@@ -902,20 +867,18 @@ namespace com.clusterrr.hakchi_gui
stats.allMenus.Add(folder.ChildMenuCollection);
AddMenu(folder.ChildMenuCollection, originalGames, stats);
}
- if (stats.GamesStart == 0)
- {
- folder.ChildIndex = stats.allMenus.IndexOf(folder.ChildMenuCollection);
- var folderDir = Path.Combine(targetDirectory, folder.Code);
- folder.Save(folderDir);
- }
+ folder.ChildIndex = stats.allMenus.IndexOf(folder.ChildMenuCollection);
+ var folderDir = Path.Combine(targetDirectory, folder.Code);
+ var folderSize = folder.Save(folderDir);
+ stats.TotalSize += folderSize;
+ stats.TransferSize += folderSize;
+
}
if (element is NesDefaultGame)
{
- if (stats.GamesStart == 0)
- {
- var game = element as NesDefaultGame;
- originalGames[game.Code] = menuIndex == 0 ? "." : string.Format("{0:D3}", menuIndex);
- }
+ var game = element as NesDefaultGame;
+ stats.TotalSize += game.Size;
+ originalGames[game.Code] = menuIndex == 0 ? "." : string.Format("{0:D3}", menuIndex);
}
}
}
@@ -957,7 +920,7 @@ namespace com.clusterrr.hakchi_gui
return process.ExitCode == 0;
}
- static UInt32 CalKernelSize(byte[] header)
+ static UInt32 CalcKernelSize(byte[] header)
{
if (Encoding.ASCII.GetString(header, 0, 8) != "ANDROID!") throw new Exception(Resources.InvalidKernelHeader);
UInt32 kernel_size = (UInt32)(header[8] | (header[9] * 0x100) | (header[10] * 0x10000) | (header[11] * 0x1000000));