Code clean up

This commit is contained in:
Travis Nickles 2017-05-12 22:54:29 -07:00
parent 959966b15c
commit 7a1b382c5a
3 changed files with 1669 additions and 2292 deletions

View File

@ -33,7 +33,6 @@
this.lvDebug = new System.Windows.Forms.ListView(); this.lvDebug = new System.Windows.Forms.ListView();
this.chTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chData = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chData = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.tmrUpdate = new System.Windows.Forms.Timer(this.components);
this.pnlButton = new System.Windows.Forms.Panel(); this.pnlButton = new System.Windows.Forms.Panel();
this.llbHelp = new System.Windows.Forms.LinkLabel(); this.llbHelp = new System.Windows.Forms.LinkLabel();
this.lbTest = new System.Windows.Forms.Label(); this.lbTest = new System.Windows.Forms.Label();
@ -207,11 +206,6 @@
// //
resources.ApplyResources(this.chData, "chData"); resources.ApplyResources(this.chData, "chData");
// //
// tmrUpdate
//
this.tmrUpdate.Interval = 1;
this.tmrUpdate.Tick += new System.EventHandler(this.ControllerStatusChange);
//
// pnlButton // pnlButton
// //
this.pnlButton.BackColor = System.Drawing.SystemColors.Control; this.pnlButton.BackColor = System.Drawing.SystemColors.Control;
@ -442,7 +436,7 @@
// //
resources.ApplyResources(this.bnEditC3, "bnEditC3"); resources.ApplyResources(this.bnEditC3, "bnEditC3");
this.bnEditC3.Name = "bnEditC3"; this.bnEditC3.Name = "bnEditC3";
this.bnEditC3.Tag = "2"; this.bnEditC3.Tag = "";
this.bnEditC3.UseVisualStyleBackColor = true; this.bnEditC3.UseVisualStyleBackColor = true;
this.bnEditC3.Click += new System.EventHandler(this.editButtons_Click); this.bnEditC3.Click += new System.EventHandler(this.editButtons_Click);
// //
@ -450,7 +444,7 @@
// //
resources.ApplyResources(this.bnEditC4, "bnEditC4"); resources.ApplyResources(this.bnEditC4, "bnEditC4");
this.bnEditC4.Name = "bnEditC4"; this.bnEditC4.Name = "bnEditC4";
this.bnEditC4.Tag = "3"; this.bnEditC4.Tag = "";
this.bnEditC4.UseVisualStyleBackColor = true; this.bnEditC4.UseVisualStyleBackColor = true;
this.bnEditC4.Click += new System.EventHandler(this.editButtons_Click); this.bnEditC4.Click += new System.EventHandler(this.editButtons_Click);
// //
@ -483,7 +477,7 @@
// //
resources.ApplyResources(this.bnEditC2, "bnEditC2"); resources.ApplyResources(this.bnEditC2, "bnEditC2");
this.bnEditC2.Name = "bnEditC2"; this.bnEditC2.Name = "bnEditC2";
this.bnEditC2.Tag = "1"; this.bnEditC2.Tag = "";
this.bnEditC2.UseVisualStyleBackColor = true; this.bnEditC2.UseVisualStyleBackColor = true;
this.bnEditC2.Click += new System.EventHandler(this.editButtons_Click); this.bnEditC2.Click += new System.EventHandler(this.editButtons_Click);
// //
@ -509,7 +503,7 @@
// //
resources.ApplyResources(this.bnEditC1, "bnEditC1"); resources.ApplyResources(this.bnEditC1, "bnEditC1");
this.bnEditC1.Name = "bnEditC1"; this.bnEditC1.Name = "bnEditC1";
this.bnEditC1.Tag = "0"; this.bnEditC1.Tag = "";
this.bnEditC1.UseVisualStyleBackColor = true; this.bnEditC1.UseVisualStyleBackColor = true;
this.bnEditC1.Click += new System.EventHandler(this.editButtons_Click); this.bnEditC1.Click += new System.EventHandler(this.editButtons_Click);
// //
@ -1265,7 +1259,6 @@
private System.Windows.Forms.ListView lvDebug; private System.Windows.Forms.ListView lvDebug;
private System.Windows.Forms.ColumnHeader chTime; private System.Windows.Forms.ColumnHeader chTime;
private System.Windows.Forms.ColumnHeader chData; private System.Windows.Forms.ColumnHeader chData;
private System.Windows.Forms.Timer tmrUpdate;
private System.Windows.Forms.Panel pnlButton; private System.Windows.Forms.Panel pnlButton;
private System.Windows.Forms.Button btnStartStop; private System.Windows.Forms.Button btnStartStop;
private System.Windows.Forms.Button btnClear; private System.Windows.Forms.Button btnClear;

View File

@ -91,6 +91,11 @@ namespace DS4Windows
{ {
InitializeComponent(); InitializeComponent();
bnEditC1.Tag = 0;
bnEditC2.Tag = 1;
bnEditC3.Tag = 2;
bnEditC4.Tag = 3;
this.StartWindowsCheckBox.CheckedChanged -= this.StartWindowsCheckBox_CheckedChanged; this.StartWindowsCheckBox.CheckedChanged -= this.StartWindowsCheckBox_CheckedChanged;
saveProfiles.Filter = Properties.Resources.XMLFiles + "|*.xml"; saveProfiles.Filter = Properties.Resources.XMLFiles + "|*.xml";
@ -322,7 +327,7 @@ namespace DS4Windows
autoProfilesTimer.Interval = 1000; autoProfilesTimer.Interval = 1000;
LoadP(); LoadP();
Global.ControllerStatusChange += ControllerStatusChange; //Global.ControllerStatusChange += ControllerStatusChange;
Global.BatteryStatusChange += BatteryStatusUpdate; Global.BatteryStatusChange += BatteryStatusUpdate;
Global.ControllerRemoved += ControllerRemovedChange; Global.ControllerRemoved += ControllerRemovedChange;
Global.DeviceStatusChange += DeviceStatusChanged; Global.DeviceStatusChange += DeviceStatusChanged;
@ -420,10 +425,21 @@ namespace DS4Windows
UpdateTheUpdater(); UpdateTheUpdater();
this.StartWindowsCheckBox.CheckedChanged += new System.EventHandler(this.StartWindowsCheckBox_CheckedChanged); this.StartWindowsCheckBox.CheckedChanged += new EventHandler(this.StartWindowsCheckBox_CheckedChanged);
new ToolTip().SetToolTip(StartWindowsCheckBox, Properties.Resources.RunAtStartup); new ToolTip().SetToolTip(StartWindowsCheckBox, Properties.Resources.RunAtStartup);
populateHoverTextDict(); populateHoverTextDict();
foreach (Control control in fLPSettings.Controls)
{
if (control.HasChildren)
{
foreach (Control ctrl in control.Controls)
ctrl.MouseHover += Items_MouseHover;
}
control.MouseHover += Items_MouseHover;
}
} }
private void populateHoverTextDict() private void populateHoverTextDict()
@ -786,9 +802,11 @@ namespace DS4Windows
{ {
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
string version = fvi.FileVersion; string version = fvi.FileVersion;
string newversion = File.ReadAllText(appdatapath + "\\version.txt"); string newversion = File.ReadAllText(appdatapath + "\\version.txt").Trim();
if (version.Replace(',', '.').CompareTo(newversion) == -1)//CompareVersions(); if (version.Replace(',', '.').CompareTo(newversion) == -1)//CompareVersions();
if (MessageBox.Show(Properties.Resources.DownloadVersion.Replace("*number*", newversion), Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) {
if (MessageBox.Show(Properties.Resources.DownloadVersion.Replace("*number*", newversion),
Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
if (!File.Exists(exepath + "\\DS4Updater.exe") || (File.Exists(exepath + "\\DS4Updater.exe") if (!File.Exists(exepath + "\\DS4Updater.exe") || (File.Exists(exepath + "\\DS4Updater.exe")
&& (FileVersionInfo.GetVersionInfo(exepath + "\\DS4Updater.exe").FileVersion.CompareTo("1.1.0.0") == -1))) && (FileVersionInfo.GetVersionInfo(exepath + "\\DS4Updater.exe").FileVersion.CompareTo("1.1.0.0") == -1)))
@ -803,17 +821,20 @@ namespace DS4Windows
Process.Start("http://23.239.26.40/ds4windows/files/DS4Updater.exe"); Process.Start("http://23.239.26.40/ds4windows/files/DS4Updater.exe");
} }
} }
Process p = new Process(); Process p = new Process();
p.StartInfo.FileName = exepath + "\\DS4Updater.exe"; p.StartInfo.FileName = exepath + "\\DS4Updater.exe";
if (!cBDownloadLangauge.Checked) if (!cBDownloadLangauge.Checked)
p.StartInfo.Arguments = "-skipLang"; p.StartInfo.Arguments = "-skipLang";
if (AdminNeeded()) if (AdminNeeded())
p.StartInfo.Verb = "runas"; p.StartInfo.Verb = "runas";
try { p.Start(); Close(); } try { p.Start(); Close(); }
catch { } catch { }
} }
else else
File.Delete(appdatapath + "\\version.txt"); File.Delete(appdatapath + "\\version.txt");
}
else else
File.Delete(appdatapath + "\\version.txt"); File.Delete(appdatapath + "\\version.txt");
} }
@ -825,8 +846,11 @@ namespace DS4Windows
profilenames.Clear(); profilenames.Clear();
string[] profiles = Directory.GetFiles(appdatapath + @"\Profiles\"); string[] profiles = Directory.GetFiles(appdatapath + @"\Profiles\");
foreach (String s in profiles) foreach (String s in profiles)
{
if (s.EndsWith(".xml")) if (s.EndsWith(".xml"))
profilenames.Add(Path.GetFileNameWithoutExtension(s)); profilenames.Add(Path.GetFileNameWithoutExtension(s));
}
lBProfiles.Items.Clear(); lBProfiles.Items.Clear();
lBProfiles.Items.AddRange(profilenames.ToArray()); lBProfiles.Items.AddRange(profilenames.ToArray());
if (lBProfiles.Items.Count == 0) if (lBProfiles.Items.Count == 0)
@ -843,7 +867,9 @@ namespace DS4Windows
cbs[i].Items.AddRange(profilenames.ToArray()); cbs[i].Items.AddRange(profilenames.ToArray());
foreach (string s in profilenames) foreach (string s in profilenames)
shortcuts[i].DropDownItems.Add(s); shortcuts[i].DropDownItems.Add(s);
for (int j = 0; j < cbs[i].Items.Count; j++)
for (int j = 0, itemCount = cbs[i].Items.Count; j < itemCount; j++)
{
if (cbs[i].Items[j].ToString() == Path.GetFileNameWithoutExtension(ProfilePath[i])) if (cbs[i].Items[j].ToString() == Path.GetFileNameWithoutExtension(ProfilePath[i]))
{ {
cbs[i].SelectedIndex = j; cbs[i].SelectedIndex = j;
@ -859,6 +885,7 @@ namespace DS4Windows
shortcuts[i].Text = Properties.Resources.ContextNew.Replace("*number*", (i + 1).ToString()); shortcuts[i].Text = Properties.Resources.ContextNew.Replace("*number*", (i + 1).ToString());
ebns[i].Text = Properties.Resources.New; ebns[i].Text = Properties.Resources.New;
} }
}
} }
} }
catch (DirectoryNotFoundException) catch (DirectoryNotFoundException)
@ -890,7 +917,7 @@ namespace DS4Windows
tabAutoProfiles.Controls.Clear(); tabAutoProfiles.Controls.Clear();
WP = new WinProgs(profilenames.ToArray(), this); WP = new WinProgs(profilenames.ToArray(), this);
WP.TopLevel = false; WP.TopLevel = false;
WP.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; WP.FormBorderStyle = FormBorderStyle.None;
WP.Visible = true; WP.Visible = true;
WP.Dock = DockStyle.Fill; WP.Dock = DockStyle.Fill;
tabAutoProfiles.Controls.Add(WP); tabAutoProfiles.Controls.Add(WP);
@ -1205,15 +1232,16 @@ namespace DS4Windows
} }
} }
protected void ControllerStatusChange(object sender, EventArgs e) /*protected void ControllerStatusChange(object sender, EventArgs e)
{ {
if (InvokeRequired) if (InvokeRequired)
Invoke(new ControllerStatusChangedDelegate(ControllerStatusChange), new object[] { sender, e }); Invoke(new ControllerStatusChangedDelegate(ControllerStatusChange), new object[] { sender, e });
else else
ControllerStatusChanged(); ControllerStatusChanged();
} }
*/
protected void ControllerStatusChanged() /*protected void ControllerStatusChanged()
{ {
String tooltip = "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion; String tooltip = "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
bool nocontrollers = true; bool nocontrollers = true;
@ -1270,15 +1298,23 @@ namespace DS4Windows
else else
notifyIcon1.Text = tooltip; notifyIcon1.Text = tooltip;
} }
*/
private void pBStatus_MouseClick(object sender, MouseEventArgs e) private void pBStatus_MouseClick(object sender, MouseEventArgs e)
{ {
int i = Int32.Parse(((PictureBox)sender).Tag.ToString()); int i = Int32.Parse(((PictureBox)sender).Tag.ToString());
if (e.Button == System.Windows.Forms.MouseButtons.Right && Program.rootHub.getDS4Status(i) == "BT" && !Program.rootHub.DS4Controllers[i].Charging) DS4Device d = Program.rootHub.DS4Controllers[i];
Program.rootHub.DS4Controllers[i].DisconnectBT(); if (d != null)
else if (e.Button == System.Windows.Forms.MouseButtons.Right && Program.rootHub.getDS4Status(i) == "SONYWA" && !Program.rootHub.DS4Controllers[i].Charging)
{ {
Program.rootHub.DS4Controllers[i].DisconnectDongle(); if (e.Button == MouseButtons.Right && Program.rootHub.getDS4Status(i) == "BT" && !d.Charging)
{
d.DisconnectBT();
}
else if (e.Button == MouseButtons.Right &&
Program.rootHub.getDS4Status(i) == "SONYWA" && !d.Charging)
{
d.DisconnectDongle();
}
} }
} }
@ -1321,12 +1357,11 @@ namespace DS4Windows
{ {
if (e.KeyValue == 13) if (e.KeyValue == 13)
ShowOptions(4, lBProfiles.SelectedItem.ToString()); ShowOptions(4, lBProfiles.SelectedItem.ToString());
if (e.KeyValue == 46) else if (e.KeyValue == 46)
tsBDeleteProfle_Click(this, e); tsBDeleteProfle_Click(this, e);
if (e.KeyValue == 68 && e.Modifiers == Keys.Control) else if (e.KeyValue == 68 && e.Modifiers == Keys.Control)
tSBDupProfile_Click(this, e); tSBDupProfile_Click(this, e);
} }
} }
private void assignToController1ToolStripMenuItem_Click(object sender, EventArgs e) private void assignToController1ToolStripMenuItem_Click(object sender, EventArgs e)
@ -1354,7 +1389,6 @@ namespace DS4Windows
ShowOptions(4, ""); ShowOptions(4, "");
} }
private void tsBNEditProfile_Click(object sender, EventArgs e) private void tsBNEditProfile_Click(object sender, EventArgs e)
{ {
if (lBProfiles.SelectedIndex >= 0) if (lBProfiles.SelectedIndex >= 0)
@ -1366,9 +1400,11 @@ namespace DS4Windows
if (lBProfiles.SelectedIndex >= 0) if (lBProfiles.SelectedIndex >= 0)
{ {
string filename = lBProfiles.SelectedItem.ToString(); string filename = lBProfiles.SelectedItem.ToString();
if (MessageBox.Show(Properties.Resources.ProfileCannotRestore.Replace("*Profile name*", "\"" + filename + "\""), Properties.Resources.DeleteProfile, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) if (MessageBox.Show(Properties.Resources.ProfileCannotRestore.Replace("*Profile name*", "\"" + filename + "\""),
Properties.Resources.DeleteProfile,
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
System.IO.File.Delete(appdatapath + @"\Profiles\" + filename + ".xml"); File.Delete(appdatapath + @"\Profiles\" + filename + ".xml");
RefreshProfiles(); RefreshProfiles();
} }
} }
@ -1384,7 +1420,7 @@ namespace DS4Windows
MTB.TopLevel = false; MTB.TopLevel = false;
MTB.Dock = DockStyle.Top; MTB.Dock = DockStyle.Top;
MTB.Visible = true; MTB.Visible = true;
MTB.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; MTB.FormBorderStyle = FormBorderStyle.None;
tabProfiles.Controls.Add(MTB); tabProfiles.Controls.Add(MTB);
lBProfiles.SendToBack(); lBProfiles.SendToBack();
toolStrip1.SendToBack(); toolStrip1.SendToBack();
@ -1394,19 +1430,19 @@ namespace DS4Windows
} }
} }
private void tSBImportProfile_Click(object sender, EventArgs e) private void tSBImportProfile_Click(object sender, EventArgs e)
{ {
if (appdatapath == Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName) if (appdatapath == Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName)
openProfiles.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool" + @"\Profiles\"; openProfiles.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool" + @"\Profiles\";
else else
openProfiles.InitialDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + @"\Profiles\"; openProfiles.InitialDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + @"\Profiles\";
if (openProfiles.ShowDialog() == System.Windows.Forms.DialogResult.OK)
if (openProfiles.ShowDialog() == DialogResult.OK)
{ {
string[] files = openProfiles.FileNames; string[] files = openProfiles.FileNames;
for (int i = 0; i < files.Length; i++) for (int i = 0, arlen = files.Length; i < arlen; i++)
File.Copy(openProfiles.FileNames[i], appdatapath + "\\Profiles\\" + Path.GetFileName(files[i]), true); File.Copy(openProfiles.FileNames[i], appdatapath + "\\Profiles\\" + Path.GetFileName(files[i]), true);
RefreshProfiles(); RefreshProfiles();
} }
} }
@ -1417,7 +1453,7 @@ namespace DS4Windows
{ {
Stream stream; Stream stream;
Stream profile = new StreamReader(appdatapath + "\\Profiles\\" + lBProfiles.SelectedItem.ToString() + ".xml").BaseStream; Stream profile = new StreamReader(appdatapath + "\\Profiles\\" + lBProfiles.SelectedItem.ToString() + ".xml").BaseStream;
if (saveProfiles.ShowDialog() == System.Windows.Forms.DialogResult.OK) if (saveProfiles.ShowDialog() == DialogResult.OK)
{ {
if ((stream = saveProfiles.OpenFile()) != null) if ((stream = saveProfiles.OpenFile()) != null)
{ {
@ -1432,6 +1468,7 @@ namespace DS4Windows
private void ShowOptions(int devID, string profile) private void ShowOptions(int devID, string profile)
{ {
Show(); Show();
tabMain.SelectedIndex = 1;
WindowState = FormWindowState.Normal; WindowState = FormWindowState.Normal;
toolStrip1.Enabled = false; toolStrip1.Enabled = false;
tSOptions.Visible = true; tSOptions.Visible = true;
@ -1448,12 +1485,12 @@ namespace DS4Windows
oldsize = Size; oldsize = Size;
{ {
if (Size.Height < (int)(90 * dpiy) + Options.mSize.Height) if (Size.Height < (int)(90 * dpiy) + Options.mSize.Height)
Size = new System.Drawing.Size(Size.Width, (int)(90 * dpiy) + Options.mSize.Height); Size = new Size(Size.Width, (int)(90 * dpiy) + Options.mSize.Height);
if (Size.Width < (int)(20 * dpix) + Options.mSize.Width) if (Size.Width < (int)(20 * dpix) + Options.mSize.Width)
Size = new System.Drawing.Size((int)(20 * dpix) + Options.mSize.Width, Size.Height); Size = new Size((int)(20 * dpix) + Options.mSize.Width, Size.Height);
} }
tabMain.SelectedIndex = 1;
opt.Reload(devID, profile); opt.Reload(devID, profile);
opt.inputtimer.Start(); opt.inputtimer.Start();
opt.Visible = true; opt.Visible = true;
@ -1487,11 +1524,13 @@ namespace DS4Windows
private void editButtons_Click(object sender, EventArgs e) private void editButtons_Click(object sender, EventArgs e)
{ {
Button bn = (Button)sender; Button bn = (Button)sender;
int i = Int32.Parse(bn.Tag.ToString()); //int i = Int32.Parse(bn.Tag.ToString());
if (cbs[i].Text == "(" + Properties.Resources.NoProfileLoaded + ")") int i = Convert.ToInt32(bn.Tag);
ShowOptions(i, ""); string profileText = cbs[i].Text;
if (profileText != "(" + Properties.Resources.NoProfileLoaded + ")")
ShowOptions(i, profileText);
else else
ShowOptions(i, cbs[i].Text); ShowOptions(i, "");
} }
private void editMenu_Click(object sender, EventArgs e) private void editMenu_Click(object sender, EventArgs e)
@ -1505,7 +1544,7 @@ namespace DS4Windows
ShowOptions(i, ""); ShowOptions(i, "");
else else
{ {
for (int t = 0; t < em.DropDownItems.Count - 2; t++) for (int t = 0, itemCount = em.DropDownItems.Count - 2; t < itemCount; t++)
{ {
if (((ToolStripMenuItem)em.DropDownItems[t]).Checked) if (((ToolStripMenuItem)em.DropDownItems[t]).Checked)
ShowOptions(i, ((ToolStripMenuItem)em.DropDownItems[t]).Text); ShowOptions(i, ((ToolStripMenuItem)em.DropDownItems[t]).Text);
@ -1515,16 +1554,16 @@ namespace DS4Windows
private void lnkControllers_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) private void lnkControllers_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{ {
System.Diagnostics.Process.Start("control", "joy.cpl"); Process.Start("control", "joy.cpl");
} }
private void hideDS4CheckBox_CheckedChanged(object sender, EventArgs e) private void hideDS4CheckBox_CheckedChanged(object sender, EventArgs e)
{ {
// Prevent the Game Controllers window from throwing an error when controllers are un/hidden // Prevent the Game Controllers window from throwing an error when controllers are un/hidden
System.Diagnostics.Process[] rundll64 = System.Diagnostics.Process.GetProcessesByName("rundll64"); Process[] rundll64 = Process.GetProcessesByName("rundll64");
foreach (System.Diagnostics.Process rundll64Instance in rundll64) foreach (Process rundll64Instance in rundll64)
{ {
foreach (System.Diagnostics.ProcessModule module in rundll64Instance.Modules) foreach (ProcessModule module in rundll64Instance.Modules)
{ {
if (module.FileName.Contains("joy.cpl")) if (module.FileName.Contains("joy.cpl"))
module.Dispose(); module.Dispose();
@ -1583,7 +1622,6 @@ namespace DS4Windows
} }
OnDeviceStatusChanged(this, tdevice); //to update profile name in notify icon OnDeviceStatusChanged(this, tdevice); //to update profile name in notify icon
//ControllerStatusChanged(); //to update profile name in notify icon
} }
private void Profile_Changed_Menu(object sender, ToolStripItemClickedEventArgs e) private void Profile_Changed_Menu(object sender, ToolStripItemClickedEventArgs e)
@ -1620,7 +1658,7 @@ namespace DS4Windows
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{ {
if (e.Button == System.Windows.Forms.MouseButtons.Middle) if (e.Button == MouseButtons.Middle)
{ {
contextclose = true; contextclose = true;
this.Close(); this.Close();
@ -1672,7 +1710,7 @@ namespace DS4Windows
private void appShortcutToStartup() private void appShortcutToStartup()
{ {
Type t = Type.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8")); //Windows Script Host Shell Object Type t = Type.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8")); // Windows Script Host Shell Object
dynamic shell = Activator.CreateInstance(t); dynamic shell = Activator.CreateInstance(t);
try try
{ {
@ -1709,23 +1747,18 @@ namespace DS4Windows
private void tabMain_SelectedIndexChanged(object sender, EventArgs e) private void tabMain_SelectedIndexChanged(object sender, EventArgs e)
{ {
lbLastMessage.Visible = tabMain.SelectedTab != tabLog; TabPage currentTab = tabMain.SelectedTab;
if (tabMain.SelectedTab == tabLog) lbLastMessage.Visible = currentTab != tabLog;
if (currentTab == tabLog)
chData.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); chData.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
if (tabMain.SelectedTab == tabSettings)
if (currentTab == tabSettings)
{ {
lbLastMessage.ForeColor = SystemColors.GrayText; lbLastMessage.ForeColor = SystemColors.GrayText;
lbLastMessage.Text = Properties.Resources.HoverOverItems; lbLastMessage.Text = Properties.Resources.HoverOverItems;
foreach (System.Windows.Forms.Control control in fLPSettings.Controls)
{
if (control.HasChildren)
foreach (System.Windows.Forms.Control ctrl in control.Controls)
ctrl.MouseHover += Items_MouseHover;
control.MouseHover += Items_MouseHover;
}
} }
else if (lvDebug.Items.Count > 0) else if (lvDebug.Items.Count > 0)
lbLastMessage.Text = lbLastMessage.Text = lvDebug.Items[lvDebug.Items.Count - 1].SubItems[1].Text; lbLastMessage.Text = lvDebug.Items[lvDebug.Items.Count - 1].SubItems[1].Text;
else else
lbLastMessage.Text = ""; lbLastMessage.Text = "";
@ -1772,7 +1805,7 @@ namespace DS4Windows
private void lBProfiles_MouseDown(object sender, MouseEventArgs e) private void lBProfiles_MouseDown(object sender, MouseEventArgs e)
{ {
lBProfiles.SelectedIndex = lBProfiles.IndexFromPoint(e.X, e.Y); lBProfiles.SelectedIndex = lBProfiles.IndexFromPoint(e.X, e.Y);
if (e.Button == System.Windows.Forms.MouseButtons.Right) if (e.Button == MouseButtons.Right)
{ {
if (lBProfiles.SelectedIndex < 0) if (lBProfiles.SelectedIndex < 0)
{ {
@ -1797,6 +1830,7 @@ namespace DS4Windows
assignToController2ToolStripMenuItem, assignToController2ToolStripMenuItem,
assignToController3ToolStripMenuItem, assignToController3ToolStripMenuItem,
assignToController4ToolStripMenuItem }; assignToController4ToolStripMenuItem };
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
if (lBProfiles.SelectedIndex == cbs[i].SelectedIndex) if (lBProfiles.SelectedIndex == cbs[i].SelectedIndex)
@ -1804,6 +1838,7 @@ namespace DS4Windows
else else
assigns[i].Checked = false; assigns[i].Checked = false;
} }
deleteToolStripMenuItem.Visible = true; deleteToolStripMenuItem.Visible = true;
editToolStripMenuItem.Visible = true; editToolStripMenuItem.Visible = true;
duplicateToolStripMenuItem.Visible = true; duplicateToolStripMenuItem.Visible = true;
@ -1837,14 +1872,17 @@ namespace DS4Windows
e.Effect = DragDropEffects.None; // Unknown data, ignore it e.Effect = DragDropEffects.None; // Unknown data, ignore it
} }
private void tBProfile_TextChanged(object sender, EventArgs e) private void tBProfile_TextChanged(object sender, EventArgs e)
{ {
if (tSTBProfile.Text != null && tSTBProfile.Text != "" && !tSTBProfile.Text.Contains("\\") && !tSTBProfile.Text.Contains("/") && !tSTBProfile.Text.Contains(":") && !tSTBProfile.Text.Contains("*") && !tSTBProfile.Text.Contains("?") && !tSTBProfile.Text.Contains("\"") && !tSTBProfile.Text.Contains("<") && !tSTBProfile.Text.Contains(">") && !tSTBProfile.Text.Contains("|")) if (tSTBProfile.Text != null && tSTBProfile.Text != "" &&
tSTBProfile.ForeColor = System.Drawing.SystemColors.WindowText; !tSTBProfile.Text.Contains("\\") && !tSTBProfile.Text.Contains("/") &&
!tSTBProfile.Text.Contains(":") && !tSTBProfile.Text.Contains("*") &&
!tSTBProfile.Text.Contains("?") && !tSTBProfile.Text.Contains("\"") &&
!tSTBProfile.Text.Contains("<") && !tSTBProfile.Text.Contains(">") &&
!tSTBProfile.Text.Contains("|"))
tSTBProfile.ForeColor = SystemColors.WindowText;
else else
tSTBProfile.ForeColor = System.Drawing.SystemColors.GrayText; tSTBProfile.ForeColor = SystemColors.GrayText;
} }
private void tBProfile_Enter(object sender, EventArgs e) private void tBProfile_Enter(object sender, EventArgs e)
@ -1872,7 +1910,12 @@ namespace DS4Windows
opt.saving = true; opt.saving = true;
opt.Set(); opt.Set();
if (tSTBProfile.Text != null && tSTBProfile.Text != "" && !tSTBProfile.Text.Contains("\\") && !tSTBProfile.Text.Contains("/") && !tSTBProfile.Text.Contains(":") && !tSTBProfile.Text.Contains("*") && !tSTBProfile.Text.Contains("?") && !tSTBProfile.Text.Contains("\"") && !tSTBProfile.Text.Contains("<") && !tSTBProfile.Text.Contains(">") && !tSTBProfile.Text.Contains("|")) if (tSTBProfile.Text != null && tSTBProfile.Text != "" &&
!tSTBProfile.Text.Contains("\\") && !tSTBProfile.Text.Contains("/") &&
!tSTBProfile.Text.Contains(":") && !tSTBProfile.Text.Contains("*") &&
!tSTBProfile.Text.Contains("?") && !tSTBProfile.Text.Contains("\"") &&
!tSTBProfile.Text.Contains("<") && !tSTBProfile.Text.Contains(">") &&
!tSTBProfile.Text.Contains("|"))
{ {
File.Delete(appdatapath + @"\Profiles\" + opt.filename + ".xml"); File.Delete(appdatapath + @"\Profiles\" + opt.filename + ".xml");
ProfilePath[opt.device] = tSTBProfile.Text; ProfilePath[opt.device] = tSTBProfile.Text;
@ -1911,15 +1954,18 @@ namespace DS4Windows
private void nUDUpdateTime_ValueChanged(object sender, EventArgs e) private void nUDUpdateTime_ValueChanged(object sender, EventArgs e)
{ {
if (cBUpdateTime.SelectedIndex == 0) int currentIndex = cBUpdateTime.SelectedIndex;
if (currentIndex == 0)
CheckWhen = (int)nUDUpdateTime.Value; CheckWhen = (int)nUDUpdateTime.Value;
else if (cBUpdateTime.SelectedIndex == 1) else if (currentIndex == 1)
CheckWhen = (int)nUDUpdateTime.Value * 24; CheckWhen = (int)nUDUpdateTime.Value * 24;
if (nUDUpdateTime.Value < 1) if (nUDUpdateTime.Value < 1)
cBUpdate.Checked = false; cBUpdate.Checked = false;
if (nUDUpdateTime.Value == 1) if (nUDUpdateTime.Value == 1)
{ {
int index = cBUpdateTime.SelectedIndex; int index = currentIndex;
cBUpdateTime.Items.Clear(); cBUpdateTime.Items.Clear();
cBUpdateTime.Items.Add(Properties.Resources.Hour); cBUpdateTime.Items.Add(Properties.Resources.Hour);
cBUpdateTime.Items.Add(Properties.Resources.Day); cBUpdateTime.Items.Add(Properties.Resources.Day);
@ -1927,7 +1973,7 @@ namespace DS4Windows
} }
else if (cBUpdateTime.Items[0].ToString() == Properties.Resources.Hour) else if (cBUpdateTime.Items[0].ToString() == Properties.Resources.Hour)
{ {
int index = cBUpdateTime.SelectedIndex; int index = currentIndex;
cBUpdateTime.Items.Clear(); cBUpdateTime.Items.Clear();
cBUpdateTime.Items.Add(Properties.Resources.Hours); cBUpdateTime.Items.Add(Properties.Resources.Hours);
cBUpdateTime.Items.Add(Properties.Resources.Days); cBUpdateTime.Items.Add(Properties.Resources.Days);
@ -1937,15 +1983,17 @@ namespace DS4Windows
private void cBUpdateTime_SelectedIndexChanged(object sender, EventArgs e) private void cBUpdateTime_SelectedIndexChanged(object sender, EventArgs e)
{ {
if (cBUpdateTime.SelectedIndex == 0) int index = cBUpdateTime.SelectedIndex;
if (index == 0)
CheckWhen = (int)nUDUpdateTime.Value; CheckWhen = (int)nUDUpdateTime.Value;
else if (cBUpdateTime.SelectedIndex == 1) else if (index == 1)
CheckWhen = (int)nUDUpdateTime.Value * 24; CheckWhen = (int)nUDUpdateTime.Value * 24;
} }
private void lLBUpdate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) private void lLBUpdate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{ {
Uri url = new Uri("http://23.236.26.40/ds4windows/files/builds/newest.txt"); //Sorry other devs, gonna have to find your own server // Sorry other devs, gonna have to find your own server
Uri url = new Uri("http://23.236.26.40/ds4windows/files/builds/newest.txt");
WebClient wct = new WebClient(); WebClient wct = new WebClient();
wct.DownloadFileAsync(url, appdatapath + "\\version.txt"); wct.DownloadFileAsync(url, appdatapath + "\\version.txt");
wct.DownloadFileCompleted += wct_DownloadFileCompleted; wct.DownloadFileCompleted += wct_DownloadFileCompleted;
@ -1963,7 +2011,9 @@ namespace DS4Windows
string version2 = fvi.FileVersion; string version2 = fvi.FileVersion;
string newversion2 = File.ReadAllText(appdatapath + "\\version.txt"); string newversion2 = File.ReadAllText(appdatapath + "\\version.txt");
if (version2.Replace(',', '.').CompareTo(File.ReadAllText(appdatapath + "\\version.txt")) == -1)//CompareVersions(); if (version2.Replace(',', '.').CompareTo(File.ReadAllText(appdatapath + "\\version.txt")) == -1)//CompareVersions();
if (MessageBox.Show(Properties.Resources.DownloadVersion.Replace("*number*", newversion2), Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) {
if (MessageBox.Show(Properties.Resources.DownloadVersion.Replace("*number*", newversion2),
Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
if (!File.Exists(exepath + "\\DS4Updater.exe") || (File.Exists(exepath + "\\DS4Updater.exe") if (!File.Exists(exepath + "\\DS4Updater.exe") || (File.Exists(exepath + "\\DS4Updater.exe")
&& (FileVersionInfo.GetVersionInfo(exepath + "\\DS4Updater.exe").FileVersion.CompareTo("1.1.0.0") == -1))) && (FileVersionInfo.GetVersionInfo(exepath + "\\DS4Updater.exe").FileVersion.CompareTo("1.1.0.0") == -1)))
@ -1978,17 +2028,21 @@ namespace DS4Windows
Process.Start("http://ds4windows.com/Files/DS4Updater.exe"); Process.Start("http://ds4windows.com/Files/DS4Updater.exe");
} }
} }
Process p = new Process(); Process p = new Process();
p.StartInfo.FileName = exepath + "\\DS4Updater.exe"; p.StartInfo.FileName = exepath + "\\DS4Updater.exe";
if (!cBDownloadLangauge.Checked) if (!cBDownloadLangauge.Checked)
p.StartInfo.Arguments = "-skipLang"; p.StartInfo.Arguments = "-skipLang";
if (AdminNeeded()) if (AdminNeeded())
p.StartInfo.Verb = "runas"; p.StartInfo.Verb = "runas";
try { p.Start(); Close(); } try { p.Start(); Close(); }
catch { } catch { }
} }
else else
File.Delete(appdatapath + "\\version.txt"); File.Delete(appdatapath + "\\version.txt");
}
else else
{ {
File.Delete(appdatapath + "\\version.txt"); File.Delete(appdatapath + "\\version.txt");
@ -1998,19 +2052,16 @@ namespace DS4Windows
private void linkProfiles_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) private void linkProfiles_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{ {
System.Diagnostics.Process.Start(appdatapath + "\\Profiles"); Process.Start(appdatapath + "\\Profiles");
} }
private void linkUninstall_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) private void linkUninstall_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{ {
if (File.Exists(appdatapath + "\\Virtual Bus Driver\\ScpDriver.exe")) if (File.Exists(appdatapath + "\\Virtual Bus Driver\\ScpDriver.exe"))
try { System.Diagnostics.Process.Start(appdatapath + "\\Virtual Bus Driver\\ScpDriver.exe"); } {
catch { System.Diagnostics.Process.Start(appdatapath + "\\Virtual Bus Driver"); } try { Process.Start(appdatapath + "\\Virtual Bus Driver\\ScpDriver.exe"); }
} catch { Process.Start(appdatapath + "\\Virtual Bus Driver"); }
}
private void cBNotifications_CheckedChanged(object sender, EventArgs e)
{
//Notifications = cBNotifications.Checked;
} }
private void cBoxNotifications_SelectedIndexChanged(object sender, EventArgs e) private void cBoxNotifications_SelectedIndexChanged(object sender, EventArgs e)
@ -2056,7 +2107,7 @@ namespace DS4Windows
DS4LightBar.shuttingdown = true; DS4LightBar.shuttingdown = true;
} }
if (oldsize == new System.Drawing.Size(0, 0)) if (oldsize == new Size(0, 0))
{ {
FormWidth = this.Width; FormWidth = this.Width;
FormHeight = this.Height; FormHeight = this.Height;
@ -2067,7 +2118,7 @@ namespace DS4Windows
FormHeight = oldsize.Height; FormHeight = oldsize.Height;
} }
if (!String.IsNullOrEmpty(appdatapath)) if (!string.IsNullOrEmpty(appdatapath))
{ {
Save(); Save();
blankControllerTab(); blankControllerTab();
@ -2109,6 +2160,7 @@ namespace DS4Windows
{ {
//oldxiport = (int)Math.Round(nUDXIPorts.Value,0); //oldxiport = (int)Math.Round(nUDXIPorts.Value,0);
} }
int oldxiport; int oldxiport;
private void pnlXIPorts_MouseLeave(object sender, EventArgs e) private void pnlXIPorts_MouseLeave(object sender, EventArgs e)
{ {
@ -2146,9 +2198,10 @@ namespace DS4Windows
{ {
Label lb = (Label)sender; Label lb = (Label)sender;
int i = Int32.Parse(lb.Tag.ToString()); int i = Int32.Parse(lb.Tag.ToString());
if (Program.rootHub.DS4Controllers[i] != null && Program.rootHub.DS4Controllers[i].ConnectionType == ConnectionType.BT) DS4Device d = Program.rootHub.DS4Controllers[i];
if (d != null && d.ConnectionType == ConnectionType.BT)
{ {
double latency = Program.rootHub.DS4Controllers[i].Latency; double latency = d.Latency;
toolTip1.Hide(Pads[i]); toolTip1.Hide(Pads[i]);
toolTip1.Show(Properties.Resources.InputDelay.Replace("*number*", latency.ToString()), lb, lb.Size.Width, 0); toolTip1.Show(Properties.Resources.InputDelay.Replace("*number*", latency.ToString()), lb, lb.Size.Width, 0);
} }

File diff suppressed because it is too large Load Diff