diff --git a/src/vpm/App.config b/src/vpm/App.config
index 5ad2c54..8859cf2 100644
--- a/src/vpm/App.config
+++ b/src/vpm/App.config
@@ -49,6 +49,10 @@
+
+
+
+
diff --git a/src/vpm/ChooseDir.xaml b/src/vpm/ChooseDir.xaml
new file mode 100644
index 0000000..d46e1b6
--- /dev/null
+++ b/src/vpm/ChooseDir.xaml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/vpm/ChooseDir.xaml.cs b/src/vpm/ChooseDir.xaml.cs
new file mode 100644
index 0000000..aad4ec3
--- /dev/null
+++ b/src/vpm/ChooseDir.xaml.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using MahApps.Metro.Controls;
+using Microsoft.WindowsAPICodePack.Dialogs;
+using Path = System.IO.Path;
+
+namespace vpm
+{
+ ///
+ /// Interaction logic for ChooseDir.xaml
+ ///
+ public partial class ChooseDir
+ {
+ public string PathFromVpm { get; set; }
+ public string PathResult { get; set; }
+ public bool Cancelled { get; set; }
+
+ public ChooseDir(string pathin)
+ {
+ PathFromVpm = pathin;
+ InitializeComponent();
+ }
+
+ private void ChooseDir_OnInitialized_OnInitialized(object sender, EventArgs e)
+ {
+ DirBox.Text = PathFromVpm;
+ }
+
+ private void OnDirDrop(object sender, DragEventArgs e)
+ {
+ if (e.Data.GetDataPresent(DataFormats.FileDrop))
+ {
+ var files = (string[])e.Data.GetData(DataFormats.FileDrop);
+ if (files != null)
+ {
+ DirBox.Text = files[0];
+ }
+ }
+ }
+
+ private void OnBrowseDir(object sender, RoutedEventArgs e)
+ {
+ var dialog = new CommonOpenFileDialog
+ {
+ IsFolderPicker = true,
+ Multiselect = false
+ };
+ var result = dialog.ShowDialog();
+ if (result == CommonFileDialogResult.Ok)
+ {
+ DirBox.Text = dialog.FileName;
+ }
+ }
+
+ private void OnConfirm(object sender, RoutedEventArgs e)
+ {
+ Cancelled = false;
+ PathResult = DirBox.Text;
+ VpmConfig.Instance.WaitSignal = false;
+ VpmConfig.Instance.DirWindow.Close();
+ }
+
+ private void OnCancelled(object sender, EventArgs e)
+ {
+ Cancelled = true;
+ VpmConfig.Instance.WaitSignal = false;
+ VpmConfig.Instance.DirWindow.Close();
+ }
+ }
+}
diff --git a/src/vpm/Program.cs b/src/vpm/Program.cs
index f4abf28..4fdc976 100644
--- a/src/vpm/Program.cs
+++ b/src/vpm/Program.cs
@@ -3,7 +3,9 @@
using System.IO;
using System.Linq;
using System.Threading;
+using System.Threading.Tasks;
using System.Windows;
+using MahApps.Metro.Controls;
using PowerArgs;
namespace vpm
@@ -19,7 +21,7 @@ static void Main(string[] args)
Console.ResetColor();
try
{
- Args.Parse(args);
+ VpmConfig.Instance.Arguments = Args.Parse(args);
}
catch (ArgException ex)
{
@@ -36,7 +38,7 @@ static void Main(string[] args)
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Parsing input Pack");
Console.ResetColor();
- var vpxml = VpmUtils.ParseAndValidateXmlFile(Args.GetAmbientArgs().VPackFile);
+ var vpxml = VpmUtils.ParseAndValidateXmlFile(VpmConfig.Instance.Arguments.VPackFile);
var namenode = vpxml.SelectSingleNode("/vpack/meta/name");
var srcnode = vpxml.SelectSingleNode("/vpack/meta/source");
@@ -53,6 +55,37 @@ static void Main(string[] args)
Console.WriteLine("Input pack is " + name);
Console.ResetColor();
+ VpmConfig.Instance.WaitSignal = true;
+ VpmConfig.Instance.WinApp.BeginInvoke(() =>
+ {
+ var winapp = VpmConfig.Instance.WinApp;
+ var window = VpmConfig.Instance.DirWindow = new ChooseDir(VpmConfig.Instance.Arguments.VVVVDir);
+ winapp.MainWindow = window;
+ window.Show();
+ });
+ VpmUtils.Wait();
+ var dirwindow = (ChooseDir)VpmConfig.Instance.DirWindow;
+ if (dirwindow.Cancelled)
+ {
+ //VpmUtils.CleanUp();
+ Environment.Exit(0);
+ }
+ VpmConfig.Instance.Arguments.VVVVDir = dirwindow.PathResult;
+
+ if (!Directory.Exists(VpmConfig.Instance.Arguments.VVVVDir))
+ {
+ Console.WriteLine("Destination directory doesn't exist. Creating it.");
+ try
+ {
+ Directory.CreateDirectory(VpmConfig.Instance.Arguments.VVVVDir);
+ }
+ catch (Exception)
+ {
+ Console.WriteLine("Couldn't do that.");
+ throw;
+ }
+ }
+
List aliaslist = null;
if (aliasesnode != null)
{
@@ -69,7 +102,7 @@ static void Main(string[] args)
Console.WriteLine("Input pack seems to be already existing as " + matchalias);
if (VpmUtils.PromptYayOrNay("Do you want to overwrite?"))
{
- var packdir = Path.Combine(Args.GetAmbientArgs().VVVVDir, "packs", matchalias);
+ var packdir = Path.Combine(VpmConfig.Instance.Arguments.VVVVDir, "packs", matchalias);
VpmUtils.DeleteDirectory(packdir, true);
}
else
@@ -83,11 +116,18 @@ static void Main(string[] args)
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Initialization complete.");
Console.ResetColor();
-
- var winapp = VpmConfig.Instance.WinApp = new Application();
- var window = VpmConfig.Instance.AgreeWindow = new UserAgree();
- winapp.Run(window);
+ VpmConfig.Instance.WinApp.BeginInvoke(() =>
+ {
+ var winapp = VpmConfig.Instance.WinApp;
+ var window = VpmConfig.Instance.AgreeWindow = new UserAgree();
+ winapp.MainWindow = window;
+ window.Show();
+ });
+ while (!VpmConfig.Instance.AgreementsAgreed)
+ {
+ Thread.Sleep(10);
+ }
if (VpmConfig.Instance.InstallationCancelled)
{
diff --git a/src/vpm/UserAgree.xaml b/src/vpm/UserAgree.xaml
index bf7c631..bcd991a 100644
--- a/src/vpm/UserAgree.xaml
+++ b/src/vpm/UserAgree.xaml
@@ -10,7 +10,7 @@
BorderThickness="0"
GlowBrush="Black"
ResizeMode="CanResizeWithGrip"
- Initialized="UserAgree_OnInitialized" Background="#FF2C2C2C" NonActiveWindowTitleBrush="#FF2C2C2C" OverrideDefaultWindowCommandsBrush="White" TitleForeground="White" WindowTitleBrush="#FF2C2C2C" Foreground="White">
+ Initialized="UserAgree_OnInitialized" Background="#FF2C2C2C" NonActiveWindowTitleBrush="#FF2C2C2C" OverrideDefaultWindowCommandsBrush="White" TitleForeground="White" WindowTitleBrush="#FF2C2C2C" Foreground="White" Closed="OnCancelled">
diff --git a/src/vpm/UserAgree.xaml.cs b/src/vpm/UserAgree.xaml.cs
index 0b37659..7dd5483 100644
--- a/src/vpm/UserAgree.xaml.cs
+++ b/src/vpm/UserAgree.xaml.cs
@@ -61,8 +61,9 @@ public void ContinueFromJS()
private void ContinueInstall_Click(object sender, RoutedEventArgs e)
{
VpmConfig.Instance.InstallationCancelled = false;
+ VpmConfig.Instance.WaitSignal = false;
+ VpmConfig.Instance.AgreementsAgreed = true;
VpmConfig.Instance.AgreeWindow.Close();
- VpmConfig.Instance.WinApp.Shutdown();
}
private void UserAgree_OnInitialized(object sender, EventArgs e)
@@ -160,5 +161,13 @@ private void AgreeAndInstall_OnIsEnabledChanged(object sender, DependencyPropert
if ((bool)e.NewValue) AgreeAndInstall.Opacity = 1;
else AgreeAndInstall.Opacity = 0.5;
}
+
+ private void OnCancelled(object sender, EventArgs e)
+ {
+ VpmConfig.Instance.InstallationCancelled = true;
+ VpmConfig.Instance.WaitSignal = false;
+ VpmConfig.Instance.AgreementsAgreed = true;
+ VpmConfig.Instance.DirWindow.Close();
+ }
}
}
diff --git a/src/vpm/args.cs b/src/vpm/args.cs
index cb3966a..a559902 100644
--- a/src/vpm/args.cs
+++ b/src/vpm/args.cs
@@ -4,7 +4,9 @@
using System.IO;
using System.Reflection;
using System.Threading;
+using System.Windows;
using BrendanGrant.Helpers.FileAssociation;
+using MahApps.Metro.Controls;
using Microsoft.Win32;
using PowerArgs;
diff --git a/src/vpm/config.cs b/src/vpm/config.cs
index e319ea3..b99d66b 100644
--- a/src/vpm/config.cs
+++ b/src/vpm/config.cs
@@ -2,8 +2,11 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
+using System.Threading;
+using System.Threading.Tasks;
using System.Windows;
using System.Xml;
+using MahApps.Metro.Controls;
using NuGet;
using PowerArgs;
@@ -18,6 +21,8 @@ public class VpmConfig
public IPackageRepository DefaultNugetRepository => _defaultNugetRepository ??
(_defaultNugetRepository = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2"));
+ public VpmArgs Arguments { get; set; }
+
private string _vvvvarch;
public string VVVVArcitecture
{
@@ -84,6 +89,8 @@ public string VpmTempDir
}
private XmlDocument _openedpack;
+ public bool WaitSignal {get; set; }
+ public bool AgreementsAgreed { get; set; }
public XmlDocument OpenedPackXml
{
@@ -97,8 +104,37 @@ public XmlDocument OpenedPackXml
return _openedpack;
}
}
- public Application WinApp { get; set; }
+ public Application WinApp
+ {
+ get
+ {
+ if (_winApp == null)
+ {
+ VpmConfig.Instance.WaitSignal = true;
+ ApplicationTask = VpmUtils.StartSTATask(() =>
+ {
+ var winapp = _winApp = new Application();
+ winapp.ShutdownMode = ShutdownMode.OnExplicitShutdown;
+ winapp.Run();
+ return true;
+ });
+ while (_winApp == null)
+ {
+ Thread.Sleep(10);
+ }
+ }
+ return _winApp;
+ }
+ //set => _winApp = value;
+ }
+
+ private Application _winApp;
+ public Task ApplicationTask { get; set; }
+
public Window AgreeWindow { get; set; }
+
+ public Window DirWindow { get; set; }
+
public List _packlist = new List();
public List PackList => _packlist;
public bool InstallationCancelled = true;
diff --git a/src/vpm/packages.config b/src/vpm/packages.config
index e7bbdc0..2870414 100644
--- a/src/vpm/packages.config
+++ b/src/vpm/packages.config
@@ -14,6 +14,8 @@
+
+
diff --git a/src/vpm/utils.cs b/src/vpm/utils.cs
index 300788f..b2a7be8 100644
--- a/src/vpm/utils.cs
+++ b/src/vpm/utils.cs
@@ -10,6 +10,7 @@
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading;
+using System.Threading.Tasks;
using System.Xml;
using LibGit2Sharp;
using LibGit2Sharp.Handlers;
@@ -77,6 +78,32 @@ public VersionRelation(System.Version curr, System.Version existing)
public static class VpmUtils
{
+ public static Task StartSTATask(Func func)
+ {
+ var tcs = new TaskCompletionSource();
+ Thread thread = new Thread(() =>
+ {
+ try
+ {
+ tcs.SetResult(func());
+ }
+ catch (Exception e)
+ {
+ tcs.SetException(e);
+ }
+ });
+ thread.SetApartmentState(ApartmentState.STA);
+ thread.Start();
+ return tcs.Task;
+ }
+
+ public static void Wait()
+ {
+ while (VpmConfig.Instance.WaitSignal)
+ {
+ Thread.Sleep(10);
+ }
+ }
public static void ConsoleClearLine()
{
Console.SetCursorPosition(0, Math.Max(Console.CursorTop - 1, 0));
diff --git a/src/vpm/vpm.csproj b/src/vpm/vpm.csproj
index a4ebe6f..dedfb18 100644
--- a/src/vpm/vpm.csproj
+++ b/src/vpm/vpm.csproj
@@ -120,6 +120,15 @@
packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll
+
+ packages\Microsoft.WindowsAPICodePack-Core.1.1.0.0\lib\Microsoft.WindowsAPICodePack.dll
+
+
+ packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.Shell.dll
+
+
+ packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.ShellExtensions.dll
+
packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll
@@ -234,6 +243,9 @@
+
+ ChooseDir.xaml
+
True
@@ -280,6 +292,10 @@
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile