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-17 02:07:25 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-03-17 02:07:25 +0300
commit7b7b043985365e370bb58333b9bf1ded7e44fe71 (patch)
tree988acc0fc878faad5c73d3ff5e7955d550f85560
parentfe74b3f3b5f7d0fa4d21e1adf4163ffaa7fe36ac (diff)
Better progress display
-rw-r--r--Clovershell/ClovershellConnection.cs2
-rw-r--r--MainForm.cs2
-rw-r--r--TrackableMemoryStream.cs6
-rw-r--r--WorkerForm.cs74
4 files changed, 47 insertions, 37 deletions
diff --git a/Clovershell/ClovershellConnection.cs b/Clovershell/ClovershellConnection.cs
index 9385513a..acdeae75 100644
--- a/Clovershell/ClovershellConnection.cs
+++ b/Clovershell/ClovershellConnection.cs
@@ -487,7 +487,7 @@ namespace com.clusterrr.clovershell
if (c == null) return;
if (c.stdout != null)
c.stdout.Write(data, pos, len);
- //Debug.WriteLine("stdout: " + Encoding.UTF8.GetString(data, pos, len));
+ Debug.WriteLine("stdout: " + Encoding.UTF8.GetString(data, pos, len));
if (len == 0)
c.stdoutFinished = true;
}
diff --git a/MainForm.cs b/MainForm.cs
index 7472eaee..528088b6 100644
--- a/MainForm.cs
+++ b/MainForm.cs
@@ -440,7 +440,7 @@ namespace com.clusterrr.hakchi_gui
{
if (game is NesMiniApplication)
{
- // Maybe type was changed? Need to reload gamed
+ // Maybe type was changed? Need to reload games
if ((game as NesMiniApplication).Save())
checkedListBoxGames.Items[i] = NesMiniApplication.FromDirectory((game as NesMiniApplication).GamePath);
}
diff --git a/TrackableMemoryStream.cs b/TrackableMemoryStream.cs
index 1737997f..cd3b9651 100644
--- a/TrackableMemoryStream.cs
+++ b/TrackableMemoryStream.cs
@@ -10,6 +10,8 @@ namespace com.clusterrr.util
{
public delegate void OnProgressDelegate(long Position, long Length);
public event OnProgressDelegate OnProgress = delegate { };
+ public event OnProgressDelegate OnReadProgress = delegate { };
+ public event OnProgressDelegate OnWriteProgress = delegate { };
public TrackableMemoryStream() : base() { }
public TrackableMemoryStream(byte[] buffer) : base(buffer) { }
@@ -18,22 +20,26 @@ namespace com.clusterrr.util
{
base.Write(array, offset, count);
OnProgress(this.Position, this.Length);
+ OnWriteProgress(this.Position, this.Length);
}
public override void WriteByte(byte value)
{
base.WriteByte(value);
OnProgress(this.Position, this.Length);
+ OnWriteProgress(this.Position, this.Length);
}
public override int Read(byte[] array, int offset, int count)
{
var r = base.Read(array, offset, count);
OnProgress(this.Position, this.Length);
+ OnReadProgress(this.Position, this.Length);
return r;
}
public override int ReadByte()
{
var r = base.ReadByte();
OnProgress(this.Position, this.Length);
+ OnReadProgress(this.Position, this.Length);
return r;
}
}
diff --git a/WorkerForm.cs b/WorkerForm.cs
index 05e7a44f..af4e2a9a 100644
--- a/WorkerForm.cs
+++ b/WorkerForm.cs
@@ -9,6 +9,7 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
+using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
@@ -473,27 +474,27 @@ namespace com.clusterrr.hakchi_gui
public void UploadGames()
{
- var clovershell = MainForm.Clovershell;
- try
+ 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)
{
- int progress = 0;
- int maxProgress = 355;
- if (Games == null || Games.Count == 0)
- throw new Exception("there are no games");
- SetStatus(Resources.BuildingFolders);
- if (FoldersMode == NesMenuCollection.SplitStyle.Custom)
+ if (FolderManagerFromThread(Games) != System.Windows.Forms.DialogResult.OK)
{
- if (FolderManagerFromThread(Games) != System.Windows.Forms.DialogResult.OK)
- {
- DialogResult = DialogResult.Abort;
- return;
- }
- Games.AddBack();
+ DialogResult = DialogResult.Abort;
+ return;
}
- else Games.Split(FoldersMode, MaxGamesPerFolder);
- progress += 5;
- SetProgress(progress, maxProgress);
+ Games.AddBack();
+ }
+ else Games.Split(FoldersMode, MaxGamesPerFolder);
+ progress += 5;
+ SetProgress(progress, maxProgress);
+ var clovershell = MainForm.Clovershell;
+ try
+ {
if (WaitForClovershellFromThread() != DialogResult.OK)
{
DialogResult = DialogResult.Abort;
@@ -543,13 +544,14 @@ namespace com.clusterrr.hakchi_gui
if (!ExecuteTool("tar.exe", "-c *", out gamesTar, tempGamesDirectory))
throw new Exception("can't pack games");
progress += 5;
- maxProgress = gamesTar.Length / 1024 / 1024 + 55;
+ maxProgress = gamesTar.Length / 1024 / 1024 + 85;
SetProgress(progress, maxProgress);
var gamesStream = new TrackableMemoryStream(gamesTar);
- gamesStream.OnProgress += delegate(long pos, long len)
+ int startProgress = progress;
+ gamesStream.OnReadProgress += delegate(long pos, long len)
{
- progress = (int)(20 + pos / 1024 / 1024);
+ progress = (int)(startProgress + pos / 1024 / 1024);
SetProgress(progress, maxProgress);
};
@@ -563,36 +565,38 @@ namespace com.clusterrr.hakchi_gui
if (!ExecuteTool("tar.exe", "-c *", out originalGamesTar, originalGamesConfigDirectory))
throw new Exception("can't pack original games");
var originalGamesStream = new MemoryStream(originalGamesTar);
- clovershell.Execute("source /etc/preinit && script_init && mkdir -p $temppath/games && tar -xvC $temppath/games", originalGamesStream, null, null, 30000, true);
- clovershell.Execute("source /etc/preinit && script_init && source $installpath/script/games && cd $temppath && target_dir=$rootfs$gamepath && transfer_original_games games", null, null, null, 30000, true);
+ clovershell.Execute("source /etc/preinit && script_init && mkdir -p $temppath/games && tar -xvC $temppath/games", originalGamesStream, null, null, 1000, true);
+ var originalGamesStreamOut = new TrackableMemoryStream();
+ startProgress = progress;
+ originalGamesStreamOut.OnWriteProgress += delegate(long pos, long len)
+ {
+ var data = new byte[originalGamesStreamOut.Length];
+ originalGamesStreamOut.Seek(0, SeekOrigin.Begin);
+ originalGamesStreamOut.Read(data, 0, (int)originalGamesStreamOut.Length);
+ var str = Encoding.UTF8.GetString(data);
+ progress = startProgress + Regex.Matches(str, "CLV-").Count*2;
+ SetProgress(progress, maxProgress);
+ };
+ clovershell.Execute("source /etc/preinit && script_init && source $installpath/script/games && cd $temppath && target_dir=$rootfs$gamepath && transfer_original_games games", null, originalGamesStreamOut, null, 30000, true);
originalGamesStream.Dispose();
- progress += 30;
- SetProgress(progress, maxProgress);
+ originalGamesStreamOut.Dispose();
SetStatus(Resources.UploadingConfig);
SyncConfig(Config);
-
- try
- {
- clovershell.Execute("reboot", null, null, null, 1000);
- }
- catch { }
#if !DEBUG
- Directory.Delete(tempDirectory, true);
+ Directory.Delete(tempDirectory, true);
#endif
SetStatus(Resources.Done);
SetProgress(maxProgress, maxProgress);
}
- catch (Exception ex)
+ finally
{
- // Turn off console in case of error/cancel
try
{
if (clovershell.IsOnline)
- clovershell.Execute("poweroff", null, null, null, 100);
+ clovershell.Execute("reboot", null, null, null, 100);
}
catch { }
- throw ex;
}
}