public void SetTagsArquivo(ViewArquivosDataSource datasource, int row, string value) { string cell = datasource.ViewArquivos [row].Tags; if (cell.Length > 0) { string tag = string.Empty; if (cell.IndexOf("|") > 0) { string[] aTags = cell.Split('|'); //tag = aTags [aTags.Length - 1]; tag = aTags [0]; } else { tag = cell; } cell = tag; } datasource.ViewArquivos [row].Tags = value + "|" + cell; }
public string GetTagsArquivo(ViewArquivosDataSource datasource, int row, int pos = 0) { string tag = "0"; string cell = datasource.ViewArquivos [row].Tags; if (cell.Length > 0) { if (cell.IndexOf("|") > 0) { string[] aTags = cell.Split('|'); if (pos != 0) { pos = aTags.Length - 1; } tag = aTags [pos]; } else { tag = cell; } } return(tag); }
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 ViewArquivosDelegate(ViewArquivosDataSource datasource) { this.DataSource = datasource; }
public void ExtractRAR(MainWindow window, NSTableView TableView, NSIndexSet nSelRows, string rarFile, string extractPath) { clsIOPrefs ioPrefs = new clsIOPrefs(); string txtRAR = ioPrefs.GetStringValue("CaminhoRAR"); if (txtRAR.Length > 0) { if (nSelRows.Count > 0) { ProgressWindowController sheet = null; TableView.InvokeOnMainThread(delegate { sheet = new ProgressWindowController(); sheet.ShowSheet(window); }); sheet.InvokeOnMainThread(delegate { sheet.ProgressBarMinValue = 0; sheet.ProgressBarMaxValue = nSelRows.Count; }); double conta = 0; bool Cancela = false; nuint[] nRows = nSelRows.ToArray(); ViewArquivosDataSource datasource = null; TableView.InvokeOnMainThread(delegate { datasource = (ViewArquivosDataSource)TableView.DataSource; }); foreach (int lRow in nRows) { string NomeArq = datasource.ViewArquivos [lRow].Nome; ++conta; sheet.InvokeOnMainThread(delegate { sheet.LabelArqValue = "Extraindo arquivo: " + NomeArq; sheet.ProgressBarValue = conta; }); string[] launchArgs = { "x", rarFile, NomeArq, extractPath }; NSPipe pipeOut = new NSPipe(); NSTask t = new NSTask(); t.LaunchPath = txtRAR; t.Arguments = launchArgs; t.StandardOutput = pipeOut; t.Launch(); t.WaitUntilExit(); //string txtRET = pipeOut.ReadHandle.ReadDataToEndOfFile ().ToString (); sheet.InvokeOnMainThread(delegate { Cancela = sheet.Canceled; }); if (Cancela) { break; } } sheet.InvokeOnMainThread(delegate { sheet.CloseSheet(); sheet = null; }); if (!Cancela) { TableView.InvokeOnMainThread(delegate { NSAlert alert = new NSAlert() { AlertStyle = NSAlertStyle.Informational, InformativeText = "Arquivo(s) extraido(s) com sucesso !", MessageText = "Extrair arquivos", }; alert.RunSheetModal(window); }); } } } }
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); }
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); } } }