Detect and check unar and lsar runnability.

This commit is contained in:
2017-04-20 21:20:37 +01:00
parent 5512243bfd
commit eb43fe7e05
8 changed files with 249 additions and 27 deletions

View File

@@ -1,3 +1,14 @@
2017-04-20 Natalia Portillo <claunia@claunia.com>
* Core.cs:
* Program.cs:
* MainWindow.cs:
* frmSettings.cs:
* gtk-gui/gui.stetic:
* gtk-gui/MainWindow.cs:
* gtk-gui/osrepodbmgr.frmSettings.cs:
Detect and check unar and lsar runnability.
2017-04-20 Natalia Portillo <claunia@claunia.com>
* Core.cs:

View File

@@ -27,6 +27,7 @@
//
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using Ionic.Zip;
@@ -80,7 +81,7 @@ namespace osrepodbmgr
}
catch(Exception ex)
{
if(System.Diagnostics.Debugger.IsAttached)
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
@@ -140,7 +141,7 @@ namespace osrepodbmgr
}
catch(Exception ex)
{
if(System.Diagnostics.Debugger.IsAttached)
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
@@ -167,7 +168,7 @@ namespace osrepodbmgr
}
catch(Exception ex)
{
if(System.Diagnostics.Debugger.IsAttached)
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
@@ -199,7 +200,7 @@ namespace osrepodbmgr
}
catch(Exception ex)
{
if(System.Diagnostics.Debugger.IsAttached)
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
@@ -264,7 +265,7 @@ namespace osrepodbmgr
}
catch(Exception ex)
{
if(System.Diagnostics.Debugger.IsAttached)
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
@@ -439,7 +440,7 @@ namespace osrepodbmgr
}
catch(Exception ex)
{
if(System.Diagnostics.Debugger.IsAttached)
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
@@ -463,11 +464,106 @@ namespace osrepodbmgr
string.Format("{0} / {1}", e.BytesTransferred, e.TotalBytesToTransfer),
e.BytesTransferred, e.TotalBytesToTransfer);
System.Console.WriteLine("{0}", e.EventType);
Console.WriteLine("{0}", e.EventType);
if(e.EventType == ZipProgressEventType.Error_Saving && Failed != null)
Failed("Failed compression");
if(e.EventType == ZipProgressEventType.Saving_Completed && FinishedWithText != null)
FinishedWithText(e.ArchiveName);
}
public static void CheckUnar()
{
if(string.IsNullOrWhiteSpace(Settings.Current.UnArchiverPath))
{
if(Failed != null)
Failed("unar path is not set.");
return;
}
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 unarPath = Path.Combine(unarFolder, unarfilename + extension);
string lsarPath = Path.Combine(unarFolder, lsarfilename + extension);
if(!File.Exists(unarPath))
{
if(Failed != null)
Failed(string.Format("Cannot find unar executable at {0}.", unarPath));
return;
}
if(!File.Exists(lsarPath))
{
if(Failed != null)
Failed("Cannot find unar executable.");
return;
}
string unarOut, lsarOut;
try
{
Process unarProcess = new Process();
unarProcess.StartInfo.FileName = unarPath;
unarProcess.StartInfo.CreateNoWindow = true;
unarProcess.StartInfo.RedirectStandardOutput = true;
unarProcess.StartInfo.UseShellExecute = false;
unarProcess.Start();
unarProcess.WaitForExit();
unarOut = unarProcess.StandardOutput.ReadToEnd();
}
catch
{
if(Failed != null)
Failed("Cannot run unar.");
return;
}
try
{
Process lsarProcess = new Process();
lsarProcess.StartInfo.FileName = lsarPath;
lsarProcess.StartInfo.CreateNoWindow = true;
lsarProcess.StartInfo.RedirectStandardOutput = true;
lsarProcess.StartInfo.UseShellExecute = false;
lsarProcess.Start();
lsarProcess.WaitForExit();
lsarOut = lsarProcess.StandardOutput.ReadToEnd();
}
catch
{
if(Failed != null)
Failed("Cannot run lsar.");
return;
}
if(!unarOut.StartsWith("unar ", StringComparison.CurrentCulture))
{
if(Failed != null)
Failed("Not the correct unar executable");
return;
}
if(!lsarOut.StartsWith("lsar ", StringComparison.CurrentCulture))
{
if(Failed != null)
Failed("Not the correct unar executable");
return;
}
Process versionProcess = new Process();
versionProcess.StartInfo.FileName = unarPath;
versionProcess.StartInfo.CreateNoWindow = true;
versionProcess.StartInfo.RedirectStandardOutput = true;
versionProcess.StartInfo.UseShellExecute = false;
versionProcess.StartInfo.Arguments = "-v";
versionProcess.Start();
versionProcess.WaitForExit();
if(FinishedWithText != null)
FinishedWithText(versionProcess.StandardOutput.ReadToEnd().TrimEnd(new char[] { '\n' }));
}
}
}

View File

@@ -26,10 +26,10 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
using System;
using System.Collections.Generic;
using System.Threading;
using Gtk;
using osrepodbmgr;
using System.Collections.Generic;
public partial class MainWindow : Window
{
@@ -48,6 +48,9 @@ public partial class MainWindow : Window
Core.InitDB();
MainClass.UnarChangeStatus += UnarChangeStatus;
MainClass.CheckUnar();
CellRendererText filenameCell = new CellRendererText();
CellRendererText hashCell = new CellRendererText();
CellRendererToggle dbCell = new CellRendererToggle();
@@ -64,6 +67,14 @@ public partial class MainWindow : Window
treeFiles.AppendColumn(dbColumn);
}
void UnarChangeStatus()
{
Application.Invoke(delegate
{
btnArchive.Sensitive = MainClass.unarUsable;
});
}
protected void OnDeleteEvent(object sender, DeleteEventArgs a)
{
if(btnStop.Visible)

View File

@@ -26,6 +26,7 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
using System.Collections.Generic;
using System.Threading;
using Gtk;
namespace osrepodbmgr
@@ -36,14 +37,41 @@ namespace osrepodbmgr
public static Dictionary<string, string> hashes;
public static string path;
public static DBEntry dbInfo;
public static bool unarUsable;
public delegate void UnarChangeStatusDelegate();
public static event UnarChangeStatusDelegate UnarChangeStatus;
public static void Main(string[] args)
{
Settings.LoadSettings();
CheckUnar();
Application.Init();
MainWindow win = new MainWindow();
win.Show();
Application.Run();
}
public static void CheckUnar()
{
Core.Finished += CheckUnarFinished;
Core.Failed += CheckUnarFailed;
Thread thdCheckUnar = new Thread(Core.CheckUnar);
thdCheckUnar.Start();
}
static void CheckUnarFinished()
{
unarUsable = true;
if(UnarChangeStatus != null)
UnarChangeStatus();
}
static void CheckUnarFailed(string text)
{
unarUsable = false;
if(UnarChangeStatus != null)
UnarChangeStatus();
}
}
}

View File

@@ -26,12 +26,16 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
using System;
using System.IO;
using System.Threading;
using Gtk;
namespace osrepodbmgr
{
public partial class frmSettings : Window
{
string oldUnarPath;
public frmSettings() :
base(WindowType.Toplevel)
{
@@ -40,6 +44,9 @@ namespace osrepodbmgr
txtUnar.Text = osrepodbmgr.Settings.Current.UnArchiverPath;
txtDatabase.Text = osrepodbmgr.Settings.Current.DatabasePath;
txtRepository.Text = osrepodbmgr.Settings.Current.RepositoryPath;
if(!string.IsNullOrWhiteSpace(txtUnar.Text))
CheckUnar();
}
protected void OnBtnCancelClicked(object sender, EventArgs e)
@@ -57,6 +64,7 @@ namespace osrepodbmgr
osrepodbmgr.Settings.SaveSettings();
Core.CloseDB();
Core.InitDB();
MainClass.CheckUnar();
Destroy();
}
@@ -67,10 +75,11 @@ namespace osrepodbmgr
dlgFile.SelectMultiple = false;
dlgFile.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
// TODO: Check it is really unarchiver
if(dlgFile.Run() == (int)ResponseType.Accept)
{
txtUnar.Text = dlgFile.Filename;
lblUnarVersion.Visible = false;
CheckUnar();
}
dlgFile.Destroy();
@@ -98,7 +107,6 @@ namespace osrepodbmgr
dlgFolder.SelectMultiple = false;
dlgFolder.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
// TODO: Check it is really unarchiver
if(dlgFolder.Run() == (int)ResponseType.Accept)
{
txtRepository.Text = dlgFolder.Filename;
@@ -115,10 +123,9 @@ namespace osrepodbmgr
dlgFile.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
dlgFile.SetFilename("osrepodbmgr.db");
// TODO: Check it is really unarchiver
if(dlgFile.Run() == (int)ResponseType.Accept)
{
if(System.IO.File.Exists(dlgFile.Filename))
if(File.Exists(dlgFile.Filename))
{
DBCore _dbCore = new SQLite();
bool notDb = false;
@@ -171,5 +178,47 @@ namespace osrepodbmgr
dlgFile.Destroy();
}
void CheckUnar()
{
Core.FinishedWithText += CheckUnarFinished;
Core.Failed += CheckUnarFailed;
oldUnarPath = osrepodbmgr.Settings.Current.UnArchiverPath;
osrepodbmgr.Settings.Current.UnArchiverPath = txtUnar.Text;
Thread thdCheckUnar = new Thread(Core.CheckUnar);
thdCheckUnar.Start();
}
void CheckUnarFinished(string text)
{
Application.Invoke(delegate
{
Core.FinishedWithText -= CheckUnarFinished;
Core.Failed -= CheckUnarFailed;
lblUnarVersion.Text = text;
lblUnarVersion.Visible = true;
osrepodbmgr.Settings.Current.UnArchiverPath = oldUnarPath;
});
}
void CheckUnarFailed(string text)
{
Application.Invoke(delegate
{
Core.FinishedWithText -= CheckUnarFinished;
Core.Failed -= CheckUnarFailed;
if(string.IsNullOrWhiteSpace(oldUnarPath))
txtUnar.Text = "";
else
txtUnar.Text = oldUnarPath;
osrepodbmgr.Settings.Current.UnArchiverPath = oldUnarPath;
MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, text);
dlgMsg.Run();
dlgMsg.Destroy();
});
}
}
}

View File

@@ -587,6 +587,7 @@ 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;

View File

@@ -643,6 +643,7 @@
<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>
@@ -877,7 +878,7 @@ QNX/QNX/20090229/source.zip</property>
</widget>
</child>
</widget>
<widget class="Gtk.Window" id="osrepodbmgr.frmSettings" design-size="400 194">
<widget class="Gtk.Window" id="osrepodbmgr.frmSettings" design-size="400 210">
<property name="MemberName" />
<property name="Title" translatable="yes">frmSettings</property>
<property name="WindowPosition">CenterOnParent</property>
@@ -1097,6 +1098,19 @@ QNX/QNX/20090229/source.zip</property>
<property name="Fill">False</property>
</packing>
</child>
<child>
<widget class="Gtk.Label" id="lblUnarVersion">
<property name="MemberName" />
<property name="Visible">False</property>
<property name="LabelProp" translatable="yes">label1</property>
</widget>
<packing>
<property name="Position">4</property>
<property name="AutoSize">True</property>
<property name="Expand">False</property>
<property name="Fill">False</property>
</packing>
</child>
<child>
<widget class="Gtk.HBox" id="hbox18">
<property name="MemberName" />
@@ -1138,7 +1152,7 @@ QNX/QNX/20090229/source.zip</property>
</child>
</widget>
<packing>
<property name="Position">4</property>
<property name="Position">5</property>
<property name="AutoSize">True</property>
<property name="Expand">False</property>
<property name="Fill">False</property>

View File

@@ -38,6 +38,8 @@ namespace osrepodbmgr
private global::Gtk.Button btnUnar;
private global::Gtk.Label lblUnarVersion;
private global::Gtk.HBox hbox18;
private global::Gtk.Button btnCancel;
@@ -220,6 +222,15 @@ namespace osrepodbmgr
w20.Expand = false;
w20.Fill = false;
// Container child vbox5.Gtk.Box+BoxChild
this.lblUnarVersion = new global::Gtk.Label();
this.lblUnarVersion.Name = "lblUnarVersion";
this.lblUnarVersion.LabelProp = global::Mono.Unix.Catalog.GetString("label1");
this.vbox5.Add(this.lblUnarVersion);
global::Gtk.Box.BoxChild w21 = ((global::Gtk.Box.BoxChild)(this.vbox5[this.lblUnarVersion]));
w21.Position = 4;
w21.Expand = false;
w21.Fill = false;
// Container child vbox5.Gtk.Box+BoxChild
this.hbox18 = new global::Gtk.HBox();
this.hbox18.Name = "hbox18";
this.hbox18.Spacing = 6;
@@ -231,10 +242,10 @@ namespace osrepodbmgr
this.btnCancel.UseUnderline = true;
this.btnCancel.Label = "gtk-cancel";
this.hbox18.Add(this.btnCancel);
global::Gtk.Box.BoxChild w21 = ((global::Gtk.Box.BoxChild)(this.hbox18[this.btnCancel]));
w21.Position = 0;
w21.Expand = false;
w21.Fill = false;
global::Gtk.Box.BoxChild w22 = ((global::Gtk.Box.BoxChild)(this.hbox18[this.btnCancel]));
w22.Position = 0;
w22.Expand = false;
w22.Fill = false;
// Container child hbox18.Gtk.Box+BoxChild
this.btnApply = new global::Gtk.Button();
this.btnApply.CanFocus = true;
@@ -243,23 +254,24 @@ namespace osrepodbmgr
this.btnApply.UseUnderline = true;
this.btnApply.Label = "gtk-apply";
this.hbox18.Add(this.btnApply);
global::Gtk.Box.BoxChild w22 = ((global::Gtk.Box.BoxChild)(this.hbox18[this.btnApply]));
w22.PackType = ((global::Gtk.PackType)(1));
w22.Position = 1;
w22.Expand = false;
w22.Fill = false;
this.vbox5.Add(this.hbox18);
global::Gtk.Box.BoxChild w23 = ((global::Gtk.Box.BoxChild)(this.vbox5[this.hbox18]));
w23.Position = 4;
global::Gtk.Box.BoxChild w23 = ((global::Gtk.Box.BoxChild)(this.hbox18[this.btnApply]));
w23.PackType = ((global::Gtk.PackType)(1));
w23.Position = 1;
w23.Expand = false;
w23.Fill = false;
this.vbox5.Add(this.hbox18);
global::Gtk.Box.BoxChild w24 = ((global::Gtk.Box.BoxChild)(this.vbox5[this.hbox18]));
w24.Position = 5;
w24.Expand = false;
w24.Fill = false;
this.Add(this.vbox5);
if((this.Child != null))
{
this.Child.ShowAll();
}
this.DefaultWidth = 400;
this.DefaultHeight = 194;
this.DefaultHeight = 210;
this.lblUnarVersion.Hide();
this.Show();
this.btnDatabase.Clicked += new global::System.EventHandler(this.OnBtnDatabaseClicked);
this.btnRepository.Clicked += new global::System.EventHandler(this.OnBtnRepositoryClicked);