diff --git a/osrepodbmgr.Core/ChangeLog b/osrepodbmgr.Core/ChangeLog index a732043..212b72c 100644 --- a/osrepodbmgr.Core/ChangeLog +++ b/osrepodbmgr.Core/ChangeLog @@ -1,3 +1,9 @@ +2017-05-12 Natalia Portillo + + * DBOps.cs: + * Workers.cs: + Implemented extract of OS from repo, as files or zipped. + 2017-05-12 Natalia Portillo * DBOps.cs: diff --git a/osrepodbmgr.Core/DBOps.cs b/osrepodbmgr.Core/DBOps.cs index eda9159..551e2e1 100644 --- a/osrepodbmgr.Core/DBOps.cs +++ b/osrepodbmgr.Core/DBOps.cs @@ -556,6 +556,68 @@ namespace osrepodbmgr.Core return false; } + + public bool GetAllFiles(out List entries, long id) + { + entries = new List(); + + string sql = string.Format("SELECT * from os_{0}", id); + + IDbCommand dbcmd = dbCon.CreateCommand(); + IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); + dbcmd.CommandText = sql; + DataSet dataSet = new DataSet(); + dataAdapter.SelectCommand = dbcmd; + dataAdapter.Fill(dataSet); + DataTable dataTable = dataSet.Tables[0]; + + foreach(DataRow dRow in dataTable.Rows) + { + DBFile fEntry = new DBFile(); + fEntry.Id = ulong.Parse(dRow["id"].ToString()); + fEntry.Path = dRow["path"].ToString(); + fEntry.Sha256 = dRow["sha256"].ToString(); + fEntry.Length = long.Parse(dRow["length"].ToString()); + fEntry.CreationTimeUtc = DateTime.Parse(dRow["creation"].ToString()); + fEntry.LastAccessTimeUtc = DateTime.Parse(dRow["access"].ToString()); + fEntry.LastWriteTimeUtc = DateTime.Parse(dRow["modification"].ToString()); + fEntry.Attributes = (FileAttributes)int.Parse(dRow["attributes"].ToString()); + + entries.Add(fEntry); + } + + return true; + } + + public bool GetAllFolders(out List entries, long id) + { + entries = new List(); + + string sql = string.Format("SELECT * from os_{0}_folders", id); + + IDbCommand dbcmd = dbCon.CreateCommand(); + IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); + dbcmd.CommandText = sql; + DataSet dataSet = new DataSet(); + dataAdapter.SelectCommand = dbcmd; + dataAdapter.Fill(dataSet); + DataTable dataTable = dataSet.Tables[0]; + + foreach(DataRow dRow in dataTable.Rows) + { + DBFolder fEntry = new DBFolder(); + fEntry.Id = ulong.Parse(dRow["id"].ToString()); + fEntry.Path = dRow["path"].ToString(); + fEntry.CreationTimeUtc = DateTime.Parse(dRow["creation"].ToString()); + fEntry.LastAccessTimeUtc = DateTime.Parse(dRow["access"].ToString()); + fEntry.LastWriteTimeUtc = DateTime.Parse(dRow["modification"].ToString()); + fEntry.Attributes = (FileAttributes)int.Parse(dRow["attributes"].ToString()); + + entries.Add(fEntry); + } + + return true; + } } } diff --git a/osrepodbmgr.Core/Workers.cs b/osrepodbmgr.Core/Workers.cs index 97df167..c2baaac 100644 --- a/osrepodbmgr.Core/Workers.cs +++ b/osrepodbmgr.Core/Workers.cs @@ -910,7 +910,6 @@ namespace osrepodbmgr.Core break; } - byte[] buffer = new byte[bufferSize]; while((inFs.Position + bufferSize) <= inFs.Length) @@ -1389,5 +1388,377 @@ namespace osrepodbmgr.Core Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException)); } } + + public static void SaveAs() + { + try + { + if(string.IsNullOrWhiteSpace(Context.path)) + { + if(Failed != null) + Failed("Destination cannot be empty"); + return; + } + + if(File.Exists(Context.path)) + { + if(Failed != null) + Failed("Destination cannot be a file"); + return; + } + + if(Context.dbInfo.id == 0) + { + if(Failed != null) + Failed("Operating system must be set"); + return; + } + + List files; + List folders; + long counter; + + if(UpdateProgress != null) + UpdateProgress("", "Asking DB for files...", 1, 100); + + dbCore.DBOps.GetAllFiles(out files, Context.dbInfo.id); + + if(UpdateProgress != null) + UpdateProgress("", "Asking DB for folders...", 2, 100); + + dbCore.DBOps.GetAllFolders(out folders, Context.dbInfo.id); + + if(UpdateProgress != null) + UpdateProgress("", "Creating folders...", 3, 100); + + counter = 0; + foreach(DBFolder folder in folders) + { + if(UpdateProgress2 != null) + UpdateProgress2("", folder.Path, counter, folders.Count); + + DirectoryInfo di = Directory.CreateDirectory(Path.Combine(Context.path, folder.Path)); + di.Attributes = folder.Attributes; + di.CreationTimeUtc = folder.CreationTimeUtc; + di.LastAccessTimeUtc = folder.LastAccessTimeUtc; + di.LastWriteTimeUtc = folder.LastWriteTimeUtc; + + counter++; + } + + counter = 3; + foreach(DBFile file in files) + { + if(UpdateProgress != null) + UpdateProgress("", string.Format("Creating {0}...", file.Path), counter, 3 + files.Count); + + Stream zStream = null; + string repoPath; + AlgoEnum algorithm; + + if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(), + file.Sha256[1].ToString(), file.Sha256[2].ToString(), + file.Sha256[3].ToString(), file.Sha256[4].ToString(), + file.Sha256 + ".gz"))) + { + repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(), + file.Sha256[1].ToString(), file.Sha256[2].ToString(), + file.Sha256[3].ToString(), file.Sha256[4].ToString(), + file.Sha256 + ".gz"); + algorithm = AlgoEnum.GZip; + } + else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(), + file.Sha256[1].ToString(), file.Sha256[2].ToString(), + file.Sha256[3].ToString(), file.Sha256[4].ToString(), + file.Sha256 + ".bz2"))) + { + repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(), + file.Sha256[1].ToString(), file.Sha256[2].ToString(), + file.Sha256[3].ToString(), file.Sha256[4].ToString(), + file.Sha256 + ".bz2"); + algorithm = AlgoEnum.BZip2; + } + else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(), + file.Sha256[1].ToString(), file.Sha256[2].ToString(), + file.Sha256[3].ToString(), file.Sha256[4].ToString(), + file.Sha256 + ".lzma"))) + { + repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(), + file.Sha256[1].ToString(), file.Sha256[2].ToString(), + file.Sha256[3].ToString(), file.Sha256[4].ToString(), + file.Sha256 + ".lzma"); + algorithm = AlgoEnum.LZMA; + } + else + { + if(Failed != null) + Failed(string.Format("Cannot find file with hash {0} in the repository", file.Sha256)); + return; + } + + FileStream inFs = new FileStream(repoPath, FileMode.Open, FileAccess.Read); + FileStream outFs = new FileStream(Path.Combine(Context.path, file.Path), FileMode.CreateNew, FileAccess.Write); + + switch(algorithm) + { + case AlgoEnum.GZip: + zStream = new GZipStream(inFs, SharpCompress.Compressors.CompressionMode.Decompress); + break; + case AlgoEnum.BZip2: + zStream = new BZip2Stream(inFs, SharpCompress.Compressors.CompressionMode.Decompress); + break; + case AlgoEnum.LZMA: + byte[] properties = new byte[5]; + inFs.Read(properties, 0, 5); + inFs.Seek(8, SeekOrigin.Current); + zStream = new LzmaStream(properties, inFs); + break; + } + + byte[] buffer = new byte[bufferSize]; + + while((outFs.Position + bufferSize) <= file.Length) + { + if(UpdateProgress2 != null) + UpdateProgress2(string.Format("{0:P}", outFs.Position / (double)file.Length), + string.Format("{0} / {1} bytes", outFs.Position, file.Length), + outFs.Position, file.Length); + + zStream.Read(buffer, 0, buffer.Length); + outFs.Write(buffer, 0, buffer.Length); + } + + buffer = new byte[file.Length - outFs.Position]; + if(UpdateProgress2 != null) + UpdateProgress2(string.Format("{0:P}", outFs.Position / (double)file.Length), + string.Format("{0} / {1} bytes", outFs.Position, file.Length), + outFs.Position, file.Length); + + zStream.Read(buffer, 0, buffer.Length); + outFs.Write(buffer, 0, buffer.Length); + + if(UpdateProgress2 != null) + UpdateProgress2(string.Format("{0:P}", file.Length / (double)file.Length), + "Finishing...", inFs.Length, inFs.Length); + + zStream.Close(); + outFs.Close(); + + FileInfo fi = new FileInfo(Path.Combine(Context.path, file.Path)); + fi.Attributes = file.Attributes; + fi.CreationTimeUtc = file.CreationTimeUtc; + fi.LastAccessTimeUtc = file.LastAccessTimeUtc; + fi.LastWriteTimeUtc = file.LastWriteTimeUtc; + + counter++; + } + + if(Finished != null) + Finished(); + } + catch(Exception ex) + { + if(Debugger.IsAttached) + throw; + if(Failed != null) + Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException)); + } + } + + public static void CompressTo() + { + try + { + if(string.IsNullOrWhiteSpace(Context.path)) + { + if(Failed != null) + Failed("Destination cannot be empty"); + return; + } + + if(Directory.Exists(Context.path)) + { + if(Failed != null) + Failed("Destination cannot be a folder"); + return; + } + + if(Context.dbInfo.id == 0) + { + if(Failed != null) + Failed("Operating system must be set"); + return; + } + + ZipFile zf = new ZipFile(Context.path, Encoding.UTF8); + zf.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression; + zf.CompressionMethod = CompressionMethod.Deflate; + zf.SaveProgress += Zf_SaveProgress; + zf.EmitTimesInUnixFormatWhenSaving = true; + zf.EmitTimesInWindowsFormatWhenSaving = true; + zf.UseZip64WhenSaving = Zip64Option.AsNecessary; + zf.SortEntriesBeforeSaving = true; + List files; + List folders; + long counter; + + if(UpdateProgress != null) + UpdateProgress("", "Asking DB for files...", 1, 100); + + dbCore.DBOps.GetAllFiles(out files, Context.dbInfo.id); + + if(UpdateProgress != null) + UpdateProgress("", "Asking DB for folders...", 2, 100); + + dbCore.DBOps.GetAllFolders(out folders, Context.dbInfo.id); + + if(UpdateProgress != null) + UpdateProgress("", "Creating folders...", 3, 100); + + counter = 0; + foreach(DBFolder folder in folders) + { + if(UpdateProgress2 != null) + UpdateProgress2("", folder.Path, counter, folders.Count); + + ZipEntry zd = zf.AddDirectoryByName(folder.Path); + zd.Attributes = folder.Attributes; + zd.CreationTime = folder.CreationTimeUtc; + zd.AccessedTime = folder.LastAccessTimeUtc; + zd.LastModified = folder.LastWriteTimeUtc; + zd.ModifiedTime = folder.LastWriteTimeUtc; + + counter++; + } + + counter = 3; + Context.hashes = new Dictionary(); + foreach(DBFile file in files) + { + if(UpdateProgress != null) + UpdateProgress("", string.Format("Adding {0}...", file.Path), counter, 3 + files.Count); + + Context.hashes.Add(file.Path, file); + + ZipEntry zi = zf.AddEntry(file.Path, Zf_HandleOpen, Zf_HandleClose); + zi.Attributes = file.Attributes; + zi.CreationTime = file.CreationTimeUtc; + zi.AccessedTime = file.LastAccessTimeUtc; + zi.LastModified = file.LastWriteTimeUtc; + zi.ModifiedTime = file.LastWriteTimeUtc; + + counter++; + } + + zipCounter = 0; + zipCurrentEntryName = ""; + zf.Save(); + } + catch(Exception ex) + { + if(Debugger.IsAttached) + throw; + if(Failed != null) + Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException)); + } + } + + static Stream Zf_HandleOpen(string entryName) + { + DBFile file; + if(!Context.hashes.TryGetValue(entryName, out file)) + throw new ArgumentException("Cannot find requested zip entry in hashes dictionary"); + + // Special case for empty file, as it seems to crash when SharpCompress tries to unLZMA it. + if(file.Length == 0) + return new MemoryStream(); + + Stream zStream = null; + string repoPath; + AlgoEnum algorithm; + + if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(), + file.Sha256[1].ToString(), file.Sha256[2].ToString(), + file.Sha256[3].ToString(), file.Sha256[4].ToString(), + file.Sha256 + ".gz"))) + { + repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(), + file.Sha256[1].ToString(), file.Sha256[2].ToString(), + file.Sha256[3].ToString(), file.Sha256[4].ToString(), + file.Sha256 + ".gz"); + algorithm = AlgoEnum.GZip; + } + else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(), + file.Sha256[1].ToString(), file.Sha256[2].ToString(), + file.Sha256[3].ToString(), file.Sha256[4].ToString(), + file.Sha256 + ".bz2"))) + { + repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(), + file.Sha256[1].ToString(), file.Sha256[2].ToString(), + file.Sha256[3].ToString(), file.Sha256[4].ToString(), + file.Sha256 + ".bz2"); + algorithm = AlgoEnum.BZip2; + } + else if(File.Exists(Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(), + file.Sha256[1].ToString(), file.Sha256[2].ToString(), + file.Sha256[3].ToString(), file.Sha256[4].ToString(), + file.Sha256 + ".lzma"))) + { + repoPath = Path.Combine(Settings.Current.RepositoryPath, file.Sha256[0].ToString(), + file.Sha256[1].ToString(), file.Sha256[2].ToString(), + file.Sha256[3].ToString(), file.Sha256[4].ToString(), + file.Sha256 + ".lzma"); + algorithm = AlgoEnum.LZMA; + } + else + throw new ArgumentException(string.Format("Cannot find file with hash {0} in the repository", file.Sha256)); + + FileStream inFs = new FileStream(repoPath, FileMode.Open, FileAccess.Read); + + switch(algorithm) + { + case AlgoEnum.GZip: + zStream = new GZipStream(inFs, SharpCompress.Compressors.CompressionMode.Decompress); + break; + case AlgoEnum.BZip2: + zStream = new BZip2Stream(inFs, SharpCompress.Compressors.CompressionMode.Decompress); + break; + case AlgoEnum.LZMA: + byte[] properties = new byte[5]; + inFs.Read(properties, 0, 5); + inFs.Seek(8, SeekOrigin.Current); + zStream = new LzmaStream(properties, inFs, inFs.Length - 13, file.Length); + break; + } + + return zStream; + } + + static void Zf_HandleClose(string entryName, Stream stream) + { + stream.Close(); + } + + static void Zf_SaveProgress(object sender, SaveProgressEventArgs e) + { + if(e.CurrentEntry != null && e.CurrentEntry.FileName != zipCurrentEntryName) + { + zipCurrentEntryName = e.CurrentEntry.FileName; + zipCounter++; + } + + if(UpdateProgress != null && e.CurrentEntry != null && e.EntriesTotal > 0) + UpdateProgress("Compressing...", e.CurrentEntry.FileName, zipCounter, e.EntriesTotal); + if(UpdateProgress2 != null && e.TotalBytesToTransfer > 0) + UpdateProgress2(string.Format("{0:P}", e.BytesTransferred / (double)e.TotalBytesToTransfer), + string.Format("{0} / {1}", e.BytesTransferred, e.TotalBytesToTransfer), + e.BytesTransferred, e.TotalBytesToTransfer); + + if(e.EventType == ZipProgressEventType.Error_Saving && Failed != null) + Failed("An error occurred creating ZIP file."); + + if(e.EventType == ZipProgressEventType.Saving_Completed && Finished != null) + Finished(); + } } } diff --git a/osrepodbmgr/ChangeLog b/osrepodbmgr/ChangeLog index 4569fff..8ffadc0 100644 --- a/osrepodbmgr/ChangeLog +++ b/osrepodbmgr/ChangeLog @@ -1,3 +1,11 @@ +2017-05-12 Natalia Portillo + + * frmMain.cs: + * gtk-gui/gui.stetic: + * gtk-gui/generated.cs: + * gtk-gui/osrepodbmgr.frmMain.cs: + Implemented extract of OS from repo, as files or zipped. + 2017-05-11 Natalia Portillo * dlgAdd.cs: diff --git a/osrepodbmgr/frmMain.cs b/osrepodbmgr/frmMain.cs index 63e18ee..493ea5e 100644 --- a/osrepodbmgr/frmMain.cs +++ b/osrepodbmgr/frmMain.cs @@ -38,8 +38,8 @@ namespace osrepodbmgr ListStore osView; Thread thdPulseProgress; Thread thdPopulateOSes; - Thread thdExtractArchive; - Thread thdCopyFile; + Thread thdCompressTo; + Thread thdSaveAs; public frmMain() : base(WindowType.Toplevel) @@ -169,7 +169,7 @@ namespace osrepodbmgr treeOSes.Sensitive = true; btnAdd.Visible = true; btnRemove.Visible = true; - btnExtract.Visible = true; + btnCompress.Visible = true; btnSave.Visible = true; btnHelp.Visible = true; btnSettings.Visible = true; @@ -251,43 +251,31 @@ namespace osrepodbmgr } } - protected void OnBtnExtractClicked(object sender, EventArgs e) + protected void OnBtnSaveClicked(object sender, EventArgs e) { - throw new NotImplementedException(); - /* TreeIter osIter; if(treeOSes.Selection.GetSelected(out osIter)) { - Context.path = (string)osView.GetValue(osIter, 16); + Context.dbInfo.id = (long)osView.GetValue(osIter, 17); - if(!File.Exists(Context.path)) - { - MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "File is not in repository."); - dlgMsg.Run(); - dlgMsg.Destroy(); - return; - } - - FileChooserDialog dlgFolder = new FileChooserDialog("Extract to...", this, FileChooserAction.SelectFolder, + FileChooserDialog dlgFolder = new FileChooserDialog("Save to...", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Choose", ResponseType.Accept); dlgFolder.SelectMultiple = false; if(dlgFolder.Run() == (int)ResponseType.Accept) { - Context.userExtracting = true; - Context.tmpFolder = dlgFolder.Filename; - Context.copyArchive = true; + Context.path = dlgFolder.Filename; dlgFolder.Destroy(); lblProgress.Visible = true; - lblProgress2.Visible = true; prgProgress.Visible = true; + lblProgress2.Visible = true; prgProgress2.Visible = true; treeOSes.Sensitive = false; btnAdd.Visible = false; btnRemove.Visible = false; - btnExtract.Visible = false; + btnCompress.Visible = false; btnSave.Visible = false; btnHelp.Visible = false; btnSettings.Visible = false; @@ -298,19 +286,19 @@ namespace osrepodbmgr thdPulseProgress.Abort(); thdPulseProgress = null; } - Workers.Failed += ExtractArchiveFailed; - Workers.Finished += ExtractArchiveFinished; + Workers.Failed += SaveAsFailed; + Workers.Finished += SaveAsFinished; Workers.UpdateProgress += UpdateProgress; Workers.UpdateProgress2 += UpdateProgress2; - thdExtractArchive = new Thread(Workers.ExtractArchive); - thdExtractArchive.Start(); + thdSaveAs = new Thread(Workers.SaveAs); + thdSaveAs.Start(); } else dlgFolder.Destroy(); - }*/ + } } - public void ExtractArchiveFailed(string text) + public void SaveAsFailed(string text) { Application.Invoke(delegate { @@ -322,38 +310,35 @@ namespace osrepodbmgr thdPulseProgress.Abort(); thdPulseProgress = null; } - if(thdExtractArchive != null) + if(thdSaveAs != null) { - thdExtractArchive.Abort(); - thdExtractArchive = null; + thdSaveAs.Abort(); + thdSaveAs = null; } lblProgress.Visible = false; - lblProgress2.Visible = false; prgProgress.Visible = false; + lblProgress2.Visible = false; prgProgress2.Visible = false; treeOSes.Sensitive = true; btnAdd.Visible = true; btnRemove.Visible = true; - btnExtract.Visible = true; + btnCompress.Visible = true; btnSave.Visible = true; btnHelp.Visible = true; btnSettings.Visible = true; btnStop.Visible = false; - Workers.Failed -= ExtractArchiveFailed; - Workers.Finished -= ExtractArchiveFinished; + Workers.Failed -= SaveAsFailed; + Workers.Finished -= SaveAsFinished; Workers.UpdateProgress -= UpdateProgress; Workers.UpdateProgress2 -= UpdateProgress2; - Context.userExtracting = false; - Context.tmpFolder = null; - //Context.copyArchive = false; Context.path = null; }); } - public void ExtractArchiveFinished() + public void SaveAsFinished() { Application.Invoke(delegate { @@ -362,176 +347,34 @@ namespace osrepodbmgr thdPulseProgress.Abort(); thdPulseProgress = null; } - if(thdExtractArchive != null) + if(thdSaveAs != null) { - thdExtractArchive.Abort(); - thdExtractArchive = null; + thdSaveAs.Abort(); + thdSaveAs = null; } lblProgress.Visible = false; - lblProgress2.Visible = false; prgProgress.Visible = false; + lblProgress2.Visible = false; prgProgress2.Visible = false; treeOSes.Sensitive = true; btnAdd.Visible = true; btnRemove.Visible = true; - btnExtract.Visible = true; + btnCompress.Visible = true; btnSave.Visible = true; btnHelp.Visible = true; btnSettings.Visible = true; btnStop.Visible = false; - Workers.Failed -= ExtractArchiveFailed; - Workers.Finished -= ExtractArchiveFinished; - Workers.UpdateProgress -= UpdateProgress; - Workers.UpdateProgress2 -= UpdateProgress2; - - MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, - string.Format("Correctly extracted to {0}", Context.tmpFolder)); - dlgMsg.Run(); - dlgMsg.Destroy(); - - Context.userExtracting = false; - Context.tmpFolder = null; - //Context.copyArchive = false; - Context.path = null; - }); - } - - protected void OnBtnSaveClicked(object sender, EventArgs e) - { - throw new NotImplementedException(); - /* - TreeIter osIter; - if(treeOSes.Selection.GetSelected(out osIter)) - { - Context.path = (string)osView.GetValue(osIter, 16); - - if(!File.Exists(Context.path)) - { - MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "File is not in repository."); - dlgMsg.Run(); - dlgMsg.Destroy(); - return; - } - - FileChooserDialog dlgFolder = new FileChooserDialog("Copy to...", this, FileChooserAction.Save, - "Cancel", ResponseType.Cancel, "Choose", ResponseType.Accept); - dlgFolder.SelectMultiple = false; - - if(dlgFolder.Run() == (int)ResponseType.Accept) - { - Context.userExtracting = true; - Context.tmpFolder = dlgFolder.Filename; - Context.copyArchive = true; - - dlgFolder.Destroy(); - - lblProgress.Visible = true; - prgProgress.Visible = true; - treeOSes.Sensitive = false; - btnAdd.Visible = false; - btnRemove.Visible = false; - btnExtract.Visible = false; - btnSave.Visible = false; - btnHelp.Visible = false; - btnSettings.Visible = false; - btnStop.Visible = true; - - if(thdPulseProgress != null) - { - thdPulseProgress.Abort(); - thdPulseProgress = null; - } - Workers.Failed += CopyFileFailed; - Workers.Finished += CopyFileFinished; - Workers.UpdateProgress += UpdateProgress; - thdCopyFile = new Thread(Workers.CopyFile); - thdCopyFile.Start(); - } - else - dlgFolder.Destroy(); - }*/ - } - - public void CopyFileFailed(string text) - { - Application.Invoke(delegate - { - MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, text); - dlgMsg.Run(); - dlgMsg.Destroy(); - if(thdPulseProgress != null) - { - thdPulseProgress.Abort(); - thdPulseProgress = null; - } - if(thdCopyFile != null) - { - thdCopyFile.Abort(); - thdCopyFile = null; - } - - lblProgress.Visible = false; - prgProgress.Visible = false; - treeOSes.Sensitive = true; - btnAdd.Visible = true; - btnRemove.Visible = true; - btnExtract.Visible = true; - btnSave.Visible = true; - btnHelp.Visible = true; - btnSettings.Visible = true; - btnStop.Visible = false; - - Workers.Failed -= CopyFileFailed; - Workers.Finished -= CopyFileFinished; - Workers.UpdateProgress -= UpdateProgress; - - Context.userExtracting = false; - Context.tmpFolder = null; - //Context.copyArchive = false; - Context.path = null; - }); - } - - public void CopyFileFinished() - { - Application.Invoke(delegate - { - if(thdPulseProgress != null) - { - thdPulseProgress.Abort(); - thdPulseProgress = null; - } - if(thdCopyFile != null) - { - thdCopyFile.Abort(); - thdCopyFile = null; - } - - lblProgress.Visible = false; - prgProgress.Visible = false; - treeOSes.Sensitive = true; - btnAdd.Visible = true; - btnRemove.Visible = true; - btnExtract.Visible = true; - btnSave.Visible = true; - btnHelp.Visible = true; - btnSettings.Visible = true; - btnStop.Visible = false; - - Workers.Failed -= CopyFileFailed; - Workers.Finished -= CopyFileFinished; + Workers.Failed -= SaveAsFailed; + Workers.Finished -= SaveAsFinished; Workers.UpdateProgress -= UpdateProgress; MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, - string.Format("Correctly saved as {0}", Context.tmpFolder)); + string.Format("Correctly saved to {0}", Context.path)); dlgMsg.Run(); dlgMsg.Destroy(); - Context.userExtracting = false; - Context.tmpFolder = null; - //Context.copyArchive = false; Context.path = null; }); } @@ -568,15 +411,15 @@ namespace osrepodbmgr thdPopulateOSes.Abort(); thdPopulateOSes = null; } - if(thdExtractArchive != null) + if(thdCompressTo != null) { thdPopulateOSes.Abort(); thdPopulateOSes = null; } - if(thdCopyFile != null) + if(thdSaveAs != null) { - thdCopyFile.Abort(); - thdCopyFile = null; + thdSaveAs.Abort(); + thdSaveAs = null; } } @@ -584,5 +427,134 @@ namespace osrepodbmgr { OnBtnStopClicked(sender, e); } + + protected void OnBtnCompressClicked(object sender, EventArgs e) + { + TreeIter osIter; + if(treeOSes.Selection.GetSelected(out osIter)) + { + Context.dbInfo.id = (long)osView.GetValue(osIter, 17); + + FileChooserDialog dlgFolder = new FileChooserDialog("Compress to...", this, FileChooserAction.Save, + "Cancel", ResponseType.Cancel, "Choose", ResponseType.Accept); + dlgFolder.SelectMultiple = false; + + if(dlgFolder.Run() == (int)ResponseType.Accept) + { + Context.path = dlgFolder.Filename; + + dlgFolder.Destroy(); + + lblProgress.Visible = true; + prgProgress.Visible = true; + lblProgress2.Visible = true; + prgProgress2.Visible = true; + treeOSes.Sensitive = false; + btnAdd.Visible = false; + btnRemove.Visible = false; + btnCompress.Visible = false; + btnSave.Visible = false; + btnHelp.Visible = false; + btnSettings.Visible = false; + btnStop.Visible = true; + + if(thdPulseProgress != null) + { + thdPulseProgress.Abort(); + thdPulseProgress = null; + } + Workers.Failed += CompressToFailed; + Workers.Finished += CompressToFinished; + Workers.UpdateProgress += UpdateProgress; + Workers.UpdateProgress2 += UpdateProgress2; + thdCompressTo = new Thread(Workers.CompressTo); + thdCompressTo.Start(); + } + else + dlgFolder.Destroy(); + } + } + + public void CompressToFailed(string text) + { + Application.Invoke(delegate + { + MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, text); + dlgMsg.Run(); + dlgMsg.Destroy(); + if(thdPulseProgress != null) + { + thdPulseProgress.Abort(); + thdPulseProgress = null; + } + if(thdCompressTo != null) + { + thdCompressTo.Abort(); + thdCompressTo = null; + } + + lblProgress.Visible = false; + lblProgress2.Visible = false; + prgProgress.Visible = false; + prgProgress2.Visible = false; + treeOSes.Sensitive = true; + btnAdd.Visible = true; + btnRemove.Visible = true; + btnCompress.Visible = true; + btnSave.Visible = true; + btnHelp.Visible = true; + btnSettings.Visible = true; + btnStop.Visible = false; + + Workers.Failed -= CompressToFailed; + Workers.Finished -= CompressToFinished; + Workers.UpdateProgress -= UpdateProgress; + Workers.UpdateProgress2 -= UpdateProgress2; + + Context.path = null; + }); + } + + public void CompressToFinished() + { + Application.Invoke(delegate + { + if(thdPulseProgress != null) + { + thdPulseProgress.Abort(); + thdPulseProgress = null; + } + if(thdCompressTo != null) + { + thdCompressTo.Abort(); + thdCompressTo = null; + } + + lblProgress.Visible = false; + lblProgress2.Visible = false; + prgProgress.Visible = false; + prgProgress2.Visible = false; + treeOSes.Sensitive = true; + btnAdd.Visible = true; + btnRemove.Visible = true; + btnCompress.Visible = true; + btnSave.Visible = true; + btnHelp.Visible = true; + btnSettings.Visible = true; + btnStop.Visible = false; + + Workers.Failed -= CompressToFailed; + Workers.Finished -= CompressToFinished; + Workers.UpdateProgress -= UpdateProgress; + Workers.UpdateProgress2 -= UpdateProgress2; + + MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, + string.Format("Correctly compressed as {0}", Context.path)); + dlgMsg.Run(); + dlgMsg.Destroy(); + + Context.path = null; + }); + } } } \ No newline at end of file diff --git a/osrepodbmgr/gtk-gui/generated.cs b/osrepodbmgr/gtk-gui/generated.cs index 50283a9..f916e7a 100644 --- a/osrepodbmgr/gtk-gui/generated.cs +++ b/osrepodbmgr/gtk-gui/generated.cs @@ -8,7 +8,7 @@ namespace Stetic internal static void Initialize(Gtk.Widget iconRenderer) { - if ((Stetic.Gui.initialized == false)) + if((Stetic.Gui.initialized == false)) { Stetic.Gui.initialized = true; } @@ -20,7 +20,7 @@ namespace Stetic public static Gdk.Pixbuf LoadIcon(Gtk.Widget widget, string name, Gtk.IconSize size) { Gdk.Pixbuf res = widget.RenderIcon(name, size, null); - if ((res != null)) + if((res != null)) { return res; } @@ -32,9 +32,9 @@ namespace Stetic { return Gtk.IconTheme.Default.LoadIcon(name, sz, 0); } - catch (System.Exception) + catch(System.Exception) { - if ((name != "gtk-missing-image")) + if((name != "gtk-missing-image")) { return Stetic.IconLoader.LoadIcon(widget, "gtk-missing-image", size); } diff --git a/osrepodbmgr/gtk-gui/gui.stetic b/osrepodbmgr/gtk-gui/gui.stetic index 7f32c1a..841a401 100644 --- a/osrepodbmgr/gtk-gui/gui.stetic +++ b/osrepodbmgr/gtk-gui/gui.stetic @@ -12563,11 +12563,11 @@ QNX/QNX/20090229/source.zip False True - True - StockItem - gtk-save-as + TextAndIcon + stock:gtk-directory Menu + Save _As + True - gtk-save-as End @@ -12578,15 +12578,14 @@ QNX/QNX/20090229/source.zip - + - False True TextAndIcon - stock:gtk-directory Menu - Extract to + stock:gtk-save Menu + Compress to True - + End diff --git a/osrepodbmgr/gtk-gui/osrepodbmgr.frmMain.cs b/osrepodbmgr/gtk-gui/osrepodbmgr.frmMain.cs index 4077b58..e449059 100644 --- a/osrepodbmgr/gtk-gui/osrepodbmgr.frmMain.cs +++ b/osrepodbmgr/gtk-gui/osrepodbmgr.frmMain.cs @@ -42,7 +42,7 @@ namespace osrepodbmgr private global::Gtk.Button btnSave; - private global::Gtk.Button btnExtract; + private global::Gtk.Button btnCompress; private global::Gtk.Button btnStop; @@ -206,30 +206,32 @@ namespace osrepodbmgr this.btnSave = new global::Gtk.Button(); this.btnSave.CanFocus = true; this.btnSave.Name = "btnSave"; - this.btnSave.UseStock = true; this.btnSave.UseUnderline = true; - this.btnSave.Label = "gtk-save-as"; + this.btnSave.Label = global::Mono.Unix.Catalog.GetString("Save _As"); + global::Gtk.Image w17 = new global::Gtk.Image(); + w17.Pixbuf = global::Stetic.IconLoader.LoadIcon(this, "gtk-directory", global::Gtk.IconSize.Menu); + this.btnSave.Image = w17; this.hbox1.Add(this.btnSave); - global::Gtk.Box.BoxChild w17 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.btnSave])); - w17.PackType = ((global::Gtk.PackType)(1)); - w17.Position = 5; - w17.Expand = false; - w17.Fill = false; + global::Gtk.Box.BoxChild w18 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.btnSave])); + w18.PackType = ((global::Gtk.PackType)(1)); + w18.Position = 5; + w18.Expand = false; + w18.Fill = false; // Container child hbox1.Gtk.Box+BoxChild - this.btnExtract = new global::Gtk.Button(); - this.btnExtract.CanFocus = true; - this.btnExtract.Name = "btnExtract"; - this.btnExtract.UseUnderline = true; - this.btnExtract.Label = global::Mono.Unix.Catalog.GetString("Extract to"); - global::Gtk.Image w18 = new global::Gtk.Image(); - w18.Pixbuf = global::Stetic.IconLoader.LoadIcon(this, "gtk-directory", global::Gtk.IconSize.Menu); - this.btnExtract.Image = w18; - this.hbox1.Add(this.btnExtract); - global::Gtk.Box.BoxChild w19 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.btnExtract])); - w19.PackType = ((global::Gtk.PackType)(1)); - w19.Position = 6; - w19.Expand = false; - w19.Fill = false; + this.btnCompress = new global::Gtk.Button(); + this.btnCompress.CanFocus = true; + this.btnCompress.Name = "btnCompress"; + this.btnCompress.UseUnderline = true; + this.btnCompress.Label = global::Mono.Unix.Catalog.GetString("Compress to"); + global::Gtk.Image w19 = new global::Gtk.Image(); + w19.Pixbuf = global::Stetic.IconLoader.LoadIcon(this, "gtk-save", global::Gtk.IconSize.Menu); + this.btnCompress.Image = w19; + this.hbox1.Add(this.btnCompress); + global::Gtk.Box.BoxChild w20 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.btnCompress])); + w20.PackType = ((global::Gtk.PackType)(1)); + w20.Position = 6; + w20.Expand = false; + w20.Fill = false; // Container child hbox1.Gtk.Box+BoxChild this.btnStop = new global::Gtk.Button(); this.btnStop.CanFocus = true; @@ -238,16 +240,16 @@ namespace osrepodbmgr this.btnStop.UseUnderline = true; this.btnStop.Label = "gtk-stop"; this.hbox1.Add(this.btnStop); - global::Gtk.Box.BoxChild w20 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.btnStop])); - w20.PackType = ((global::Gtk.PackType)(1)); - w20.Position = 7; - w20.Expand = false; - w20.Fill = false; - this.vbox2.Add(this.hbox1); - global::Gtk.Box.BoxChild w21 = ((global::Gtk.Box.BoxChild)(this.vbox2[this.hbox1])); - w21.Position = 3; + global::Gtk.Box.BoxChild w21 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.btnStop])); + w21.PackType = ((global::Gtk.PackType)(1)); + w21.Position = 7; w21.Expand = false; w21.Fill = false; + this.vbox2.Add(this.hbox1); + global::Gtk.Box.BoxChild w22 = ((global::Gtk.Box.BoxChild)(this.vbox2[this.hbox1])); + w22.Position = 3; + w22.Expand = false; + w22.Fill = false; this.Add(this.vbox2); if((this.Child != null)) { @@ -262,14 +264,13 @@ namespace osrepodbmgr this.btnSettings.Hide(); this.btnHelp.Hide(); this.btnSave.Hide(); - this.btnExtract.Hide(); this.btnStop.Hide(); this.Show(); this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent); this.btnAdd.Clicked += new global::System.EventHandler(this.OnBtnAddClicked); this.btnRemove.Clicked += new global::System.EventHandler(this.OnBtnRemoveClicked); this.btnStop.Clicked += new global::System.EventHandler(this.OnBtnStopClicked); - this.btnExtract.Clicked += new global::System.EventHandler(this.OnBtnExtractClicked); + this.btnCompress.Clicked += new global::System.EventHandler(this.OnBtnCompressClicked); this.btnSave.Clicked += new global::System.EventHandler(this.OnBtnSaveClicked); this.btnHelp.Clicked += new global::System.EventHandler(this.OnBtnHelpClicked); this.btnSettings.Clicked += new global::System.EventHandler(this.OnBtnSettingsClicked);