public void TestMethod1() { using (var sourceStream = File.OpenRead(@"C:\Data\mongo-dump-2016-01-14.tar.gz")) using (var unZipStream = new System.IO.Compression.GZipStream(sourceStream, System.IO.Compression.CompressionMode.Decompress)) using (var tarStream = new TarStream(unZipStream)) { while (tarStream.NextFile()) { var taredFileExtention = Path.GetExtension(tarStream.CurrentFilename); if (tarStream.CurrentFilename == "dump/github/org_members.bson") //taredFileExtention == ".bson") { using (var output = File.Create("org_members.bson")) { Byte[] outputBytes = new byte[8196]; while (tarStream.Read(outputBytes, 0, 8196) > 0) { output.Write(outputBytes, 0, outputBytes.Length); } } } } ; } }
public void TestMethod1() { using (var sourceStream = File.OpenRead(@"C:\Data\mongo-dump-2016-01-14.tar.gz")) using (var unZipStream = new System.IO.Compression.GZipStream(sourceStream, System.IO.Compression.CompressionMode.Decompress)) using (var tarStream = new TarStream(unZipStream)) { while (tarStream.NextFile()) { var taredFileExtention = Path.GetExtension(tarStream.CurrentFilename); if (tarStream.CurrentFilename == "dump/github/org_members.bson") //taredFileExtention == ".bson") { using (var output = File.Create("org_members.bson")) { Byte[] outputBytes = new byte[8196]; while (tarStream.Read(outputBytes, 0, 8196) > 0) { output.Write(outputBytes, 0, outputBytes.Length); } } } }; } }
public Tasker.Conclusion SyncRemoteGamesShell(Tasker tasker, Object syncObject = null) { // transfer games tasker.SetProgress(0, 100, Tasker.State.Running, Resources.UploadingGames); bool uploadSuccessful = false; if (!transferGameSet.Any()) { Trace.WriteLine("No file to upload"); uploadSuccessful = true; } else { Trace.WriteLine("Uploading through tar file"); using (var gamesTar = new TarStream(transferGameSet, ".")) { Trace.WriteLine($"Upload size: " + Shared.SizeSuffix(gamesTar.Length)); if (gamesTar.Length > 0) { DateTime startTime = DateTime.Now, lastTime = DateTime.Now; bool done = false; gamesTar.OnAdvancedReadProgress += delegate(long pos, long len, string filename) { if (done) { return; } if (DateTime.Now.Subtract(lastTime).TotalMilliseconds >= UpdateFreq) { transferForm.SetAdvancedProgress(pos, len, filename); lastTime = DateTime.Now; } }; hakchi.Shell.Execute($"tar -xvC \"{uploadPath}\"", gamesTar, null, null, 0, true); Trace.WriteLine("Uploaded " + (int)(gamesTar.Length / 1024) + "kb in " + DateTime.Now.Subtract(startTime).TotalSeconds + " seconds"); uploadSuccessful = true; done = true; #if VERY_DEBUG File.Delete(Program.BaseDirectoryExternal + "\\DebugSyncOutput.tar"); gamesTar.Position = 0; gamesTar.CopyTo(File.OpenWrite(Program.BaseDirectoryExternal + "\\DebugSyncOutput.tar")); #endif } transferForm.SetAdvancedProgress(gamesTar.Length, gamesTar.Length, ""); } } // don't continue if upload wasn't successful if (!uploadSuccessful) { Trace.WriteLine("Something happened during transfer, cancelling"); return(Tasker.Conclusion.Error); } return(Tasker.Conclusion.Success); }
public static TaskFunc TransferHmod(string transferPath, string hmod) { return((Tasker tasker, Object syncObject) => { tasker.SetStatus(Resources.TransferringMods); var modName = hmod + ".hmod"; foreach (var dir in Shared.hmodDirectories) { string hmodHakchiPath = Shared.EscapeShellArgument($"{transferPath}/{modName}"); if (Directory.Exists(Path.Combine(dir, modName))) { hakchi.Shell.ExecuteSimple($"mkdir -p {hmodHakchiPath}"); using (var hmodTar = new TarStream(Path.Combine(dir, modName))) { if (hmodTar.Length > 0) { using (TrackableStream hmodStream = new TrackableStream(hmodTar)) { hmodStream.OnProgress += tasker.OnProgress; hakchi.Shell.Execute($"tar -xvC {hmodHakchiPath}", hmodStream, null, null, 0, true); } } } break; } if (File.Exists(Path.Combine(dir, modName))) { hakchi.Shell.ExecuteSimple($"mkdir -p {hmodHakchiPath}"); using (var hmodStream = new TrackableFileStream(Path.Combine(dir, modName), FileMode.Open)) { hmodStream.OnProgress += tasker.OnProgress; hakchi.Shell.Execute($"tar -xzvC {hmodHakchiPath}", hmodStream, null, null, 0, true); } break; } } return Conclusion.Success; }); }
private void buttonSync_Click(object sender, EventArgs e) { const string src_backgroundPath = "/var/lib/hakchi/squashfs/usr/share/backgrounds"; const string dest_backgroundPath = "/var/lib/hakchi/rootfs/usr/share/backgrounds"; var clovershell = MainForm.Clovershell; string bgDirectory = BorderElement.BackgroundsDirectory; SaveSelectedBorders(); ConfigIni.Save(); string baseDirectoryInternal = Program.BaseDirectoryInternal; string tempDirectory; #if DEBUG tempDirectory = Path.Combine(baseDirectoryInternal, "temp"); #else tempDirectory = Path.Combine(Path.GetTempPath(), "hakchi-temp"); #endif string tempBordersDirectory = Path.Combine(tempDirectory, "borders"); Directory.CreateDirectory(tempDirectory); Directory.CreateDirectory(tempBordersDirectory); labelSyncing.Text = "Making sync"; progressBarSync.Value = 0; labelSyncing.Visible = true; progressBarSync.Visible = true; labelSyncing.Refresh(); progressBarSync.Refresh(); if (clovershell.IsOnline) { this.Enabled = false; try { /*labelSyncing.Text = "Deleting a file"; * labelSyncing.Refresh(); * progressBarSync.Value = 10; * progressBarSync.Refresh(); * string del_cmd = $"rm /etc/preinit.d/p8173_ownbgs"; * clovershell.ExecuteSimple(del_cmd, 3000); * Thread.Sleep(1000); * labelSyncing.Text = "Reboot..."; * labelSyncing.Refresh(); * progressBarSync.Value = 20; * progressBarSync.Refresh(); * clovershell.ExecuteSimple("reboot", 3000); * Thread.Sleep(2000); * labelSyncing.Text = "Waiting reboot..."; * labelSyncing.Refresh(); * progressBarSync.Value = 30; * progressBarSync.Refresh(); * while (!(clovershell.IsOnline)) * { * Debug.WriteLine("Wait reboot"); * Thread.Sleep(2000); * } */ labelSyncing.Text = "Creating directory..."; labelSyncing.Refresh(); progressBarSync.Value = 10; progressBarSync.Refresh(); string command = $"src=\"{src_backgroundPath}\" && " + $"dst=\"{dest_backgroundPath}\" && " + $"rm -rf \"$dst\" && " + $"mkdir -p \"$dst\""; clovershell.ExecuteSimple(command, 10000, true); foreach (ListViewItem border in listViewBorders.CheckedItems) { if (border.Tag is BorderElement) { string repName = (border.Tag as BorderElement).Name; DirectoryInfo diSource = new DirectoryInfo(bgDirectory + "/" + repName); DirectoryInfo diTarget = new DirectoryInfo(tempBordersDirectory + "/" + repName); CopyAll(diSource, diTarget); } } string[] lines = { "overmount /usr/share/backgrounds/", "" }; System.IO.File.WriteAllLines(tempBordersDirectory + "/" + "p8173_ownbgs", lines); labelSyncing.Text = "Uploading user borders..."; labelSyncing.Refresh(); progressBarSync.Value = 20; progressBarSync.Refresh(); using (var bordersTar = new TarStream(tempBordersDirectory)) { if (bordersTar.Length > 0) { bordersTar.OnReadProgress += delegate(long pos, long len) { Debug.WriteLine("SetProgress(" + pos.ToString() + ", " + len.ToString()); }; clovershell.Execute(string.Format("tar -xvC {0}", dest_backgroundPath), bordersTar, null, null, 30000, true); } } string move_cmd = $"mv {dest_backgroundPath}/p8173_ownbgs /etc/preinit.d/"; clovershell.ExecuteSimple(move_cmd, 3000, true); labelSyncing.Text = "Managing default borders..."; labelSyncing.Refresh(); progressBarSync.Value = 80; progressBarSync.Refresh(); if (listViewBorders.Items[0].Checked) { var selected = new List <string>(); foreach (DefaultBorder border in checkedListBoxDefaultBorders.CheckedItems) { selected.Add(border.Name); } foreach (string bordername in selected) { string cmd = $"src=\"{src_backgroundPath}/{bordername}\" && " + $"dst=\"{dest_backgroundPath}/{bordername}\" && " + $"ln -s \"$src\" \"$dst\""; clovershell.ExecuteSimple(cmd, 10000, true); } } } finally { try { labelSyncing.Text = "Reboot..."; labelSyncing.Refresh(); progressBarSync.Value = 100; progressBarSync.Refresh(); Directory.Delete(tempDirectory, true); if (clovershell.IsOnline) { clovershell.ExecuteSimple("reboot", 100); } } catch { } MessageBox.Show(this, "work is done", "Custom borders", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Enabled = true; this.Close(); } } }
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 { } } }