Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/clovershell-client.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-11 22:50:03 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-03-11 22:50:03 +0300
commit110a1ec7d882bd43454fd178156d4d6812813849 (patch)
tree544d6323149dd3ca50a9fe0eaa74845831600881
parent82ba762f9466e04da3aa8173112449f69465dea2 (diff)
push/pull progress
-rw-r--r--CloverShell.csproj1
-rw-r--r--CloverShell/ClovershellConnection.cs5
-rw-r--r--Program.cs39
3 files changed, 35 insertions, 10 deletions
diff --git a/CloverShell.csproj b/CloverShell.csproj
index d3f1601..8d9d294 100644
--- a/CloverShell.csproj
+++ b/CloverShell.csproj
@@ -197,6 +197,7 @@
<Compile Include="LibWinUsb\WinUsb\WinUsbRegistry.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="TrackableFileStream.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="LibWinUsb\LibUsbDotNet.csproj" />
diff --git a/CloverShell/ClovershellConnection.cs b/CloverShell/ClovershellConnection.cs
index eeaddc6..d212420 100644
--- a/CloverShell/ClovershellConnection.cs
+++ b/CloverShell/ClovershellConnection.cs
@@ -595,16 +595,13 @@ namespace com.clusterrr.clovershell
if (timeout > 0 && IdleTime.TotalMilliseconds > timeout)
throw new Exception("clovershell read timeout");
}
-
if (throwOnNonZero && c.result != 0)
{
string errText = "";
if (stderr is MemoryStream)
{
stderr.Seek(0, SeekOrigin.Begin);
- var buff = new byte[stderr.Length];
- stderr.Read(buff, 0, buff.Length);
- errText = ": " + Encoding.UTF8.GetString(buff);
+ errText = ": " + new StreamReader(stderr).ReadToEnd();
}
throw new Exception(string.Format("shell command \"{0}\" returned exit code {1}{2}", command, c.result, errText));
}
diff --git a/Program.cs b/Program.cs
index 5bdc8f2..8baf1a1 100644
--- a/Program.cs
+++ b/Program.cs
@@ -9,6 +9,7 @@ using System.Diagnostics;
using System.IO;
using System.Reflection;
using com.clusterrr.clovershell;
+using com.clusterrr.util;
namespace com.clusterrr.clovershell
{
@@ -19,6 +20,7 @@ namespace com.clusterrr.clovershell
string source;
string target;
int result = -1;
+ int top, left;
#if DEBUG
Debug.Listeners.Add(new TextWriterTraceListener(System.Console.Error));
#endif
@@ -107,7 +109,22 @@ namespace com.clusterrr.clovershell
target = target.Substring(pos + 1);
}
source = source.Replace("'", "\\'");
- result = nes.Execute("cat '" + source + "'", null, new FileStream(target, FileMode.Create), Console.OpenStandardError());
+ var sizeMS = new MemoryStream();
+ nes.Execute(string.Format("stat -c %s \"{0}\"", source), null, sizeMS, null, 1000, true);
+ sizeMS.Seek(0, SeekOrigin.Begin);
+ var size = int.Parse(new StreamReader(sizeMS).ReadToEnd());
+ Console.Write("Reading {0}... ", source);
+ top = Console.CursorTop;
+ left = Console.CursorLeft;
+ var outFile = new TrackableFileStream(target, FileMode.Create);
+ outFile.OnProgress += delegate(long Position, long Length)
+ {
+ Console.CursorTop = top;
+ Console.CursorLeft = left;
+ Console.Write("{0} / {1} ({2}%) ", Position, size > 0 ? size.ToString() : "???", size > 0 ? (Position * 100 / size).ToString() : "???");
+ };
+ result = nes.Execute("cat '" + source + "'", null, outFile, Console.OpenStandardError(), 1000, true);
+ Console.Write("Done.");
break;
case "push":
if (args.Length < 3)
@@ -117,8 +134,18 @@ namespace com.clusterrr.clovershell
}
source = args[1];
target = args[2];
- target=target.Replace("'", "\\'");
- result = nes.Execute("cat > '" + target + "'", new FileStream(source, FileMode.Open), Console.OpenStandardOutput(), Console.OpenStandardError());
+ target = target.Replace("'", "\\'");
+ top = Console.CursorTop;
+ left = Console.CursorLeft;
+ var inFile = new TrackableFileStream(source, FileMode.Open);
+ inFile.OnProgress += delegate(long Position, long Length)
+ {
+ Console.CursorTop = top;
+ Console.CursorLeft = left;
+ Console.Write("{0} / {1} ({2}%) ", Position, Length, Position * 100 / Length);
+ };
+ result = nes.Execute("cat > '" + target + "'", inFile, Console.OpenStandardOutput(), Console.OpenStandardError(), 1000, true);
+ Console.Write("Done.");
break;
default:
ShowHelp();
@@ -142,9 +169,9 @@ namespace com.clusterrr.clovershell
{
Console.WriteLine("clovershell client v{0} (c) Alexey 'Cluster' Avdyukhin, 2017", Assembly.GetExecutingAssembly().GetName().Version);
Console.WriteLine(
- "Usage: {0} shell [port]\r\n"+
- "Usage: {0} exec <command> [stdin [stdout [stderr]]]\r\n"+
- "Usage: {0} pull <remote_file> [local_file]\r\n"+
+ "Usage: {0} shell [port]\r\n" +
+ "Usage: {0} exec <command> [stdin [stdout [stderr]]]\r\n" +
+ "Usage: {0} pull <remote_file> [local_file]\r\n" +
"Usage: {0} push <local_file> <remote_file>\r\n"
, Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase));
Console.WriteLine("Examples:");