void timerElapsedUi(object sender, ElapsedEventArgs e) { InvokeOnMainThread(delegate { if (LinesAdded > 500) { txtConsoleOutput.Value = string.Empty; LinesAdded = 0; } if (extractTask != null) { while (extractTask.messages.Count > 0) { txtConsoleOutput.Value += extractTask.messages.Take(); txtConsoleOutput.ScrollRangeToVisible(new NSRange(txtConsoleOutput.Value.Length, 0)); LinesAdded += 1; } } if (extractTask != null) { if (extractTask.done) { extractTask = null; _timerUi.Stop(); if (doItNow) { txtConsoleOutput.Value += "\n\nThe application will close in 3 secs..."; txtConsoleOutput.ScrollRangeToVisible(new NSRange(txtConsoleOutput.Value.Length, 0)); NSRunLoop.Current.RunUntil(DateTime.Now.AddSeconds(3)); NSApplication.SharedApplication.Terminate(this); } } } }); }
private void doExtract() { string ext = Path.GetExtension(txtFilename.StringValue).ToUpper(); string extdir = Path.GetDirectoryName(txtFilename.StringValue) + "/" + Path.GetFileNameWithoutExtension(txtFilename.StringValue) + "/"; string arguments = string.Empty; string filename = string.Empty; string pathres = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/../Resources/Resources/"; switch (ext) { case ".ZIP": //filename = "/usr/bin/unzip"; var alert = new NSAlert { MessageText = "Extract only this file or all the ZIP files in the directory?", AlertStyle = NSAlertStyle.Critical }; alert.AddButton("This file only"); alert.AddButton("All the files"); string fileToExtract = "\\*.zip"; if (alert.RunModal() == (int)NSAlertButtonReturn.First) { fileToExtract = "\"" + txtFilename.StringValue + "\""; } filename = pathres + "unzip"; arguments = "-u -o " + fileToExtract + " -d \"" + extdir + "\""; break; case ".001": case ".RAR": filename = pathres + "unrar"; arguments = "x -y \"" + txtFilename.StringValue + "\" \"" + extdir + "\""; break; } string workingdir = Path.GetDirectoryName(txtFilename.StringValue); extractTask = new ExtractTask(filename, workingdir, arguments); _timerUi.Start(); extractTask.messages.Add("-------- STARTED\n"); extractTask.messages.Add("-------- Using: " + filename + "\n"); var bw = new BackgroundWorker(); bw.DoWork += (sender, args) => { Console.WriteLine("Worker has started"); extractTask.Task(); }; bw.RunWorkerCompleted += (sender, args) => { Console.WriteLine("Worker has completed"); extractTask.messages.Add("-------- DONE!\n"); extractTask.messages.Add("-------- Extracted to: " + extdir); extractTask.done = true; }; bw.RunWorkerAsync(); }