Ejemplo n.º 1
0
        public static async Task CopyToWithStatusAsync(this Stream istream, long maxSize, Stream ostream, string status)
        {
            var buffer = new byte[1024 * 64];

            if (maxSize == 0)
            {
                maxSize = 1;
            }
            long totalRead = 0;
            long remain    = maxSize;

            while (true)
            {
                var toRead = Math.Min(buffer.Length, remain);
                var read   = await istream.ReadAsync(buffer, 0, (int)toRead);

                remain -= read;
                if (read == 0)
                {
                    break;
                }
                totalRead += read;
                await ostream.WriteAsync(buffer, 0, read);

                Status(status, Percent.FactoryPutInRange(totalRead, maxSize));
            }

            await ostream.FlushAsync();
        }
Ejemplo n.º 2
0
        private Percent OverAllStatus(Percent sub_status)
        {
            var per_step = 1.0f / _internalMaxStep;
            var macro    = _internalCurrentStep * per_step;

            return(Percent.FactoryPutInRange(macro + (per_step * sub_status.Value)));
        }
Ejemplo n.º 3
0
        private void UpdateStatus()
        {
            if (_inner.Length == 0)
            {
                return;
            }

            if (_queue != null)
            {
                _queue.Report(_message, Percent.FactoryPutInRange(_inner.Position, _inner.Length));
            }
            else
            {
                Utils.Status(_message, Percent.FactoryPutInRange(_inner.Position, _inner.Length));
            }
        }
Ejemplo n.º 4
0
        private static readonly string[] Suffix = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; // Longs run out around EB

        public static void CopyToWithStatus(this Stream istream, long maxSize, Stream ostream, string status)
        {
            var buffer = new byte[1024 * 64];

            if (maxSize == 0)
            {
                maxSize = 1;
            }
            long totalRead = 0;

            while (true)
            {
                var read = istream.Read(buffer, 0, buffer.Length);
                if (read == 0)
                {
                    break;
                }
                totalRead += read;
                ostream.Write(buffer, 0, read);
                Status(status, Percent.FactoryPutInRange(totalRead, maxSize));
            }
        }
Ejemplo n.º 5
0
        private void UpdateStatus()
        {
            if (DateTime.Now - _lastUpdate < TimeSpan.FromMilliseconds(500))
            {
                return;
            }

            _lastUpdate = DateTime.Now;

            if (_inner.Length == 0)
            {
                return;
            }

            if (_queue != null)
            {
                _queue.Report(_message, Percent.FactoryPutInRange(_inner.Position, _inner.Length));
            }
            else
            {
                Utils.Status(_message, Percent.FactoryPutInRange(_inner.Position, _inner.Length));
            }
        }
Ejemplo n.º 6
0
 public void MakeUpdate(int max, int curr)
 {
     MakeUpdate(Percent.FactoryPutInRange(curr, max == 0 ? 1 : max));
 }
Ejemplo n.º 7
0
        private static void ExtractAllWithInno(string source, string dest)
        {
            Utils.Log($"Extracting {Path.GetFileName(source)}");

            var info = new ProcessStartInfo
            {
                FileName               = @"Extractors\innounp.exe",
                Arguments              = $"-x -y -b -d\"{dest}\" \"{source}\"",
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                UseShellExecute        = false,
                CreateNoWindow         = true
            };

            var p = new Process {
                StartInfo = info
            };

            p.Start();
            ChildProcessTracker.AddProcess(p);

            try
            {
                p.PriorityClass = ProcessPriorityClass.BelowNormal;
            }
            catch (Exception e)
            {
                Utils.Error(e, "Error while setting process priority level for innounp.exe");
            }

            var name = Path.GetFileName(source);

            try
            {
                while (!p.HasExited)
                {
                    var line = p.StandardOutput.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    if (line.Length <= 4 || line[3] != '%')
                    {
                        continue;
                    }

                    int.TryParse(line.Substring(0, 3), out var percentInt);
                    Utils.Status($"Extracting {name} - {line.Trim()}", Percent.FactoryPutInRange(percentInt / 100d));
                }
            }
            catch (Exception e)
            {
                Utils.Error(e, "Error while reading StandardOutput for innounp.exe");
            }

            p.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Extracting {name}");
            if (p.ExitCode == 0)
            {
                return;
            }

            Utils.Log(p.StandardOutput.ReadToEnd());
            Utils.Log($"Extraction error extracting {source}");
        }
Ejemplo n.º 8
0
        private static void ExtractAllWith7Zip(string source, string dest)
        {
            Utils.Log(new GenericInfo($"Extracting {Path.GetFileName(source)}", $"The contents of {source} are being extracted to {dest} using 7zip.exe"));

            var info = new ProcessStartInfo
            {
                FileName               = @"Extractors\7z.exe",
                Arguments              = $"x -bsp1 -y -o\"{dest}\" \"{source}\" -mmt=off",
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                UseShellExecute        = false,
                CreateNoWindow         = true
            };

            var p = new Process {
                StartInfo = info
            };

            p.Start();
            ChildProcessTracker.AddProcess(p);
            try
            {
                p.PriorityClass = ProcessPriorityClass.BelowNormal;
            }
            catch (Exception)
            {
            }

            var name = Path.GetFileName(source);

            try
            {
                while (!p.HasExited)
                {
                    var line = p.StandardOutput.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    if (line.Length <= 4 || line[3] != '%')
                    {
                        continue;
                    }

                    int.TryParse(line.Substring(0, 3), out var percentInt);
                    Utils.Status($"Extracting {name} - {line.Trim()}", Percent.FactoryPutInRange(percentInt / 100d));
                }
            }
            catch (Exception)
            {
            }

            p.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Extracting {name}");

            if (p.ExitCode == 0)
            {
                Utils.Status($"Extracting {name} - 100%", Percent.One, alsoLog: true);
                return;
            }
            Utils.Error(new _7zipReturnError(p.ExitCode, source, dest, p.StandardOutput.ReadToEnd()));
        }
Ejemplo n.º 9
0
 public void SetProgress(long inSize, long outSize)
 {
     Utils.Status("Extracting OMOD", Percent.FactoryPutInRange(inSize, _total));
 }
Ejemplo n.º 10
0
 public void MakeUpdate(int max, int curr)
 {
     MakeUpdate(Percent.FactoryPutInRange(curr, max == 0 ? 1 : max));
     _stepName.OnNext($"({_internalCurrentStep}/{_internalMaxStep}) {_currentStepName}, {curr} of {max}");
 }