diff --git a/src/vpm/UserAgree.xaml.cs b/src/vpm/UserAgree.xaml.cs index 56f726d..b89d1f2 100644 --- a/src/vpm/UserAgree.xaml.cs +++ b/src/vpm/UserAgree.xaml.cs @@ -24,12 +24,39 @@ namespace vpm /// public partial class UserAgree : Window { + public JsVPackInterop InteropObj; public ListBoxItem SelectedPack; + public bool PackChanged = false; public UserAgree() { InitializeComponent(); } + public void DisableAgree() + { + Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => + { + AgreeAndInstall.IsEnabled = false; + })); + } + public void EnableAgree() + { + Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => + { + AgreeAndInstall.IsEnabled = true; + })); + } + + public void ContinueFromJS() + { + Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => + { + AgreeAndInstall.IsEnabled = true; + AgreeAndInstall.IsChecked = true; + if (VPackList.SelectedIndex < VPackList.Items.Count - 1) + VPackList.SelectedIndex = (VPackList.SelectedIndex + 1) % VPackList.Items.Count; + })); + } private void ContinueInstall_Click(object sender, RoutedEventArgs e) { VpmConfig.Instance.InstallationCancelled = false; @@ -39,6 +66,12 @@ private void ContinueInstall_Click(object sender, RoutedEventArgs e) private void UserAgree_OnInitialized(object sender, EventArgs e) { + + InteropObj = new JsVPackInterop + { + UserAgreeWindow = this + }; + Browser.RegisterJsObject("vpm", InteropObj); foreach (var vpack in VpmConfig.Instance.PackList) { var item = new ListBoxItem @@ -51,7 +84,7 @@ private void UserAgree_OnInitialized(object sender, EventArgs e) }; VPackList.Items.Add(item); } - var delay = new Timer { Interval = 1500 }; + var delay = new Timer { Interval = 1000 }; delay.Elapsed += (o, ee) => { Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => @@ -66,7 +99,7 @@ private void UserAgree_OnInitialized(object sender, EventArgs e) private void VPackList_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if(e.AddedItems.Count <= 0) return; - + PackChanged = true; SelectedPack = (ListBoxItem)e.AddedItems[0]; var pack = (VPack)SelectedPack.Content; AgreeAndInstall.IsChecked = pack.Agreed; @@ -90,15 +123,17 @@ private void Browser_OnLoadingStateChanged(object sender, LoadingStateChangedEve { Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action( () => { + if (!PackChanged) return; if (e.IsLoading) { AgreeAndInstall.IsEnabled = false; - NextPack.IsEnabled = false; + InteropObj.CurrentPack = (VPack)SelectedPack.Content; } else { AgreeAndInstall.IsEnabled = true; NextPack.IsEnabled = true; + PackChanged = false; } })); } @@ -107,5 +142,12 @@ private void NextPack_OnClick(object sender, RoutedEventArgs e) { VPackList.SelectedIndex = (VPackList.SelectedIndex + 1) % VPackList.Items.Count; } + /* + private void AgreeAndInstall_OnIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) + { + if(AgreeAndInstall.IsEnabled) + Console.WriteLine("Agree Enabled"); + } + */ } } diff --git a/src/vpm/vpack.cs b/src/vpm/vpack.cs index 4a998b5..ef1dfe1 100644 --- a/src/vpm/vpack.cs +++ b/src/vpm/vpack.cs @@ -12,6 +12,43 @@ namespace vpm { + public class JsVPackInterop + { + public VPack CurrentPack; + public UserAgree UserAgreeWindow; + + public string GetPackXml() + { + return CurrentPack.RawXml; + } + + public void Continue(string data) + { + SetInstallData(data); + UserAgreeWindow.ContinueFromJS(); + } + public void SetInstallData(string data) + { + CurrentPack.InstallDataFromJS = data; + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine("Licensing page passed data for the installation script."); + Console.ResetColor(); + } + public void DisableAgree() + { + UserAgreeWindow.DisableAgree(); + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine("Licensing page Disabled the \"Agree\" checkbox."); + Console.ResetColor(); + } + public void EnableAgree() + { + UserAgreeWindow.EnableAgree(); + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine("Licensing page Enabled the \"Agree\" checkbox."); + Console.ResetColor(); + } + } public class VPack { public string Name; @@ -19,7 +56,9 @@ public class VPack public string Source; public string TempDir; public string LicenseUrl; + public string InstallDataFromJS; public string InstallScript; + public string RawXml; public bool Agreed = false; public List Aliases = new List(); public List Dependencies = new List(); @@ -58,6 +97,7 @@ public VPack(string name, string source, IEnumerable aliases = null, Xml } if (xmldoc != null) { + RawXml = xmldoc.ToString(); var licensenode = xmldoc.SelectSingleNode("/vpack/meta/license"); LicenseUrl = licensenode != null ? licensenode.InnerText.Trim() : "http://www.imxprs.com/free/microdee/vpmnolicense"; diff --git a/src/vpm/vpm.csproj b/src/vpm/vpm.csproj index b3fef46..013ef8d 100644 --- a/src/vpm/vpm.csproj +++ b/src/vpm/vpm.csproj @@ -225,7 +225,9 @@ - + + Always +