Skip to content

Commit

Permalink
Support command line parameter of file to be opened
Browse files Browse the repository at this point in the history
  • Loading branch information
Dijji committed Aug 29, 2018
1 parent bc9b7fa commit 9114ded
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 33 deletions.
2 changes: 1 addition & 1 deletion App.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Application x:Class="XstReader.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
Startup="Application_Startup">
<Application.Resources>

</Application.Resources>
Expand Down
7 changes: 7 additions & 0 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@ namespace XstReader
/// </summary>
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
MainWindow wnd = new MainWindow();
if (e.Args.Length == 1)
wnd.OpenFile(e.Args[0]);
wnd.Show();
}
}
}
71 changes: 40 additions & 31 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,45 @@ public MainWindow()
InitializeComponent();
this.DataContext = view;
}


public void OpenFile(string fileName)
{
if (!System.IO.File.Exists(fileName))
return;

Properties.Settings.Default.LastFolder = System.IO.Path.GetDirectoryName(fileName);
Properties.Settings.Default.Save();

view.Clear();
txtStatus.Text = "Loading...";
Mouse.OverrideCursor = Cursors.Wait;

// Load on a background thread so we can keep the UI in sync
Task.Factory.StartNew(() =>
{
try
{
xstFile = new XstFile(view, fileName);
xstFile.ReadFolderTree();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message, "Error reading xst file");
}
})
// When loading completes, update the UI using the UI thread
.ContinueWith((task) =>
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{
txtStatus.Text = "";
Mouse.OverrideCursor = null;
Title = "Xst Reader - " + System.IO.Path.GetFileName(fileName);
}));
});
}


private void btnOpen_Click(object sender, RoutedEventArgs e)
{
// Ask for a .ost or .pst file to open
Expand All @@ -43,36 +81,7 @@ private void btnOpen_Click(object sender, RoutedEventArgs e)

if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Properties.Settings.Default.LastFolder = System.IO.Path.GetDirectoryName(dialog.FileName);
Properties.Settings.Default.Save();

view.Clear();
txtStatus.Text = "Loading...";
Mouse.OverrideCursor = Cursors.Wait;

// Load on a background thread so we can keep the UI in sync
Task.Factory.StartNew(() =>
{
try
{
xstFile = new XstFile(view, dialog.FileName);
xstFile.ReadFolderTree();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message, "Error reading xst file");
}
})
// When loading completes, update the UI using the UI thread
.ContinueWith((task) =>
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{
txtStatus.Text = "";
Mouse.OverrideCursor = null;
Title = "Xst Reader - " + System.IO.Path.GetFileName(dialog.FileName);
}));
});
OpenFile(dialog.FileName);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.*")]
[assembly: AssemblyVersion("1.4.*")]

0 comments on commit 9114ded

Please sign in to comment.