From 6e6c627556b9724ec2fa4e923ca96afa2e14d4b7 Mon Sep 17 00:00:00 2001 From: jays2kings Date: Thu, 12 Jun 2014 14:46:00 -0400 Subject: [PATCH] Version 10.3 First time runs of DS4Windows ask where you want to save settings, Will automatically pick the settings location based one the two location profiles.xml is in (App folder or Appdata). If settings are in both, it will ask you to pick where you want to save, and attempt to delete the other settings. If settings are in the app folder and needs UAC to write, There is an option to copy over the files to appdata. Disable touchpad mouse movement again by holding PS and touching the touchpad (instead of clicking) Version 10.26 FIx for crash when DS4Windows and DS4Updater is in Program files on a drive that is not C Version 10.25 Fix for Buttons inputting DS4Updater: Fix for reading version --- DS4Control/Control.cs | 4 +- DS4Control/Mapping.cs | 10 +- DS4Control/ScpUtil.cs | 44 +++++++-- DS4Tool/DS4Tool.csproj | 9 ++ DS4Tool/Hotkeys.Designer.cs | 4 +- DS4Tool/SaveWhere.Designer.cs | 150 ++++++++++++++++++++++++++++++ DS4Tool/SaveWhere.cs | 101 ++++++++++++++++++++ DS4Tool/SaveWhere.resx | 120 ++++++++++++++++++++++++ DS4Tool/ScpForm.Designer.cs | 66 ++++++------- DS4Tool/ScpForm.cs | 128 +++++++++++++++---------- DS4Tool/ScpForm.resx | 6 -- DS4Tool/WelcomeDialog.Designer.cs | 6 +- DS4Tool/WelcomeDialog.cs | 5 +- DS4Tool/WinProgs.cs | 4 - 14 files changed, 539 insertions(+), 118 deletions(-) create mode 100644 DS4Tool/SaveWhere.Designer.cs create mode 100644 DS4Tool/SaveWhere.cs create mode 100644 DS4Tool/SaveWhere.resx diff --git a/DS4Control/Control.cs b/DS4Control/Control.cs index adb194e..1140f3c 100644 --- a/DS4Control/Control.cs +++ b/DS4Control/Control.cs @@ -412,7 +412,7 @@ namespace DS4Control DS4LightBar.updateLightBar(device, ind); //DS4LightBar.defualtLight(device, ind); - x360Bus.Parse(MappedState[ind], processingData[ind].Report, ind); + x360Bus.Parse(cState, processingData[ind].Report, ind); // We push the translated Xinput state, and simultaneously we // pull back any possible rumble data coming from Xinput consumers. if (x360Bus.Report(processingData[ind].Report, processingData[ind].Rumble)) @@ -490,7 +490,7 @@ namespace DS4Control } } } - if (cState.TouchButton && pState.PS) + if (cState.Touch1 && pState.PS) { if (Global.getTouchSensitivity(deviceID) > 0 && touchreleased[deviceID]) { diff --git a/DS4Control/Mapping.cs b/DS4Control/Mapping.cs index 3f60a55..6a2c6e7 100644 --- a/DS4Control/Mapping.cs +++ b/DS4Control/Mapping.cs @@ -766,19 +766,11 @@ namespace DS4Control break; case X360Controls.LT: if (MappedState.L2 == 0) - { MappedState.L2 = getByteMapping(customButton.Key, cState); - L2 = true; - } break; case X360Controls.RT: - if (MappedState.L2 == 0 && MappedState.R2 == 0) - { + if (MappedState.R2 == 0) MappedState.R2 = getByteMapping(customButton.Key, cState); - //if (MappedState.R2 == 255) - //MessageBox.Show("225"); - R2 = true; - } break; case X360Controls.LeftMouse: if (getBoolMapping(customButton.Key, cState)) diff --git a/DS4Control/ScpUtil.cs b/DS4Control/ScpUtil.cs index 224d4ad..ef9e387 100644 --- a/DS4Control/ScpUtil.cs +++ b/DS4Control/ScpUtil.cs @@ -7,6 +7,7 @@ using System.Reflection; using System.Xml; using System.Drawing; using DS4Library; +using System.Security.Principal; namespace DS4Control { [Flags] @@ -84,14 +85,36 @@ namespace DS4Control static string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName; public static string appdatapath; - public static void SaveWhere() + public static void SaveWhere(string path) { - if (!exepath.StartsWith("C:\\Program Files") && !exepath.StartsWith("C:\\Windows")) - appdatapath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName; - else - appdatapath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool"; + appdatapath = path; m_Config.m_Profile = appdatapath + "\\Profiles.xml"; } + /// + /// Check if Admin Rights are needed to write in Appliplation Directory + /// + /// + public static bool AdminNeeded() + { + try + { + File.WriteAllText("test.txt", "test"); + File.Delete("test.txt"); + return false; + } + catch (UnauthorizedAccessException) + { + return true; + } + } + + public static bool IsAdministrator() + { + var identity = WindowsIdentity.GetCurrent(); + var principal = new WindowsPrincipal(identity); + return principal.IsInRole(WindowsBuiltInRole.Administrator); + } + public static event EventHandler ControllerStatusChange; // called when a controller is added/removed/battery or touchpad mode changes/etc. public static void ControllerStatusChanged(object sender) { @@ -450,9 +473,9 @@ namespace DS4Control { m_Config.LoadProfile(device, appdatapath + @"\Profiles\" + name + ".xml"); } - public static void Save() + public static bool Save() { - m_Config.Save(); + return m_Config.Save(); } public static void SaveProfile(int device, string propath, System.Windows.Forms.Control[] buttons) @@ -1219,7 +1242,7 @@ namespace DS4Control { Boolean Saved = true; - try + //try { XmlNode Node; @@ -1253,9 +1276,10 @@ namespace DS4Control XmlNode xmlNotifications = m_Xdoc.CreateNode(XmlNodeType.Element, "Notifications", null); xmlNotifications.InnerText = notifications.ToString(); Node.AppendChild(xmlNotifications); m_Xdoc.AppendChild(Node); - m_Xdoc.Save(m_Profile); + try { m_Xdoc.Save(m_Profile); } + catch (UnauthorizedAccessException) { Saved = false; } } - catch { Saved = false; } + //catch { Saved = false; } return Saved; } diff --git a/DS4Tool/DS4Tool.csproj b/DS4Tool/DS4Tool.csproj index 827e7b0..83d46d2 100644 --- a/DS4Tool/DS4Tool.csproj +++ b/DS4Tool/DS4Tool.csproj @@ -132,6 +132,12 @@ True Resource.es.resx + + Form + + + SaveWhere.cs + Form @@ -175,6 +181,9 @@ ResXFileCodeGenerator Resource.es.Designer.cs + + SaveWhere.cs + ScpForm.cs diff --git a/DS4Tool/Hotkeys.Designer.cs b/DS4Tool/Hotkeys.Designer.cs index 949526b..d57e1e8 100644 --- a/DS4Tool/Hotkeys.Designer.cs +++ b/DS4Tool/Hotkeys.Designer.cs @@ -377,9 +377,9 @@ this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(3, 127); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(108, 13); + this.label1.Size = new System.Drawing.Size(116, 13); this.label1.TabIndex = 0; - this.label1.Text = "Click Touchpad + PS"; + this.label1.Text = "Touch Touchpad + PS"; // // label22 // diff --git a/DS4Tool/SaveWhere.Designer.cs b/DS4Tool/SaveWhere.Designer.cs new file mode 100644 index 0000000..b52950e --- /dev/null +++ b/DS4Tool/SaveWhere.Designer.cs @@ -0,0 +1,150 @@ +namespace ScpServer +{ + partial class SaveWhere + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label4 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.bnAppdataFolder = new System.Windows.Forms.Button(); + this.bnPrgmFolder = new System.Windows.Forms.Button(); + this.lbPickWhere = new System.Windows.Forms.Label(); + this.lbMultiSaves = new System.Windows.Forms.Label(); + this.cBDeleteOther = new System.Windows.Forms.CheckBox(); + this.SuspendLayout(); + // + // label4 + // + this.label4.AutoSize = true; + this.label4.ForeColor = System.Drawing.SystemColors.GrayText; + this.label4.Location = new System.Drawing.Point(206, 83); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(177, 39); + this.label4.TabIndex = 9; + this.label4.Text = "For those who prefer a regular install\r\nSettings saved at \r\n%appdata%/ds4tool"; + this.label4.TextAlign = System.Drawing.ContentAlignment.TopCenter; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.ForeColor = System.Drawing.SystemColors.GrayText; + this.label3.Location = new System.Drawing.Point(5, 83); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(195, 39); + this.label3.TabIndex = 10; + this.label3.Text = "For those who prefer a portable program\r\nNote: this option does not\r\n work if in " + + "an admin folder w/o UAC"; + this.label3.TextAlign = System.Drawing.ContentAlignment.TopCenter; + // + // bnAppdataFolder + // + this.bnAppdataFolder.Location = new System.Drawing.Point(222, 57); + this.bnAppdataFolder.Name = "bnAppdataFolder"; + this.bnAppdataFolder.Size = new System.Drawing.Size(140, 23); + this.bnAppdataFolder.TabIndex = 7; + this.bnAppdataFolder.Text = "Appdata"; + this.bnAppdataFolder.UseVisualStyleBackColor = true; + this.bnAppdataFolder.Click += new System.EventHandler(this.bnAppdataFolder_Click); + // + // bnPrgmFolder + // + this.bnPrgmFolder.Location = new System.Drawing.Point(32, 57); + this.bnPrgmFolder.Name = "bnPrgmFolder"; + this.bnPrgmFolder.Size = new System.Drawing.Size(140, 23); + this.bnPrgmFolder.TabIndex = 8; + this.bnPrgmFolder.Text = "Program Folder"; + this.bnPrgmFolder.UseVisualStyleBackColor = true; + this.bnPrgmFolder.Click += new System.EventHandler(this.bnPrgmFolder_Click); + // + // lbPickWhere + // + this.lbPickWhere.ForeColor = System.Drawing.SystemColors.ControlText; + this.lbPickWhere.Location = new System.Drawing.Point(1, 27); + this.lbPickWhere.Name = "lbPickWhere"; + this.lbPickWhere.Size = new System.Drawing.Size(386, 27); + this.lbPickWhere.TabIndex = 10; + this.lbPickWhere.Text = "Pick where you want settings and profiles to be saved"; + this.lbPickWhere.TextAlign = System.Drawing.ContentAlignment.TopCenter; + // + // lbMultiSaves + // + this.lbMultiSaves.AutoSize = true; + this.lbMultiSaves.ForeColor = System.Drawing.SystemColors.ControlText; + this.lbMultiSaves.Location = new System.Drawing.Point(9, 8); + this.lbMultiSaves.Name = "lbMultiSaves"; + this.lbMultiSaves.Size = new System.Drawing.Size(159, 13); + this.lbMultiSaves.TabIndex = 10; + this.lbMultiSaves.Text = "Multiple save locations detected\r\n"; + this.lbMultiSaves.TextAlign = System.Drawing.ContentAlignment.TopCenter; + this.lbMultiSaves.Visible = false; + // + // cBDeleteOther + // + this.cBDeleteOther.AutoSize = true; + this.cBDeleteOther.Location = new System.Drawing.Point(201, 7); + this.cBDeleteOther.Name = "cBDeleteOther"; + this.cBDeleteOther.Size = new System.Drawing.Size(186, 17); + this.cBDeleteOther.TabIndex = 11; + this.cBDeleteOther.Text = "Don\'t Delete the other settings yet"; + this.cBDeleteOther.UseVisualStyleBackColor = true; + this.cBDeleteOther.Visible = false; + // + // SaveWhere + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.SystemColors.ControlLightLight; + this.ClientSize = new System.Drawing.Size(389, 128); + this.Controls.Add(this.cBDeleteOther); + this.Controls.Add(this.label4); + this.Controls.Add(this.lbMultiSaves); + this.Controls.Add(this.lbPickWhere); + this.Controls.Add(this.label3); + this.Controls.Add(this.bnAppdataFolder); + this.Controls.Add(this.bnPrgmFolder); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "SaveWhere"; + this.Text = "DS4Windows"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SaveWhere_FormClosing); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button bnAppdataFolder; + private System.Windows.Forms.Button bnPrgmFolder; + private System.Windows.Forms.Label lbPickWhere; + private System.Windows.Forms.Label lbMultiSaves; + private System.Windows.Forms.CheckBox cBDeleteOther; + } +} \ No newline at end of file diff --git a/DS4Tool/SaveWhere.cs b/DS4Tool/SaveWhere.cs new file mode 100644 index 0000000..517731b --- /dev/null +++ b/DS4Tool/SaveWhere.cs @@ -0,0 +1,101 @@ +using DS4Control; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml; + +namespace ScpServer +{ + public partial class SaveWhere : Form + { + private bool multisaves; + public SaveWhere(bool multisavespots) + { + InitializeComponent(); + Icon = Properties.Resources.DS4; + multisaves = multisavespots; + lbMultiSaves.Visible = multisaves; + cBDeleteOther.Visible = multisaves; + if (multisaves) + lbPickWhere.Text += ", other location files will be deleted"; + if (Global.AdminNeeded()) + bnPrgmFolder.Enabled = false; + } + + private void bnPrgmFolder_Click(object sender, EventArgs e) + { + Global.SaveWhere(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName); + if (multisaves && !cBDeleteOther.Checked) + { + try { Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool", true); } + catch { } + } + else if (!multisaves) + Save(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + "Profiles.xml"); + Close(); + } + + private void bnAppdataFolder_Click(object sender, EventArgs e) + { + + if (multisaves && !cBDeleteOther.Checked) + try + { + Directory.Delete("Profiles", true); + File.Delete("Profiles.xml"); + File.Delete("Auto Profiles.xml"); + } + catch (UnauthorizedAccessException) { MessageBox.Show("Cannot Delete old settings, please manaully delete", "DS4Windows"); } + else if (!multisaves) + Save(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool\\Profiles.xml"); + Global.SaveWhere(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool"); + Close(); + } + + public bool Save(String path) + { + Boolean Saved = true; + XmlDocument m_Xdoc = new XmlDocument(); + try + { + XmlNode Node; + + m_Xdoc.RemoveAll(); + + Node = m_Xdoc.CreateXmlDeclaration("1.0", "utf-8", String.Empty); + m_Xdoc.AppendChild(Node); + + Node = m_Xdoc.CreateComment(String.Format(" Profile Configuration Data. {0} ", DateTime.Now)); + m_Xdoc.AppendChild(Node); + + Node = m_Xdoc.CreateWhitespace("\r\n"); + m_Xdoc.AppendChild(Node); + + Node = m_Xdoc.CreateNode(XmlNodeType.Element, "Profile", null); + + m_Xdoc.AppendChild(Node); + + m_Xdoc.Save(path); + } + catch { Saved = false; } + + return Saved; + } + + private void SaveWhere_FormClosing(object sender, FormClosingEventArgs e) + { + if (String.IsNullOrEmpty(Global.appdatapath)) + if (MessageBox.Show("Close DS4Windows?\nA location must be picked to continue", "DS4Windows", + MessageBoxButtons.YesNo) == DialogResult.No) + e.Cancel = true; + } + } +} diff --git a/DS4Tool/SaveWhere.resx b/DS4Tool/SaveWhere.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/DS4Tool/SaveWhere.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DS4Tool/ScpForm.Designer.cs b/DS4Tool/ScpForm.Designer.cs index aee0b61..c0873b7 100644 --- a/DS4Tool/ScpForm.Designer.cs +++ b/DS4Tool/ScpForm.Designer.cs @@ -121,8 +121,8 @@ this.lLBUpdate = new System.Windows.Forms.LinkLabel(); this.linkUninstall = new System.Windows.Forms.LinkLabel(); this.lLSetup = new System.Windows.Forms.LinkLabel(); - this.saveProfiles = new System.Windows.Forms.SaveFileDialog(); this.lLAppDataDelete = new System.Windows.Forms.LinkLabel(); + this.saveProfiles = new System.Windows.Forms.SaveFileDialog(); this.pnlButton.SuspendLayout(); this.cMTaskbar.SuspendLayout(); this.tabMain.SuspendLayout(); @@ -410,7 +410,7 @@ this.tLPControllers.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 23.34039F)); this.tLPControllers.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25.31077F)); this.tLPControllers.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 117F)); - this.tLPControllers.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 50F)); + this.tLPControllers.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 45F)); this.tLPControllers.Controls.Add(this.pBStatus1, 1, 1); this.tLPControllers.Controls.Add(this.lbPad1, 0, 1); this.tLPControllers.Controls.Add(this.lbPad2, 0, 2); @@ -452,7 +452,7 @@ this.pBStatus1.Anchor = System.Windows.Forms.AnchorStyles.None; this.pBStatus1.Image = ((System.Drawing.Image)(resources.GetObject("pBStatus1.Image"))); this.pBStatus1.InitialImage = global::ScpServer.Properties.Resources.BT; - this.pBStatus1.Location = new System.Drawing.Point(369, 19); + this.pBStatus1.Location = new System.Drawing.Point(373, 19); this.pBStatus1.Name = "pBStatus1"; this.pBStatus1.Size = new System.Drawing.Size(39, 20); this.pBStatus1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; @@ -466,9 +466,9 @@ this.lbPad1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbPad1.Location = new System.Drawing.Point(3, 22); this.lbPad1.Name = "lbPad1"; - this.lbPad1.Size = new System.Drawing.Size(123, 15); + this.lbPad1.Size = new System.Drawing.Size(70, 15); this.lbPad1.TabIndex = 44; - this.lbPad1.Text = "Pad 1 : Disconnected"; + this.lbPad1.Text = "Controller 1"; // // lbPad2 // @@ -477,14 +477,14 @@ this.lbPad2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbPad2.Location = new System.Drawing.Point(3, 51); this.lbPad2.Name = "lbPad2"; - this.lbPad2.Size = new System.Drawing.Size(123, 15); + this.lbPad2.Size = new System.Drawing.Size(70, 15); this.lbPad2.TabIndex = 44; - this.lbPad2.Text = "Pad 2 : Disconnected"; + this.lbPad2.Text = "Controller 2"; // // bnEditC3 // this.bnEditC3.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.bnEditC3.Location = new System.Drawing.Point(737, 76); + this.bnEditC3.Location = new System.Drawing.Point(742, 76); this.bnEditC3.Name = "bnEditC3"; this.bnEditC3.Size = new System.Drawing.Size(40, 23); this.bnEditC3.TabIndex = 43; @@ -496,7 +496,7 @@ // bnEditC4 // this.bnEditC4.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.bnEditC4.Location = new System.Drawing.Point(737, 105); + this.bnEditC4.Location = new System.Drawing.Point(742, 105); this.bnEditC4.Name = "bnEditC4"; this.bnEditC4.Size = new System.Drawing.Size(40, 23); this.bnEditC4.TabIndex = 43; @@ -512,9 +512,9 @@ this.lbPad3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbPad3.Location = new System.Drawing.Point(3, 80); this.lbPad3.Name = "lbPad3"; - this.lbPad3.Size = new System.Drawing.Size(123, 15); + this.lbPad3.Size = new System.Drawing.Size(70, 15); this.lbPad3.TabIndex = 44; - this.lbPad3.Text = "Pad 3 : Disconnected"; + this.lbPad3.Text = "Controller 3"; // // lbPad4 // @@ -523,16 +523,16 @@ this.lbPad4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbPad4.Location = new System.Drawing.Point(3, 109); this.lbPad4.Name = "lbPad4"; - this.lbPad4.Size = new System.Drawing.Size(123, 15); + this.lbPad4.Size = new System.Drawing.Size(70, 15); this.lbPad4.TabIndex = 44; - this.lbPad4.Text = "Pad 4 : Disconnected"; + this.lbPad4.Text = "Controller 4"; // // cBController1 // this.cBController1.Anchor = System.Windows.Forms.AnchorStyles.Left; this.cBController1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cBController1.FormattingEnabled = true; - this.cBController1.Location = new System.Drawing.Point(620, 19); + this.cBController1.Location = new System.Drawing.Point(625, 19); this.cBController1.Name = "cBController1"; this.cBController1.Size = new System.Drawing.Size(111, 21); this.cBController1.TabIndex = 42; @@ -542,7 +542,7 @@ // bnEditC2 // this.bnEditC2.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.bnEditC2.Location = new System.Drawing.Point(737, 47); + this.bnEditC2.Location = new System.Drawing.Point(742, 47); this.bnEditC2.Name = "bnEditC2"; this.bnEditC2.Size = new System.Drawing.Size(40, 23); this.bnEditC2.TabIndex = 43; @@ -556,7 +556,7 @@ this.cBController2.Anchor = System.Windows.Forms.AnchorStyles.Left; this.cBController2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cBController2.FormattingEnabled = true; - this.cBController2.Location = new System.Drawing.Point(620, 48); + this.cBController2.Location = new System.Drawing.Point(625, 48); this.cBController2.Name = "cBController2"; this.cBController2.Size = new System.Drawing.Size(111, 21); this.cBController2.TabIndex = 42; @@ -568,7 +568,7 @@ this.cBController3.Anchor = System.Windows.Forms.AnchorStyles.Left; this.cBController3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cBController3.FormattingEnabled = true; - this.cBController3.Location = new System.Drawing.Point(620, 77); + this.cBController3.Location = new System.Drawing.Point(625, 77); this.cBController3.Name = "cBController3"; this.cBController3.Size = new System.Drawing.Size(111, 21); this.cBController3.TabIndex = 42; @@ -578,7 +578,7 @@ // bnEditC1 // this.bnEditC1.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.bnEditC1.Location = new System.Drawing.Point(737, 18); + this.bnEditC1.Location = new System.Drawing.Point(742, 18); this.bnEditC1.Name = "bnEditC1"; this.bnEditC1.Size = new System.Drawing.Size(40, 23); this.bnEditC1.TabIndex = 43; @@ -592,7 +592,7 @@ this.cBController4.Anchor = System.Windows.Forms.AnchorStyles.Left; this.cBController4.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cBController4.FormattingEnabled = true; - this.cBController4.Location = new System.Drawing.Point(620, 106); + this.cBController4.Location = new System.Drawing.Point(625, 106); this.cBController4.Name = "cBController4"; this.cBController4.Size = new System.Drawing.Size(111, 21); this.cBController4.TabIndex = 42; @@ -604,7 +604,7 @@ this.lBSelectedProfile.Anchor = System.Windows.Forms.AnchorStyles.None; this.lBSelectedProfile.AutoSize = true; this.lBSelectedProfile.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lBSelectedProfile.Location = new System.Drawing.Point(621, 0); + this.lBSelectedProfile.Location = new System.Drawing.Point(626, 0); this.lBSelectedProfile.Name = "lBSelectedProfile"; this.lBSelectedProfile.Size = new System.Drawing.Size(109, 15); this.lBSelectedProfile.TabIndex = 45; @@ -626,7 +626,7 @@ this.lBStatus.Anchor = System.Windows.Forms.AnchorStyles.None; this.lBStatus.AutoSize = true; this.lBStatus.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lBStatus.Location = new System.Drawing.Point(365, 0); + this.lBStatus.Location = new System.Drawing.Point(369, 0); this.lBStatus.Name = "lBStatus"; this.lBStatus.Size = new System.Drawing.Size(47, 15); this.lBStatus.TabIndex = 45; @@ -637,7 +637,7 @@ this.lBBattery.Anchor = System.Windows.Forms.AnchorStyles.None; this.lBBattery.AutoSize = true; this.lBBattery.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lBBattery.Location = new System.Drawing.Point(513, 0); + this.lBBattery.Location = new System.Drawing.Point(518, 0); this.lBBattery.Name = "lBBattery"; this.lBBattery.Size = new System.Drawing.Size(51, 15); this.lBBattery.TabIndex = 45; @@ -648,7 +648,7 @@ this.lBBatt1.Anchor = System.Windows.Forms.AnchorStyles.None; this.lBBatt1.AutoSize = true; this.lBBatt1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lBBatt1.Location = new System.Drawing.Point(519, 22); + this.lBBatt1.Location = new System.Drawing.Point(524, 22); this.lBBatt1.Name = "lBBatt1"; this.lBBatt1.Size = new System.Drawing.Size(39, 15); this.lBBatt1.TabIndex = 44; @@ -659,7 +659,7 @@ this.lBBatt2.Anchor = System.Windows.Forms.AnchorStyles.None; this.lBBatt2.AutoSize = true; this.lBBatt2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lBBatt2.Location = new System.Drawing.Point(519, 51); + this.lBBatt2.Location = new System.Drawing.Point(524, 51); this.lBBatt2.Name = "lBBatt2"; this.lBBatt2.Size = new System.Drawing.Size(39, 15); this.lBBatt2.TabIndex = 44; @@ -670,7 +670,7 @@ this.lBBatt3.Anchor = System.Windows.Forms.AnchorStyles.None; this.lBBatt3.AutoSize = true; this.lBBatt3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lBBatt3.Location = new System.Drawing.Point(519, 80); + this.lBBatt3.Location = new System.Drawing.Point(524, 80); this.lBBatt3.Name = "lBBatt3"; this.lBBatt3.Size = new System.Drawing.Size(39, 15); this.lBBatt3.TabIndex = 44; @@ -681,7 +681,7 @@ this.lBBatt4.Anchor = System.Windows.Forms.AnchorStyles.None; this.lBBatt4.AutoSize = true; this.lBBatt4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lBBatt4.Location = new System.Drawing.Point(519, 109); + this.lBBatt4.Location = new System.Drawing.Point(524, 109); this.lBBatt4.Name = "lBBatt4"; this.lBBatt4.Size = new System.Drawing.Size(39, 15); this.lBBatt4.TabIndex = 44; @@ -692,7 +692,7 @@ this.pBStatus2.Anchor = System.Windows.Forms.AnchorStyles.None; this.pBStatus2.Image = ((System.Drawing.Image)(resources.GetObject("pBStatus2.Image"))); this.pBStatus2.InitialImage = global::ScpServer.Properties.Resources.BT; - this.pBStatus2.Location = new System.Drawing.Point(369, 48); + this.pBStatus2.Location = new System.Drawing.Point(373, 48); this.pBStatus2.Name = "pBStatus2"; this.pBStatus2.Size = new System.Drawing.Size(39, 20); this.pBStatus2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; @@ -704,7 +704,7 @@ this.pBStatus3.Anchor = System.Windows.Forms.AnchorStyles.None; this.pBStatus3.Image = ((System.Drawing.Image)(resources.GetObject("pBStatus3.Image"))); this.pBStatus3.InitialImage = global::ScpServer.Properties.Resources.BT; - this.pBStatus3.Location = new System.Drawing.Point(369, 77); + this.pBStatus3.Location = new System.Drawing.Point(373, 77); this.pBStatus3.Name = "pBStatus3"; this.pBStatus3.Size = new System.Drawing.Size(39, 20); this.pBStatus3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; @@ -716,7 +716,7 @@ this.pBStatus4.Anchor = System.Windows.Forms.AnchorStyles.None; this.pBStatus4.Image = ((System.Drawing.Image)(resources.GetObject("pBStatus4.Image"))); this.pBStatus4.InitialImage = global::ScpServer.Properties.Resources.BT; - this.pBStatus4.Location = new System.Drawing.Point(369, 106); + this.pBStatus4.Location = new System.Drawing.Point(373, 106); this.pBStatus4.Name = "pBStatus4"; this.pBStatus4.Size = new System.Drawing.Size(39, 20); this.pBStatus4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; @@ -1144,10 +1144,6 @@ this.lLSetup.Text = "Controller Setup"; this.lLSetup.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lLSetup_LinkClicked); // - // saveProfiles - // - this.saveProfiles.Filter = "XML Files (*.xml)|*.xml"; - // // lLAppDataDelete // this.lLAppDataDelete.AutoSize = true; @@ -1160,6 +1156,10 @@ this.lLAppDataDelete.Visible = false; this.lLAppDataDelete.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lLAppDataDelete_LinkClicked); // + // saveProfiles + // + this.saveProfiles.Filter = "XML Files (*.xml)|*.xml"; + // // ScpForm // this.AllowDrop = true; diff --git a/DS4Tool/ScpForm.cs b/DS4Tool/ScpForm.cs index cc46607..caeaf15 100644 --- a/DS4Tool/ScpForm.cs +++ b/DS4Tool/ScpForm.cs @@ -17,7 +17,7 @@ namespace ScpServer { public partial class ScpForm : Form { - double version = 10.2; + double version = 10.3; private DS4Control.Control rootHub; delegate void LogDebugDelegate(DateTime Time, String Data); @@ -84,9 +84,10 @@ namespace ScpServer //CheckDrivers(); SystemEvents.PowerModeChanged += OnPowerChange; tSOptions.Visible = false; - LoadP(); + LoadP(); ToolTip tt = new ToolTip(); - tt.SetToolTip(linkUninstall, "To fully remove DS4Windows, You can delete the profiles by the link to the other side"); + if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool\\Profiles.xml")) + tt.SetToolTip(linkUninstall, "If removing DS4Windows, You can delete the settings following the profile folder link"); tt.SetToolTip(lLAppDataDelete, @"Delete Appdata\DS4Tool folder as it's no longer in use"); } @@ -124,18 +125,23 @@ namespace ScpServer protected void Form_Load(object sender, EventArgs e) { SetupArrays(); - if (!exepath.StartsWith("C:\\Program Files") && !exepath.StartsWith("C:\\Windows")) + if (!File.Exists("Profiles.xml") && !File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DS4Tool\Profiles.xml")) { - if (!File.Exists("Profiles.xml") && - File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DS4Tool\Profiles.xml")) - File.Copy(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DS4Tool\Profiles.xml", - "Profiles.xml", false); - if (!File.Exists("Auto Profiles.xml") && - File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DS4Tool\Auto Profiles.xml")) - File.Copy(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\DS4Tool\Auto Profiles.xml", - "Auto Profiles.xml", false); + new WelcomeDialog().ShowDialog(); + new SaveWhere(false).ShowDialog(); } + else if (File.Exists("Profiles.xml") && File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool\\Profiles.xml")) + new SaveWhere(true).ShowDialog(); + else if (File.Exists("Profiles.xml")) + Global.SaveWhere(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName); + else if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool\\Profiles.xml")) + Global.SaveWhere(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool"); + if (String.IsNullOrEmpty(Global.appdatapath)) + { + Close(); + return; + } Graphics g = this.CreateGraphics(); try { @@ -153,16 +159,43 @@ namespace ScpServer Log.GuiLog += On_Debug; Log.TrayIconLog += ShowNotification; // tmrUpdate.Enabled = true; TODO remove tmrUpdate and leave tick() - Global.SaveWhere(); - if (!File.Exists(Global.appdatapath + @"\Profiles.xml")) - { - WelcomeDialog wd = new WelcomeDialog(); - wd.ShowDialog(); - } + Directory.CreateDirectory(Global.appdatapath); Global.Load(); Global.setVersion(version); - Global.Save(); + if (!Global.Save()) //if can't write to file + if (MessageBox.Show("Cannot write at current locataion\nCopy Settings to appdata?", "DS4Windows", + MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes) + { + try + { + Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + + "\\DS4Tool"); + File.Copy("Profiles.xml", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + + "\\DS4Tool\\Profiles.xml"); + File.Copy("Auto Profiles.xml", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + + "\\DS4Tool\\Auto Profiles.xml"); + Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + + "\\DS4Tool\\Profiles"); + foreach (string s in Directory.GetFiles("Profiles")) + { + File.Copy(s, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + + "\\DS4Tool\\Profiles\\" + Path.GetFileName(s)); + } + } + catch { } + MessageBox.Show("Copy complete, please relaunch DS4Windows and remove settings from Program Directory", "DS4Windows"); + Global.appdatapath = null; + Close(); + return; + } + else + { + MessageBox.Show("DS4Windows cannot edit settings here, This will now close", "DS4Windows"); + Global.appdatapath = null; + Close(); + return; + } foreach (ToolStripMenuItem t in shortcuts) t.DropDownItemClicked += Profile_Changed_Menu; hideDS4CheckBox.CheckedChanged -= hideDS4CheckBox_CheckedChanged; @@ -179,15 +212,11 @@ namespace ScpServer RegistryKey KeyLoc = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", false); StartWindowsCheckBox.Checked = (KeyLoc.GetValue("DS4Tool") != null); if (startMinimizedCheckBox.Checked) - { this.WindowState = FormWindowState.Minimized; - //Form_Resize(sender, e); - } Form_Resize(sender, e); RefreshProfiles(); for (int i = 0; i < 4; i++) Global.LoadProfile(i); - Global.ControllerStatusChange += ControllerStatusChange; ControllerStatusChanged(); if (btnStartStop.Enabled) @@ -383,7 +412,7 @@ namespace ScpServer } Process p = new Process(); p.StartInfo.FileName = "DS4Updater.exe"; - if (!exepath.StartsWith("C:\\Program Files") && !exepath.StartsWith("C:\\Windows")) + if (!Global.AdminNeeded()) p.StartInfo.Verb = "runas"; p.Start(); this.Close(); @@ -1042,28 +1071,7 @@ namespace ScpServer e.Effect = DragDropEffects.None; // Unknown data, ignore it } - protected void Form_Close(object sender, FormClosingEventArgs e) - { - if (systemShutdown) - // Reset the variable because the user might cancel the - // shutdown. - { - systemShutdown = false; - DS4LightBar.shuttingdown = true; - } - if (oldsize == new System.Drawing.Size(0, 0)) - { - Global.setFormWidth(this.Width); - Global.setFormHeight(this.Height); - } - else - { - Global.setFormWidth(oldsize.Width); - Global.setFormHeight(oldsize.Height); - } - Global.Save(); - rootHub.Stop(); - } + private void tBProfile_TextChanged(object sender, EventArgs e) { @@ -1185,7 +1193,7 @@ namespace ScpServer } Process p = new Process(); p.StartInfo.FileName = "DS4Updater.exe"; - if (!exepath.StartsWith("C:\\Program Files") && !exepath.StartsWith("C:\\Windows")) + if (Global.AdminNeeded()) p.StartInfo.Verb = "runas"; p.Start(); Close(); @@ -1245,6 +1253,32 @@ namespace ScpServer lLAppDataDelete.Visible = false; } } + + protected void Form_Close(object sender, FormClosingEventArgs e) + { + if (systemShutdown) + // Reset the variable because the user might cancel the + // shutdown. + { + systemShutdown = false; + DS4LightBar.shuttingdown = true; + } + if (oldsize == new System.Drawing.Size(0, 0)) + { + Global.setFormWidth(this.Width); + Global.setFormHeight(this.Height); + } + else + { + Global.setFormWidth(oldsize.Width); + Global.setFormHeight(oldsize.Height); + } + if (!String.IsNullOrEmpty(Global.appdatapath)) + { + Global.Save(); + rootHub.Stop(); + } + } } public class ThemeUtil diff --git a/DS4Tool/ScpForm.resx b/DS4Tool/ScpForm.resx index d76d63b..e62a17a 100644 --- a/DS4Tool/ScpForm.resx +++ b/DS4Tool/ScpForm.resx @@ -6302,12 +6302,6 @@ 449, 17 - - 891, 17 - - - 568, 17 - iVBORw0KGgoAAAANSUhEUgAAACcAAAAUCAYAAAAOTSQ2AAAABGdBTUEAALGOfPtRkwAAACBjSFJNAACH diff --git a/DS4Tool/WelcomeDialog.Designer.cs b/DS4Tool/WelcomeDialog.Designer.cs index 558efae..0d1076a 100644 --- a/DS4Tool/WelcomeDialog.Designer.cs +++ b/DS4Tool/WelcomeDialog.Designer.cs @@ -99,7 +99,7 @@ this.labelBluetooth2.Size = new System.Drawing.Size(312, 64); this.labelBluetooth2.TabIndex = 3; this.labelBluetooth2.Text = "Once flashing go to your Bluetooth Settings\r\nand Connect to \"Wireless Controller\"" + - "\r\n\r\nOnce paired, you\'re good to go. Have fun!"; + "\r\n\r\nAfter paired, you\'re ready. Have fun!"; this.labelBluetooth2.TextAlign = System.Drawing.ContentAlignment.TopCenter; // // linkBluetoothSettings @@ -133,7 +133,7 @@ // // bnFinish // - this.bnFinish.Location = new System.Drawing.Point(123, 388); + this.bnFinish.Location = new System.Drawing.Point(117, 394); this.bnFinish.Name = "bnFinish"; this.bnFinish.Size = new System.Drawing.Size(75, 23); this.bnFinish.TabIndex = 0; @@ -146,7 +146,7 @@ this.AcceptButton = this.bnFinish; this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; - this.ClientSize = new System.Drawing.Size(315, 422); + this.ClientSize = new System.Drawing.Size(315, 421); this.Controls.Add(this.linkBluetoothSettings); this.Controls.Add(this.labelBluetooth); this.Controls.Add(this.pictureBox1); diff --git a/DS4Tool/WelcomeDialog.cs b/DS4Tool/WelcomeDialog.cs index e2ddd38..f38a9d6 100644 --- a/DS4Tool/WelcomeDialog.cs +++ b/DS4Tool/WelcomeDialog.cs @@ -24,6 +24,7 @@ namespace ScpServer { InitializeComponent(); this.Icon = Properties.Resources.DS4; + } private void bnFinish_Click(object sender, EventArgs e) @@ -55,7 +56,7 @@ namespace ScpServer string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName; private void wb_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { - if (!exepath.StartsWith("C:\\Program Files") && !exepath.StartsWith("C:\\Windows")) + if (!Global.AdminNeeded()) { bnStep1.Text = "Opening Installer"; try @@ -96,7 +97,7 @@ namespace ScpServer private void timer_Tick(object sender, EventArgs e) { Process[] processes = Process.GetProcessesByName("ScpDriver"); - if (!exepath.StartsWith("C:\\Program Files") && !exepath.StartsWith("C:\\Windows")) + if (!Global.AdminNeeded()) { if (processes.Length < 1) { diff --git a/DS4Tool/WinProgs.cs b/DS4Tool/WinProgs.cs index 99fdf70..d1cfdf1 100644 --- a/DS4Tool/WinProgs.cs +++ b/DS4Tool/WinProgs.cs @@ -46,10 +46,6 @@ namespace ScpServer Create(); LoadP(); - /*RegistryKey regKey = Registry.CurrentUser; - regKey = regKey.OpenSubKey(@"Software\Valve\Steam"); - - if (regKey != null)*/ if (Directory.Exists(@"C:\Program Files (x86)\Steam\steamapps\common")) steamgamesdir = @"C:\Program Files (x86)\Steam\steamapps\common"; else if (Directory.Exists(@"C:\Program Files\Steam\steamapps\common"))