mirror of
https://github.com/claunia/apprepodbmgr.git
synced 2025-12-16 19:24:42 +00:00
Added support for archives.
This commit is contained in:
@@ -1,3 +1,14 @@
|
||||
2017-04-23 Natalia Portillo <claunia@claunia.com>
|
||||
|
||||
* Core.cs:
|
||||
* Program.cs:
|
||||
* MainWindow.cs:
|
||||
* packages.config:
|
||||
* osrepodbmgr.csproj:
|
||||
* gtk-gui/gui.stetic:
|
||||
* gtk-gui/MainWindow.cs:
|
||||
Added support for archives.
|
||||
|
||||
2017-04-20 Natalia Portillo <claunia@claunia.com>
|
||||
|
||||
* Core.cs:
|
||||
|
||||
@@ -31,6 +31,7 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Ionic.Zip;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace osrepodbmgr
|
||||
{
|
||||
@@ -60,13 +61,20 @@ namespace osrepodbmgr
|
||||
|
||||
public static void FindFiles()
|
||||
{
|
||||
if(string.IsNullOrEmpty(MainClass.path))
|
||||
string filesPath;
|
||||
|
||||
if(!string.IsNullOrEmpty(MainClass.tmpFolder) && Directory.Exists(MainClass.tmpFolder))
|
||||
filesPath = MainClass.tmpFolder;
|
||||
else
|
||||
filesPath = MainClass.path;
|
||||
|
||||
if(string.IsNullOrEmpty(filesPath))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Path is null or empty");
|
||||
}
|
||||
|
||||
if(!Directory.Exists(MainClass.path))
|
||||
if(!Directory.Exists(filesPath))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Directory not found");
|
||||
@@ -74,7 +82,7 @@ namespace osrepodbmgr
|
||||
|
||||
try
|
||||
{
|
||||
MainClass.files = new List<string>(Directory.EnumerateFiles(MainClass.path, "*", SearchOption.AllDirectories));
|
||||
MainClass.files = new List<string>(Directory.EnumerateFiles(filesPath, "*", SearchOption.AllDirectories));
|
||||
MainClass.files.Sort();
|
||||
if(Finished != null)
|
||||
Finished();
|
||||
@@ -96,7 +104,14 @@ namespace osrepodbmgr
|
||||
long counter = 1;
|
||||
foreach(string file in MainClass.files)
|
||||
{
|
||||
string relpath = file.Substring(MainClass.path.Length + 1);
|
||||
string filesPath;
|
||||
|
||||
if(!string.IsNullOrEmpty(MainClass.tmpFolder) && Directory.Exists(MainClass.tmpFolder))
|
||||
filesPath = MainClass.tmpFolder;
|
||||
else
|
||||
filesPath = MainClass.path;
|
||||
|
||||
string relpath = file.Substring(filesPath.Length + 1);
|
||||
if(UpdateProgress != null)
|
||||
UpdateProgress(string.Format("Hashing file {0} of {1}", counter, MainClass.files.Count), null, counter, MainClass.files.Count);
|
||||
FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
|
||||
@@ -405,6 +420,13 @@ namespace osrepodbmgr
|
||||
zf.CompressionMethod = CompressionMethod.Deflate;
|
||||
zf.UseZip64WhenSaving = Zip64Option.AsNecessary;
|
||||
|
||||
string filesPath;
|
||||
|
||||
if(!string.IsNullOrEmpty(MainClass.tmpFolder) && Directory.Exists(MainClass.tmpFolder))
|
||||
filesPath = MainClass.tmpFolder;
|
||||
else
|
||||
filesPath = MainClass.path;
|
||||
|
||||
int counter = 0;
|
||||
foreach(string file in MainClass.files)
|
||||
{
|
||||
@@ -420,7 +442,7 @@ namespace osrepodbmgr
|
||||
ze.CreationTime = fi.CreationTimeUtc;
|
||||
ze.EmitTimesInUnixFormatWhenSaving = true;
|
||||
ze.LastModified = fi.LastWriteTimeUtc;
|
||||
ze.FileName = file.Substring(MainClass.path.Length + 1);
|
||||
ze.FileName = file.Substring(filesPath.Length + 1);
|
||||
|
||||
//fs.Close();
|
||||
|
||||
@@ -565,5 +587,311 @@ namespace osrepodbmgr
|
||||
if(FinishedWithText != null)
|
||||
FinishedWithText(versionProcess.StandardOutput.ReadToEnd().TrimEnd(new char[] { '\n' }));
|
||||
}
|
||||
|
||||
public static void OpenArchive()
|
||||
{
|
||||
if(!MainClass.unarUsable)
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("The UnArchiver is not correctly installed");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!File.Exists(MainClass.path))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Specified file cannot be found");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string unarFolder = Path.GetDirectoryName(Settings.Current.UnArchiverPath);
|
||||
string extension = Path.GetExtension(Settings.Current.UnArchiverPath);
|
||||
string unarfilename = Path.GetFileNameWithoutExtension(Settings.Current.UnArchiverPath);
|
||||
string lsarfilename = unarfilename.Replace("unar", "lsar");
|
||||
string lsarPath = Path.Combine(unarFolder, lsarfilename + extension);
|
||||
|
||||
Process lsarProcess = new Process();
|
||||
lsarProcess.StartInfo.FileName = lsarPath;
|
||||
lsarProcess.StartInfo.CreateNoWindow = true;
|
||||
lsarProcess.StartInfo.RedirectStandardOutput = true;
|
||||
lsarProcess.StartInfo.UseShellExecute = false;
|
||||
lsarProcess.StartInfo.Arguments = string.Format("-j \"\"\"{0}\"\"\"", MainClass.path);
|
||||
lsarProcess.Start();
|
||||
string lsarOutput = lsarProcess.StandardOutput.ReadToEnd();
|
||||
lsarProcess.WaitForExit();
|
||||
|
||||
long counter = 0;
|
||||
string format = null;
|
||||
JsonTextReader jsReader = new JsonTextReader(new StringReader(lsarOutput));
|
||||
while(jsReader.Read())
|
||||
{
|
||||
if(jsReader.TokenType == JsonToken.PropertyName && jsReader.Value != null && jsReader.Value.ToString() == "XADFileName")
|
||||
counter++;
|
||||
else if(jsReader.TokenType == JsonToken.PropertyName && jsReader.Value != null && jsReader.Value.ToString() == "lsarFormatName")
|
||||
{
|
||||
jsReader.Read();
|
||||
if(jsReader.TokenType == JsonToken.String && jsReader.Value != null)
|
||||
format = jsReader.Value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Check if ZIP file contains Mac OS X metadata
|
||||
MainClass.copyArchive = false;
|
||||
MainClass.archiveFormat = format;
|
||||
MainClass.noFilesInArchive = counter;
|
||||
|
||||
if(string.IsNullOrEmpty(format))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("File not recognized as an archive");
|
||||
return;
|
||||
}
|
||||
|
||||
if(counter == 0)
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Archive contains no files");
|
||||
return;
|
||||
}
|
||||
|
||||
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 ExtractArchive()
|
||||
{
|
||||
if(!MainClass.unarUsable)
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("The UnArchiver is not correctly installed");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!File.Exists(MainClass.path))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Specified file cannot be found");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!Directory.Exists(Settings.Current.TemporaryFolder))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Temporary folder cannot be found");
|
||||
return;
|
||||
}
|
||||
|
||||
string tmpFolder = Path.Combine(Settings.Current.TemporaryFolder, Path.GetRandomFileName());
|
||||
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(tmpFolder);
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
if(Debugger.IsAttached)
|
||||
throw;
|
||||
if(Failed != null)
|
||||
Failed("Cannot create temporary folder");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
MainClass.unarProcess = new Process();
|
||||
MainClass.unarProcess.StartInfo.FileName = Settings.Current.UnArchiverPath;
|
||||
MainClass.unarProcess.StartInfo.CreateNoWindow = true;
|
||||
MainClass.unarProcess.StartInfo.RedirectStandardOutput = true;
|
||||
MainClass.unarProcess.StartInfo.UseShellExecute = false;
|
||||
MainClass.unarProcess.StartInfo.Arguments = string.Format("-o \"\"\"{0}\"\"\" -r -D -k hidden \"\"\"{1}\"\"\"", tmpFolder, MainClass.path);
|
||||
long counter = 0;
|
||||
MainClass.unarProcess.OutputDataReceived += (sender, e) =>
|
||||
{
|
||||
counter++;
|
||||
if(UpdateProgress2 != null)
|
||||
UpdateProgress2("", e.Data, counter, MainClass.noFilesInArchive);
|
||||
};
|
||||
MainClass.unarProcess.Start();
|
||||
MainClass.unarProcess.BeginOutputReadLine();
|
||||
MainClass.unarProcess.WaitForExit();
|
||||
MainClass.unarProcess.Close();
|
||||
|
||||
if(Finished != null)
|
||||
Finished();
|
||||
|
||||
MainClass.tmpFolder = tmpFolder;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
if(Debugger.IsAttached)
|
||||
throw;
|
||||
if(Failed != null)
|
||||
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyArchive()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(MainClass.dbInfo.developer))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Developer cannot be empty");
|
||||
return;
|
||||
}
|
||||
|
||||
if(string.IsNullOrWhiteSpace(MainClass.dbInfo.product))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Product cannot be empty");
|
||||
return;
|
||||
}
|
||||
|
||||
if(string.IsNullOrWhiteSpace(MainClass.dbInfo.version))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("Version cannot be empty");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if repository folder exists
|
||||
string destinationFolder = Settings.Current.RepositoryPath;
|
||||
if(!Directory.Exists(destinationFolder))
|
||||
Directory.CreateDirectory(destinationFolder);
|
||||
// Check if developer folder exists
|
||||
destinationFolder = Path.Combine(destinationFolder, MainClass.dbInfo.developer);
|
||||
if(!Directory.Exists(destinationFolder))
|
||||
Directory.CreateDirectory(destinationFolder);
|
||||
// Check if product folder exists
|
||||
destinationFolder = Path.Combine(destinationFolder, MainClass.dbInfo.product);
|
||||
if(!Directory.Exists(destinationFolder))
|
||||
Directory.CreateDirectory(destinationFolder);
|
||||
// Check if version folder exists
|
||||
destinationFolder = Path.Combine(destinationFolder, MainClass.dbInfo.version);
|
||||
if(!Directory.Exists(destinationFolder))
|
||||
Directory.CreateDirectory(destinationFolder);
|
||||
if(!string.IsNullOrWhiteSpace(MainClass.dbInfo.languages))
|
||||
{
|
||||
// Check if languages folder exists
|
||||
destinationFolder = Path.Combine(destinationFolder, MainClass.dbInfo.languages);
|
||||
if(!Directory.Exists(destinationFolder))
|
||||
Directory.CreateDirectory(destinationFolder);
|
||||
}
|
||||
if(!string.IsNullOrWhiteSpace(MainClass.dbInfo.architecture))
|
||||
{
|
||||
// Check if architecture folder exists
|
||||
destinationFolder = Path.Combine(destinationFolder, MainClass.dbInfo.architecture);
|
||||
if(!Directory.Exists(destinationFolder))
|
||||
Directory.CreateDirectory(destinationFolder);
|
||||
}
|
||||
if(MainClass.dbInfo.oem)
|
||||
{
|
||||
// Check if oem folder exists
|
||||
destinationFolder = Path.Combine(destinationFolder, "oem");
|
||||
if(!Directory.Exists(destinationFolder))
|
||||
Directory.CreateDirectory(destinationFolder);
|
||||
}
|
||||
if(!string.IsNullOrWhiteSpace(MainClass.dbInfo.machine))
|
||||
{
|
||||
// Check if architecture folder exists
|
||||
destinationFolder = Path.Combine(destinationFolder, "for " + MainClass.dbInfo.machine);
|
||||
if(!Directory.Exists(destinationFolder))
|
||||
Directory.CreateDirectory(destinationFolder);
|
||||
}
|
||||
|
||||
string destinationFile = "";
|
||||
if(!string.IsNullOrWhiteSpace(MainClass.dbInfo.format))
|
||||
destinationFile += "[" + MainClass.dbInfo.format + "]";
|
||||
if(MainClass.dbInfo.files)
|
||||
{
|
||||
if(destinationFile != "")
|
||||
destinationFile += "_";
|
||||
destinationFile += "files";
|
||||
}
|
||||
if(MainClass.dbInfo.netinstall)
|
||||
{
|
||||
if(destinationFile != "")
|
||||
destinationFile += "_";
|
||||
destinationFile += "netinstall";
|
||||
}
|
||||
if(MainClass.dbInfo.source)
|
||||
{
|
||||
if(destinationFile != "")
|
||||
destinationFile += "_";
|
||||
destinationFile += "source";
|
||||
}
|
||||
if(MainClass.dbInfo.update)
|
||||
{
|
||||
if(destinationFile != "")
|
||||
destinationFile += "_";
|
||||
destinationFile += "update";
|
||||
}
|
||||
if(MainClass.dbInfo.upgrade)
|
||||
{
|
||||
if(destinationFile != "")
|
||||
destinationFile += "_";
|
||||
destinationFile += "upgrade";
|
||||
}
|
||||
if(!string.IsNullOrWhiteSpace(MainClass.dbInfo.description))
|
||||
{
|
||||
if(destinationFile != "")
|
||||
destinationFile += "_";
|
||||
destinationFile += MainClass.dbInfo.description;
|
||||
}
|
||||
else if(destinationFile == "")
|
||||
{
|
||||
destinationFile = "archive";
|
||||
}
|
||||
|
||||
string destination = Path.Combine(destinationFolder, destinationFile) + ".zip";
|
||||
if(File.Exists(destination))
|
||||
{
|
||||
if(Failed != null)
|
||||
Failed("File already exists");
|
||||
return;
|
||||
}
|
||||
|
||||
File.Copy(MainClass.path, destination);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
if(Debugger.IsAttached)
|
||||
throw;
|
||||
if(Failed != null)
|
||||
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
|
||||
}
|
||||
if(Finished != null)
|
||||
Finished();
|
||||
}
|
||||
|
||||
public static void RemoveTempFolder()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(Directory.Exists(MainClass.tmpFolder))
|
||||
{
|
||||
Directory.Delete(MainClass.tmpFolder, true);
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,9 @@ public partial class MainWindow : Window
|
||||
Thread thdCheckFiles;
|
||||
Thread thdAddFiles;
|
||||
Thread thdPackFiles;
|
||||
Thread thdOpenArchive;
|
||||
Thread thdExtractArchive;
|
||||
Thread thdRemoveTemp;
|
||||
bool stopped;
|
||||
ListStore view;
|
||||
|
||||
@@ -356,6 +359,25 @@ public partial class MainWindow : Window
|
||||
chkUpgrade.Active = false;
|
||||
chkNetinstall.Active = false;
|
||||
chkSource.Active = false;
|
||||
|
||||
if(MainClass.tmpFolder != null)
|
||||
{
|
||||
btnStop.Visible = false;
|
||||
prgProgress.Visible = true;
|
||||
prgProgress.Text = "Removing temporary files";
|
||||
thdPulseProgress = new Thread(() =>
|
||||
{
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
prgProgress.Pulse();
|
||||
});
|
||||
Thread.Sleep(10);
|
||||
});
|
||||
Core.Failed += RemoveTempFilesFailed;
|
||||
Core.Finished += RemoveTempFilesFinished;
|
||||
thdRemoveTemp = new Thread(Core.RemoveTempFolder);
|
||||
thdRemoveTemp.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateProgress(string text, string inner, long current, long maximum)
|
||||
@@ -393,30 +415,76 @@ public partial class MainWindow : Window
|
||||
thdPulseProgress.Abort();
|
||||
thdPulseProgress = null;
|
||||
}
|
||||
|
||||
if(thdFindFiles != null)
|
||||
{
|
||||
thdFindFiles.Abort();
|
||||
thdFindFiles = null;
|
||||
}
|
||||
|
||||
if(thdHashFiles != null)
|
||||
{
|
||||
thdHashFiles.Abort();
|
||||
thdHashFiles = null;
|
||||
}
|
||||
|
||||
if(thdCheckFiles != null)
|
||||
{
|
||||
thdCheckFiles.Abort();
|
||||
thdCheckFiles = null;
|
||||
}
|
||||
|
||||
if(thdAddFiles != null)
|
||||
{
|
||||
thdAddFiles.Abort();
|
||||
thdAddFiles = null;
|
||||
}
|
||||
|
||||
if(thdPackFiles != null)
|
||||
{
|
||||
thdPackFiles.Abort();
|
||||
thdPackFiles = null;
|
||||
}
|
||||
|
||||
if(thdOpenArchive != null)
|
||||
{
|
||||
thdOpenArchive.Abort();
|
||||
thdOpenArchive = null;
|
||||
}
|
||||
|
||||
if(MainClass.unarProcess != null)
|
||||
{
|
||||
MainClass.unarProcess.Kill();
|
||||
MainClass.unarProcess = null;
|
||||
}
|
||||
|
||||
if(MainClass.tmpFolder != null)
|
||||
{
|
||||
btnStop.Visible = false;
|
||||
prgProgress.Text = "Removing temporary files";
|
||||
thdPulseProgress = new Thread(() =>
|
||||
{
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
prgProgress.Pulse();
|
||||
});
|
||||
Thread.Sleep(10);
|
||||
});
|
||||
Core.Failed += RemoveTempFilesFailed;
|
||||
Core.Finished += RemoveTempFilesFinished;
|
||||
thdRemoveTemp = new Thread(Core.RemoveTempFolder);
|
||||
thdRemoveTemp.Start();
|
||||
}
|
||||
else
|
||||
RestoreUI();
|
||||
}
|
||||
|
||||
public void RestoreUI()
|
||||
{
|
||||
lblProgress.Visible = false;
|
||||
prgProgress.Visible = false;
|
||||
lblProgress2.Visible = false;
|
||||
prgProgress2.Visible = false;
|
||||
Core.Failed -= HashFilesFailed;
|
||||
Core.Finished -= HashFilesFinished;
|
||||
Core.UpdateProgress -= UpdateProgress;
|
||||
Core.UpdateProgress2 -= UpdateProgress2;
|
||||
btnExit.Sensitive = true;
|
||||
btnFolder.Visible = true;
|
||||
btnArchive.Visible = true;
|
||||
@@ -428,12 +496,65 @@ public partial class MainWindow : Window
|
||||
btnArchive.Visible = true;
|
||||
btnSettings.Sensitive = true;
|
||||
Core.Failed -= FindFilesFailed;
|
||||
Core.Failed -= HashFilesFailed;
|
||||
Core.Failed -= ChkFilesFailed;
|
||||
Core.Failed -= OpenArchiveFailed;
|
||||
Core.Failed -= AddFilesToDbFailed;
|
||||
Core.Failed -= PackFilesFailed;
|
||||
Core.Failed -= ExtractArchiveFailed;
|
||||
Core.Failed -= RemoveTempFilesFailed;
|
||||
Core.Finished -= FindFilesFinished;
|
||||
Core.Finished -= HashFilesFinished;
|
||||
Core.Finished -= ChkFilesFinished;
|
||||
Core.Finished -= OpenArchiveFinished;
|
||||
Core.Finished -= AddFilesToDbFinished;
|
||||
Core.Finished -= ExtractArchiveFinished;
|
||||
Core.Finished -= RemoveTempFilesFinished;
|
||||
Core.FinishedWithText -= PackFilesFinished;
|
||||
Core.UpdateProgress -= UpdateProgress;
|
||||
Core.UpdateProgress2 -= UpdateProgress2;
|
||||
btnStop.Visible = false;
|
||||
if(view != null)
|
||||
view.Clear();
|
||||
}
|
||||
|
||||
public void RemoveTempFilesFailed(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;
|
||||
}
|
||||
Core.Failed -= RemoveTempFilesFailed;
|
||||
Core.Finished -= RemoveTempFilesFinished;
|
||||
MainClass.path = null;
|
||||
MainClass.tmpFolder = null;
|
||||
RestoreUI();
|
||||
});
|
||||
}
|
||||
|
||||
public void RemoveTempFilesFinished()
|
||||
{
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
if(thdPulseProgress != null)
|
||||
{
|
||||
thdPulseProgress.Abort();
|
||||
thdPulseProgress = null;
|
||||
}
|
||||
Core.Failed -= RemoveTempFilesFailed;
|
||||
Core.Finished -= RemoveTempFilesFinished;
|
||||
MainClass.path = null;
|
||||
MainClass.tmpFolder = null;
|
||||
RestoreUI();
|
||||
});
|
||||
}
|
||||
|
||||
protected void OnBtnAddClicked(object sender, EventArgs e)
|
||||
{
|
||||
btnAdd.Sensitive = false;
|
||||
@@ -576,9 +697,30 @@ public partial class MainWindow : Window
|
||||
MainClass.dbInfo.update = chkUpdate.Active;
|
||||
MainClass.dbInfo.upgrade = chkUpgrade.Active;
|
||||
|
||||
if(!string.IsNullOrEmpty(MainClass.tmpFolder) && MainClass.copyArchive)
|
||||
{
|
||||
thdPulseProgress = new Thread(() =>
|
||||
{
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
prgProgress.Pulse();
|
||||
});
|
||||
Thread.Sleep(10);
|
||||
});
|
||||
Core.UpdateProgress -= UpdateProgress;
|
||||
Core.UpdateProgress2 -= UpdateProgress2;
|
||||
prgProgress.Text = "Copying archive as is.";
|
||||
prgProgress2.Visible = false;
|
||||
lblProgress2.Visible = false;
|
||||
thdPackFiles = new Thread(Core.CopyArchive);
|
||||
thdPackFiles.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
thdPackFiles = new Thread(Core.CompressFiles);
|
||||
thdPackFiles.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public void PackFilesFinished(string text)
|
||||
{
|
||||
@@ -647,4 +789,182 @@ public partial class MainWindow : Window
|
||||
chkSource.Sensitive = true;
|
||||
});
|
||||
}
|
||||
|
||||
protected void OnBtnArchiveClicked(object sender, EventArgs e)
|
||||
{
|
||||
if(!MainClass.unarUsable)
|
||||
{
|
||||
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Cannot open archives without a working unar installation.");
|
||||
dlgMsg.Run();
|
||||
dlgMsg.Destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
FileChooserDialog dlgFolder = new FileChooserDialog("Open archive", this, FileChooserAction.Open,
|
||||
"Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
|
||||
dlgFolder.SelectMultiple = false;
|
||||
|
||||
if(dlgFolder.Run() == (int)ResponseType.Accept)
|
||||
{
|
||||
stopped = false;
|
||||
prgProgress.Text = "Opening archive";
|
||||
lblProgress.Visible = false;
|
||||
prgProgress.Visible = true;
|
||||
btnExit.Sensitive = false;
|
||||
btnFolder.Visible = false;
|
||||
btnArchive.Visible = false;
|
||||
btnSettings.Sensitive = false;
|
||||
thdPulseProgress = new Thread(() =>
|
||||
{
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
prgProgress.Pulse();
|
||||
});
|
||||
Thread.Sleep(10);
|
||||
});
|
||||
|
||||
thdOpenArchive = new Thread(Core.OpenArchive);
|
||||
MainClass.path = dlgFolder.Filename;
|
||||
Core.Failed += OpenArchiveFailed;
|
||||
Core.Finished += OpenArchiveFinished;
|
||||
btnStop.Visible = true;
|
||||
thdPulseProgress.Start();
|
||||
thdOpenArchive.Start();
|
||||
}
|
||||
|
||||
dlgFolder.Destroy();
|
||||
}
|
||||
|
||||
public void OpenArchiveFailed(string text)
|
||||
{
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
if(!stopped)
|
||||
{
|
||||
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, text);
|
||||
dlgMsg.Run();
|
||||
dlgMsg.Destroy();
|
||||
}
|
||||
if(thdPulseProgress != null)
|
||||
thdPulseProgress.Abort();
|
||||
lblProgress.Visible = false;
|
||||
prgProgress.Visible = false;
|
||||
btnExit.Sensitive = true;
|
||||
btnFolder.Visible = true;
|
||||
btnArchive.Visible = true;
|
||||
btnSettings.Sensitive = true;
|
||||
Core.Failed -= OpenArchiveFailed;
|
||||
Core.Finished -= OpenArchiveFinished;
|
||||
thdOpenArchive = null;
|
||||
});
|
||||
}
|
||||
|
||||
public void OpenArchiveFinished()
|
||||
{
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
stopped = false;
|
||||
prgProgress.Text = "Extracting archive";
|
||||
lblProgress.Visible = false;
|
||||
prgProgress.Visible = true;
|
||||
prgProgress2.Visible = true;
|
||||
btnExit.Sensitive = false;
|
||||
btnFolder.Visible = false;
|
||||
btnArchive.Visible = false;
|
||||
btnSettings.Sensitive = false;
|
||||
thdPulseProgress = new Thread(() =>
|
||||
{
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
prgProgress.Pulse();
|
||||
});
|
||||
Thread.Sleep(10);
|
||||
});
|
||||
Core.Failed -= OpenArchiveFailed;
|
||||
Core.Finished -= OpenArchiveFinished;
|
||||
thdOpenArchive = null;
|
||||
Core.Failed += ExtractArchiveFailed;
|
||||
Core.Finished += ExtractArchiveFinished;
|
||||
Core.UpdateProgress2 += UpdateProgress2;
|
||||
thdExtractArchive = new Thread(Core.ExtractArchive);
|
||||
thdExtractArchive.Start();
|
||||
});
|
||||
}
|
||||
|
||||
public void ExtractArchiveFailed(string text)
|
||||
{
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
if(!stopped)
|
||||
{
|
||||
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, text);
|
||||
dlgMsg.Run();
|
||||
dlgMsg.Destroy();
|
||||
}
|
||||
if(thdPulseProgress != null)
|
||||
thdPulseProgress.Abort();
|
||||
lblProgress.Visible = false;
|
||||
prgProgress2.Visible = false;
|
||||
btnExit.Sensitive = true;
|
||||
btnFolder.Visible = true;
|
||||
btnArchive.Visible = true;
|
||||
btnSettings.Sensitive = true;
|
||||
Core.Failed -= ExtractArchiveFailed;
|
||||
Core.Finished -= ExtractArchiveFinished;
|
||||
Core.UpdateProgress2 -= UpdateProgress2;
|
||||
thdExtractArchive = null;
|
||||
if(MainClass.tmpFolder != null)
|
||||
{
|
||||
btnStop.Visible = false;
|
||||
prgProgress.Text = "Removing temporary files";
|
||||
thdPulseProgress = new Thread(() =>
|
||||
{
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
prgProgress.Pulse();
|
||||
});
|
||||
Thread.Sleep(10);
|
||||
});
|
||||
Core.Failed += RemoveTempFilesFailed;
|
||||
Core.Finished += RemoveTempFilesFinished;
|
||||
thdRemoveTemp = new Thread(Core.RemoveTempFolder);
|
||||
thdRemoveTemp.Start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void ExtractArchiveFinished()
|
||||
{
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
if(thdExtractArchive != null)
|
||||
thdExtractArchive.Abort();
|
||||
stopped = false;
|
||||
lblProgress.Text = "Finding files";
|
||||
lblProgress.Visible = true;
|
||||
prgProgress.Visible = true;
|
||||
btnExit.Sensitive = false;
|
||||
btnFolder.Visible = false;
|
||||
btnArchive.Visible = false;
|
||||
btnSettings.Sensitive = false;
|
||||
Core.Failed -= ExtractArchiveFailed;
|
||||
Core.Finished -= ExtractArchiveFinished;
|
||||
Core.UpdateProgress2 -= UpdateProgress2;
|
||||
thdPulseProgress = new Thread(() =>
|
||||
{
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
prgProgress.Pulse();
|
||||
});
|
||||
Thread.Sleep(10);
|
||||
});
|
||||
|
||||
thdFindFiles = new Thread(Core.FindFiles);
|
||||
Core.Failed += FindFilesFailed;
|
||||
Core.Finished += FindFilesFinished;
|
||||
btnStop.Visible = true;
|
||||
thdPulseProgress.Start();
|
||||
thdFindFiles.Start();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using Gtk;
|
||||
|
||||
@@ -40,6 +41,11 @@ namespace osrepodbmgr
|
||||
public static bool unarUsable;
|
||||
public delegate void UnarChangeStatusDelegate();
|
||||
public static event UnarChangeStatusDelegate UnarChangeStatus;
|
||||
public static string tmpFolder;
|
||||
public static long noFilesInArchive;
|
||||
public static string archiveFormat;
|
||||
public static Process unarProcess;
|
||||
public static bool copyArchive;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
@@ -65,6 +71,8 @@ namespace osrepodbmgr
|
||||
unarUsable = true;
|
||||
if(UnarChangeStatus != null)
|
||||
UnarChangeStatus();
|
||||
Core.Finished -= CheckUnarFinished;
|
||||
Core.Failed -= CheckUnarFailed;
|
||||
}
|
||||
|
||||
static void CheckUnarFailed(string text)
|
||||
@@ -72,6 +80,8 @@ namespace osrepodbmgr
|
||||
unarUsable = false;
|
||||
if(UnarChangeStatus != null)
|
||||
UnarChangeStatus();
|
||||
Core.Finished -= CheckUnarFinished;
|
||||
Core.Failed -= CheckUnarFailed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -587,7 +587,6 @@ public partial class MainWindow
|
||||
w51.Fill = false;
|
||||
// Container child hbox1.Gtk.Box+BoxChild
|
||||
this.btnArchive = new global::Gtk.Button();
|
||||
this.btnArchive.Sensitive = false;
|
||||
this.btnArchive.CanFocus = true;
|
||||
this.btnArchive.Name = "btnArchive";
|
||||
this.btnArchive.UseUnderline = true;
|
||||
@@ -653,6 +652,7 @@ public partial class MainWindow
|
||||
this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent);
|
||||
this.btnStop.Clicked += new global::System.EventHandler(this.OnBtnStopClicked);
|
||||
this.btnFolder.Clicked += new global::System.EventHandler(this.OnBtnFolderClicked);
|
||||
this.btnArchive.Clicked += new global::System.EventHandler(this.OnBtnArchiveClicked);
|
||||
this.btnAdd.Clicked += new global::System.EventHandler(this.OnBtnAddClicked);
|
||||
this.btnPack.Clicked += new global::System.EventHandler(this.OnBtnPackClicked);
|
||||
this.btnClose.Clicked += new global::System.EventHandler(this.OnBtnCloseClicked);
|
||||
|
||||
@@ -643,12 +643,12 @@
|
||||
<child>
|
||||
<widget class="Gtk.Button" id="btnArchive">
|
||||
<property name="MemberName" />
|
||||
<property name="Sensitive">False</property>
|
||||
<property name="CanFocus">True</property>
|
||||
<property name="Type">TextAndIcon</property>
|
||||
<property name="Icon">stock:gtk-open Menu</property>
|
||||
<property name="Label" translatable="yes">Open _archive</property>
|
||||
<property name="UseUnderline">True</property>
|
||||
<signal name="Clicked" handler="OnBtnArchiveClicked" />
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="PackType">End</property>
|
||||
|
||||
@@ -59,6 +59,9 @@
|
||||
<Reference Include="DotNetZip">
|
||||
<HintPath>..\packages\DotNetZip.1.10.1\lib\net20\DotNetZip.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="gtk-gui\gui.stetic">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="DotNetZip" version="1.10.1" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" />
|
||||
<package id="plist-cil" version="1.15.0" targetFramework="net45" />
|
||||
<package id="System.Data.SQLite.Core" version="1.0.105.0" targetFramework="net45" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user