public string OpenRAR(string path, MainWindow window, NSTableView TableView) { if (path.Length > 0) { clsIOPrefs ioPrefs = new clsIOPrefs(); string txtRAR = ioPrefs.GetStringValue("CaminhoRAR"); if (txtRAR.Length > 0) { string[] launchArgs = { "vt", path }; NSPipe pipeOut = new NSPipe(); NSTask t = new NSTask(); t.LaunchPath = txtRAR; t.Arguments = launchArgs; t.StandardOutput = pipeOut; t.Launch(); ViewArquivosDataSource datasource = new ViewArquivosDataSource(); ProgressWindowController sheet = null; TableView.InvokeOnMainThread(delegate { sheet = new ProgressWindowController(); sheet.ShowSheet(window); }); bool Cancela = false; do { string txtRET = pipeOut.ReadHandle.ReadDataToEndOfFile().ToString(); int pos = txtRET.IndexOf("Name:"); if (pos > 0) { TableView.InvokeOnMainThread(delegate { if (!TableView.Enabled) { TableView.Enabled = true; TableView.Hidden = false; window.tb_outAdicionarActive = true; window.tb_outAtualizarActive = true; window.tb_outExtrairActive = true; window.tb_outRemoverActive = true; window.tb_outDesfazerActive = true; } }); txtRET = txtRET.Substring(pos); List <string> nomes = new List <string>(); do { pos = txtRET.IndexOf("Name:", pos + 1); if (pos < 0) { nomes.Add(txtRET.Trim()); break; } nomes.Add(txtRET.Substring(0, pos - 2).Trim()); txtRET = txtRET.Substring(pos); pos = 0; } while (true); if (nomes.Count > 0) { sheet.InvokeOnMainThread(delegate { sheet.ProgressBarMinValue = 0; sheet.ProgressBarMaxValue = nomes.Count; }); double conta = 0; foreach (string nome in nomes) { clsViewArquivos viewArquivos = new clsViewArquivos(); string[] colunas = nome.Split('\n'); string tipo = colunas [1].Substring(colunas [1].IndexOf(":") + 1).Trim(); viewArquivos.Nome = colunas [0].Substring(colunas [0].IndexOf(":") + 1).Trim(); viewArquivos.Tipo = colunas [1].Substring(colunas [1].IndexOf(":") + 1).Trim(); ++conta; sheet.InvokeOnMainThread(delegate { sheet.LabelArqValue = "Processando arquivo: " + viewArquivos.Nome; sheet.ProgressBarValue = conta; }); // NSApplication.SharedApplication.InvokeOnMainThread (() => { // sheet.LabelArqValue = "Processando arquivo: " + viewArquivos.Nome; // sheet.ProgressBarValue = conta; // }); if (tipo == "File") { viewArquivos.Tamanho = colunas [2].Substring(colunas [2].IndexOf(":") + 1).Trim(); viewArquivos.Compactado = colunas [3].Substring(colunas [3].IndexOf(":") + 1).Trim(); viewArquivos.Compressao = colunas [4].Substring(colunas [4].IndexOf(":") + 1).Trim(); viewArquivos.DataHora = colunas [5].Substring(colunas [5].IndexOf(":") + 1).Trim(); viewArquivos.Atributos = colunas [6].Substring(colunas [6].IndexOf(":") + 1).Trim(); viewArquivos.CRC32 = colunas [7].Substring(colunas [7].IndexOf(":") + 1).Trim(); viewArquivos.OS = colunas [8].Substring(colunas [8].IndexOf(":") + 1).Trim(); viewArquivos.Compressor = colunas [9].Substring(colunas [9].IndexOf(":") + 1).Trim(); } else { viewArquivos.Tamanho = ""; viewArquivos.Compactado = ""; viewArquivos.Compressao = ""; viewArquivos.DataHora = colunas [2].Substring(colunas [2].IndexOf(":") + 1).Trim(); viewArquivos.Atributos = colunas [3].Substring(colunas [3].IndexOf(":") + 1).Trim(); viewArquivos.CRC32 = colunas [4].Substring(colunas [4].IndexOf(":") + 1).Trim(); viewArquivos.OS = colunas [5].Substring(colunas [5].IndexOf(":") + 1).Trim(); viewArquivos.Compressor = colunas [6].Substring(colunas [6].IndexOf(":") + 1).Trim(); } viewArquivos.Tags = "0"; datasource.ViewArquivos.Add(viewArquivos); viewArquivos = null; sheet.InvokeOnMainThread(delegate { Cancela = sheet.Canceled; }); if (Cancela) { break; } } } } else { TableView.InvokeOnMainThread(delegate { TableView.Enabled = false; TableView.Hidden = true; sheet.CloseSheet(); NSAlert alert = new NSAlert() { AlertStyle = NSAlertStyle.Critical, InformativeText = "Não foi possível processar o arquivo:\r\n" + path, MessageText = "Abrir Arquivo", }; alert.RunSheetModal(window); }); } if (Cancela) { break; } } while(t.IsRunning); sheet.InvokeOnMainThread(delegate { sheet.CloseSheet(); sheet = null; }); pipeOut.Dispose(); pipeOut = null; TableView.InvokeOnMainThread(delegate { TableView.DataSource = datasource; TableView.Delegate = new ViewArquivosDelegate(datasource); }); t.Terminate(); t.Dispose(); t = null; } ioPrefs = null; } return(path); }
public override NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, nint row) { NSTableCellView view = (NSTableCellView)tableView.MakeView(tableColumn.Title, this); if (view == null) { view = new NSTableCellView(); if (tableColumn.Title == "Nome") { view.ImageView = new NSImageView(new CGRect(0, 0, 17, 17)); view.AddSubview(view.ImageView); view.TextField = new NSTextField(new CGRect(20, 0, 2, 17)); } else { view.TextField = new NSTextField(new CGRect(0, 0, 2, 17)); } view.TextField.AutoresizingMask = NSViewResizingMask.WidthSizable; view.AddSubview(view.TextField); view.Identifier = tableColumn.Title; view.TextField.BackgroundColor = NSColor.Clear; view.TextField.Bordered = false; view.TextField.Selectable = false; view.TextField.Editable = false; view.TextField.EditingEnded += (sender, e) => { switch (view.Identifier) { case "Nome": DataSource.ViewArquivos [(int)view.TextField.Tag].Nome = view.TextField.StringValue; break; case "Tipo": DataSource.ViewArquivos [(int)view.TextField.Tag].Tipo = view.TextField.StringValue; break; case "Tamanho": DataSource.ViewArquivos [(int)view.TextField.Tag].Tamanho = view.TextField.StringValue; break; case "Compactado": DataSource.ViewArquivos [(int)view.TextField.Tag].Compactado = view.TextField.StringValue; break; case "Compressão": DataSource.ViewArquivos [(int)view.TextField.Tag].Compressao = view.TextField.StringValue; break; case "Data/Hora": DataSource.ViewArquivos [(int)view.TextField.Tag].DataHora = view.TextField.StringValue; break; case "Atributos": DataSource.ViewArquivos [(int)view.TextField.Tag].Atributos = view.TextField.StringValue; break; case "CRC 32": DataSource.ViewArquivos [(int)view.TextField.Tag].CRC32 = view.TextField.StringValue; break; case "OS": DataSource.ViewArquivos [(int)view.TextField.Tag].OS = view.TextField.StringValue; break; case "Compressor": DataSource.ViewArquivos [(int)view.TextField.Tag].Compressor = view.TextField.StringValue; break; } }; } // Tag view view.TextField.Tag = row; switch (tableColumn.Title) { case "Nome": clsViewArquivos cvarq = new clsViewArquivos(); string tagArquivo = cvarq.GetTagsArquivo((ViewArquivosDataSource)tableView.DataSource, (int)row); cvarq.SetStateArquivo(tableView.GetRowView(row, false), view, Convert.ToInt32(tagArquivo)); cvarq = null; view.TextField.Alignment = NSTextAlignment.Left; view.TextField.StringValue = DataSource.ViewArquivos [(int)row].Nome; break; case "Tipo": view.TextField.Alignment = NSTextAlignment.Center; view.TextField.StringValue = DataSource.ViewArquivos [(int)row].Tipo; break; case "Tamanho": view.TextField.Alignment = NSTextAlignment.Right; view.TextField.StringValue = DataSource.ViewArquivos [(int)row].Tamanho; break; case "Compactado": view.TextField.Alignment = NSTextAlignment.Right; view.TextField.StringValue = DataSource.ViewArquivos [(int)row].Compactado; break; case "Compressão": view.TextField.Alignment = NSTextAlignment.Center; view.TextField.StringValue = DataSource.ViewArquivos [(int)row].Compressao; break; case "Data/Hora": view.TextField.Alignment = NSTextAlignment.Center; view.TextField.StringValue = DataSource.ViewArquivos [(int)row].DataHora; break; case "Atributos": view.TextField.Alignment = NSTextAlignment.Center; view.TextField.StringValue = DataSource.ViewArquivos [(int)row].Atributos; break; case "CRC 32": view.TextField.Alignment = NSTextAlignment.Center; view.TextField.StringValue = DataSource.ViewArquivos [(int)row].CRC32; break; case "OS": view.TextField.Alignment = NSTextAlignment.Center; view.TextField.StringValue = DataSource.ViewArquivos [(int)row].OS; break; case "Compressor": view.TextField.Alignment = NSTextAlignment.Left; view.TextField.StringValue = DataSource.ViewArquivos [(int)row].Compressor; break; } return(view); }
private void procBtn(int state = 1) { if (state == 4) { string[] filetypes = { "rar" }; NSOpenPanel dlg = NSOpenPanel.OpenPanel; dlg.Title = "Selecione"; dlg.CanChooseFiles = true; dlg.CanChooseDirectories = false; dlg.AllowedFileTypes = filetypes; dlg.AllowsMultipleSelection = false; dlg.ResolvesAliases = true; dlg.ReleasedWhenClosed = true; dlg.BeginSheet(this, (i) => { try { if (dlg.Url != null) { var urlString = dlg.Url.Path; if (!string.IsNullOrEmpty(urlString)) { //NSDate DateLoop = new NSDate (); //DateLoop = DateLoop.AddSeconds (0.1); //NSRunLoop.Current.RunUntil(DateLoop ); NSThread.Start(() => { clsRAR orar = new clsRAR(); rarFile = orar.OpenRAR(urlString, this, this.tbv_Arquivos); orar = null; }); } } } finally { dlg.Dispose(); dlg = null; } }); } else { NSIndexSet nSelRows = this.tbv_Arquivos.SelectedRows; if (nSelRows.Count > 0) { nuint[] nRows = nSelRows.ToArray(); if (nRows.Length > 0) { ViewArquivosDataSource datasource = (ViewArquivosDataSource)this.tbv_Arquivos.DataSource; clsViewArquivos cvarqs = new clsViewArquivos(); string aState = string.Empty; foreach (nint lRow in nRows) { switch (state) { case 1: aState = "1"; break; case 2: aState = cvarqs.GetTagsArquivo(datasource, (int)lRow, 1); break; case 3: NSOpenPanel dlg = NSOpenPanel.OpenPanel; dlg.Title = "Salvar em"; dlg.CanChooseFiles = false; dlg.CanChooseDirectories = true; dlg.AllowsMultipleSelection = false; dlg.ResolvesAliases = true; dlg.ReleasedWhenClosed = true; dlg.BeginSheet(this, (i) => { try { string urlString = dlg.Url.Path; if (!string.IsNullOrEmpty(urlString)) { nSelRows = this.tbv_Arquivos.SelectedRows; NSThread.Start(() => { clsRAR exRAR = new clsRAR(); exRAR.ExtractRAR(this, this.tbv_Arquivos, nSelRows, rarFile, urlString); exRAR = null; }); } } finally { dlg.Dispose(); dlg = null; } this.tbv_Arquivos.ReloadData(); }); break; case 5: break; } if (state != 3) { cvarqs.SetTagsArquivo(datasource, (int)lRow, aState); cvarqs = null; datasource = null; this.tbv_Arquivos.ReloadData(); } } } } else { string mText = string.Empty; string iText = string.Empty; switch (state) { case 1: mText = "Remover Arquivo(s)"; iText = "Selecione ao menos um aquivo para Remover !"; break; case 2: mText = "Desfazer Ação"; iText = "Selecione ao menos um arquivo para\r\n Desfazer a Ação !"; break; case 3: mText = "Extrair Arquivos"; iText = "Selecione ao menos um arquivo para Extrair !"; break; } NSAlert alert = new NSAlert() { AlertStyle = NSAlertStyle.Warning, InformativeText = iText, MessageText = mText, }; alert.RunSheetModal(this); } } }