public void UploadGames() { const string gamesPath = "/usr/share/games/nes/kachikachi"; const string rootFsPath = "/var/lib/hakchi/rootfs"; const string installPath = "/var/lib/hakchi"; int progress = 0; int maxProgress = 400; if (Games == null || Games.Count == 0) { throw new Exception("there are no games"); } SetStatus(Resources.BuildingFolders); if (FoldersMode == NesMenuCollection.SplitStyle.Custom) { if (FoldersManagerFromThread(Games) != System.Windows.Forms.DialogResult.OK) { DialogResult = DialogResult.Abort; return; } Games.AddBack(); } else { Games.Split(FoldersMode, MaxGamesPerFolder); } progress += 5; SetProgress(progress, maxProgress); var clovershell = MainForm.Clovershell; try { if (WaitForClovershellFromThread() != DialogResult.OK) { DialogResult = DialogResult.Abort; return; } progress += 5; SetProgress(progress, maxProgress); new clovershell.ClovershellWrapper(clovershell).ShowSplashScreen(); SetStatus(Resources.BuildingFolders); if (Directory.Exists(tempDirectory)) { Directory.Delete(tempDirectory, true); } Directory.CreateDirectory(tempDirectory); // Games! tempGamesDirectory = Path.Combine(tempDirectory, "games"); Directory.CreateDirectory(tempDirectory); Directory.CreateDirectory(tempGamesDirectory); Dictionary <string, string> originalGames = new Dictionary <string, string>(); var stats = new GamesTreeStats(); AddMenu(Games, originalGames, stats); progress += 5; SetProgress(progress, maxProgress); GetMemoryStats(); var maxGamesSize = (NandCFree + WritedGamesSize) - ReservedMemory * 1024 * 1024; if (stats.TotalSize > maxGamesSize) { throw new Exception(string.Format(Resources.MemoryFull, stats.TotalSize / 1024 / 1024) + "\r\n\r\n" + string.Format(Resources.MemoryStats.Replace("|", "\r\n"), NandCTotal / 1024.0 / 1024.0, (NandCFree + WritedGamesSize - ReservedMemory * 1024 * 1024) / 1024 / 1024, SaveStatesSize / 1024.0 / 1024.0, (NandCUsed - WritedGamesSize - SaveStatesSize) / 1024.0 / 1024.0)); } int startProgress = progress; using (var gamesTar = new TarStream(tempGamesDirectory)) { 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) { 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), gamesTar, null, null, 30000, true); } } SetStatus(Resources.UploadingOriginalGames); startProgress = progress; foreach (var originalCode in originalGames.Keys) { clovershell.ExecuteSimple(string.Format(@"mkdir -p ""{2}{3}/{1}/{0}/"" && rsync -ac ""{3}/{0}/"" ""{2}{3}/{1}/{0}/"" && sed -i -e 's/\/usr\/bin\/clover-kachikachi/\/bin\/clover-kachikachi-wr/g' ""{2}{3}/{1}/{0}/{0}.desktop""", originalCode, originalGames[originalCode], rootFsPath, gamesPath), 5000, true); progress += 2; SetProgress(progress, maxProgress); } ; SetStatus(Resources.UploadingConfig); SyncConfig(Config); #if !DEBUG Directory.Delete(tempDirectory, true); #endif SetStatus(Resources.Done); SetProgress(maxProgress, maxProgress); } finally { try { if (clovershell.IsOnline) { clovershell.ExecuteSimple("reboot", 100); } } catch { } } }
public void Memboot() { int progress = 0; int maxProgress = -1; var stats = new GamesTreeStats(); if (Games != null) { SetStatus(Resources.BuildingFolders); if (FoldersMode == NesMenuCollection.SplitStyle.Custom) { if (FolderManagerFromThread(Games) != System.Windows.Forms.DialogResult.OK) { DialogResult = DialogResult.Abort; return; } Games.AddBack(); } else { Games.Split(FoldersMode, MaxGamesPerFolder); } } progress += 5; SetProgress(progress, 300); do { if (stats.GamesProceed > 0) { ShowMessage(Resources.ParticallyBody, Resources.ParticallyTitle); } GC.Collect(); // Connecting to NES Mini if (WaitForDeviceFromThread() != DialogResult.OK) { DialogResult = DialogResult.Abort; return; } progress += 5; SetProgress(progress, maxProgress > 0 ? maxProgress : 300); byte[] kernel; if (!string.IsNullOrEmpty(Mod)) { kernel = CreatePatchedKernel(stats); } else { kernel = File.ReadAllBytes(KernelDump); } var size = CalKernelSize(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; size = size * Fel.sector_size; if (kernel.Length != size) { var newK = new byte[size]; Array.Copy(kernel, newK, kernel.Length); kernel = newK; } progress += 5; if (maxProgress < 0) { if (stats.GamesProceed > 0) { maxProgress = (kernel.Length / 67000 + 20) * stats.GamesTotal / stats.GamesProceed + 75 * ((int)Math.Ceiling((float)stats.GamesTotal / (float)stats.GamesProceed) - 1); } else { maxProgress = (kernel.Length / 67000 + 20); } } SetProgress(progress, maxProgress); SetStatus(Resources.UploadingKernel); fel.WriteMemory(Fel.flash_mem_base, kernel, delegate(Fel.CurrentAction action, string command) { switch (action) { case Fel.CurrentAction.WritingMemory: SetStatus(Resources.UploadingKernel); break; } progress++; SetProgress(progress, maxProgress); } ); var bootCommand = string.Format("boota {0:x}", Fel.kernel_base_m); SetStatus(Resources.ExecutingCommand + " " + bootCommand); fel.RunUbootCmd(bootCommand, true); } while (stats.GamesProceed < stats.GamesTotal); SetStatus(Resources.Done); SetProgress(maxProgress, maxProgress); }