diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 6325177..e85c3de 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -10,6 +10,7 @@ using System.Drawing; using System.Security.Principal; using System.Threading; using System.Threading.Tasks; +using System.Globalization; namespace DS4Windows { @@ -226,8 +227,13 @@ namespace DS4Windows { protected static BackingStore m_Config = new BackingStore(); protected static Int32 m_IdleTimeout = 600000; - static string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName; + public static string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName; public static string appdatapath; + public static bool firstRun = false; + public static bool multisavespots = false; + public static bool oldappdatafail = false; + public static string appDataPpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Windows"; + public static string oldappdatapath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool"; public static bool runHotPlug = false; public const int XINPUT_UNPLUG_SETTLE_TIME = 250; // Inhibit races that occur with the asynchronous teardown of ScpVBus -> X360 driver instance. public static string[] tempprofilename = new string[5] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty }; @@ -324,6 +330,52 @@ namespace DS4Windows return result; } + public static void FindConfigLocation() + { + if (File.Exists(exepath + "\\Auto Profiles.xml") + && File.Exists(appDataPpath + "\\Auto Profiles.xml")) + { + Global.firstRun = true; + Global.multisavespots = true; + } + else if (File.Exists(exepath + "\\Auto Profiles.xml")) + SaveWhere(exepath); + else if (File.Exists(appDataPpath + "\\Auto Profiles.xml")) + SaveWhere(appDataPpath); + else if (File.Exists(oldappdatapath + "\\Auto Profiles.xml")) + { + try + { + if (Directory.Exists(appDataPpath)) + Directory.Move(appDataPpath, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Windows Old"); + Directory.Move(oldappdatapath, appDataPpath); + SaveWhere(appDataPpath); + } + catch + { + Global.oldappdatafail = true; + } + } + else if (!File.Exists(exepath + "\\Auto Profiles.xml") + && !File.Exists(appDataPpath + "\\Auto Profiles.xml")) + { + Global.firstRun = true; + Global.multisavespots = false; + } + } + + public static void SetCulture(string culture) + { + try + { + Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(culture); + CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo(culture); + } + catch { /* Skip setting culture that we cannot set */ } + } + + + public static event EventHandler ControllerStatusChange; // called when a controller is added/removed/battery or touchpad mode changes/etc. public static void ControllerStatusChanged(object sender) { diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index 6bcd9af..47994ab 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -10,7 +10,6 @@ using Microsoft.Win32; using System.Diagnostics; using System.Xml; using System.Text; -using System.Globalization; using Microsoft.Win32.TaskScheduler; using System.Security.Principal; using System.Threading; @@ -38,9 +37,6 @@ namespace DS4Windows WebClient wc = new WebClient(); NonFormTimer hotkeysTimer = new NonFormTimer(); NonFormTimer autoProfilesTimer = new NonFormTimer(); - string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName; - string appDataPpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Windows"; - string oldappdatapath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool"; string tempProfileProgram = string.Empty; double dpix, dpiy; List profilenames = new List(); @@ -87,44 +83,22 @@ namespace DS4Windows public DS4Form(string[] args) { - bool firstrun = false; + Global.FindConfigLocation(); - if (File.Exists(exepath + "\\Auto Profiles.xml") - && File.Exists(appDataPpath + "\\Auto Profiles.xml")) + if (Global.firstRun) { - firstrun = true; - new SaveWhere(true).ShowDialog(); + new SaveWhere(Global.multisavespots).ShowDialog(); } - else if (File.Exists(exepath + "\\Auto Profiles.xml")) - SaveWhere(exepath); - else if (File.Exists(appDataPpath + "\\Auto Profiles.xml")) - SaveWhere(appDataPpath); - else if (File.Exists(oldappdatapath + "\\Auto Profiles.xml")) + else if (Global.oldappdatafail) { - try - { - if (Directory.Exists(appDataPpath)) - Directory.Move(appDataPpath, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Windows Old"); - Directory.Move(oldappdatapath, appDataPpath); - SaveWhere(appDataPpath); - } - catch - { - MessageBox.Show(Properties.Resources.CannotMoveFiles, "DS4Windows"); - Process.Start("explorer.exe", @"/select, " + appDataPpath); - Close(); - return; - } - } - else if (!File.Exists(exepath + "\\Auto Profiles.xml") - && !File.Exists(appDataPpath + "\\Auto Profiles.xml")) - { - firstrun = true; - new SaveWhere(false).ShowDialog(); + MessageBox.Show(Properties.Resources.CannotMoveFiles, "DS4Windows"); + Process.Start("explorer.exe", @"/select, " + appDataPpath); + Close(); + return; } Global.Load(); - this.setCulture(UseLang); + Global.SetCulture(UseLang); InitializeComponent(); ThemeUtil.SetTheme(lvDebug); @@ -434,16 +408,6 @@ namespace DS4Windows } } - private void setCulture(string culture) - { - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(culture); - CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo(culture); - } - catch { /* Skip setting culture that we cannot set */ } - } - private void populateHoverTextDict() { hoverTextDict.Clear(); diff --git a/DS4Windows/DS4Forms/WelcomeDialog.cs b/DS4Windows/DS4Forms/WelcomeDialog.cs index 3b8b345..d2871ac 100644 --- a/DS4Windows/DS4Forms/WelcomeDialog.cs +++ b/DS4Windows/DS4Forms/WelcomeDialog.cs @@ -1,30 +1,29 @@ using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; using System.Net; using System.IO; using System.IO.Compression; using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security.Principal; -using System.Security.Permissions; -using System.Reflection; +using NonFormTimer = System.Threading.Timer; +using System.Threading.Tasks; +using static DS4Windows.Global; namespace DS4Windows { public partial class WelcomeDialog : Form { - public WelcomeDialog() + public WelcomeDialog(bool loadConfig=false) { InitializeComponent(); Icon = Properties.Resources.DS4; - + if (loadConfig) + { + Global.FindConfigLocation(); + Global.Load(); + Global.SetCulture(Global.UseLang); + } } private void bnFinish_Click(object sender, EventArgs e) @@ -54,7 +53,6 @@ namespace DS4Windows bnStep1.Text = Properties.Resources.Downloading.Replace("*number*", e.ProgressPercentage.ToString()); } - string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName; private void wb_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { bnStep1.Text = Properties.Resources.OpeningInstaller; diff --git a/DS4Windows/Program.cs b/DS4Windows/Program.cs index 8436793..37557a0 100644 --- a/DS4Windows/Program.cs +++ b/DS4Windows/Program.cs @@ -39,7 +39,7 @@ namespace DS4Windows { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new WelcomeDialog()); + Application.Run(new WelcomeDialog(true)); return; } else if (s == "re-enabledevice" || s == "-re-enabledevice")