Add startup task mode.

Related to issue #16.
This commit is contained in:
Travis Nickles 2017-04-19 22:54:09 -07:00
parent 29b73527a4
commit d1994b2876
6 changed files with 2614 additions and 1682 deletions

View File

@ -118,6 +118,10 @@
this.hideDS4CheckBox = new System.Windows.Forms.CheckBox(); this.hideDS4CheckBox = new System.Windows.Forms.CheckBox();
this.cBSwipeProfiles = new System.Windows.Forms.CheckBox(); this.cBSwipeProfiles = new System.Windows.Forms.CheckBox();
this.StartWindowsCheckBox = new System.Windows.Forms.CheckBox(); this.StartWindowsCheckBox = new System.Windows.Forms.CheckBox();
this.runStartupPanel = new System.Windows.Forms.Panel();
this.runStartTaskRadio = new System.Windows.Forms.RadioButton();
this.label1 = new System.Windows.Forms.Label();
this.runStartProgRadio = new System.Windows.Forms.RadioButton();
this.startMinimizedCheckBox = new System.Windows.Forms.CheckBox(); this.startMinimizedCheckBox = new System.Windows.Forms.CheckBox();
this.panel1 = new System.Windows.Forms.Panel(); this.panel1 = new System.Windows.Forms.Panel();
this.lbNotifications = new System.Windows.Forms.Label(); this.lbNotifications = new System.Windows.Forms.Label();
@ -168,6 +172,7 @@
this.toolStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout();
this.tabSettings.SuspendLayout(); this.tabSettings.SuspendLayout();
this.fLPSettings.SuspendLayout(); this.fLPSettings.SuspendLayout();
this.runStartupPanel.SuspendLayout();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
this.panel2.SuspendLayout(); this.panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDLatency)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nUDLatency)).BeginInit();
@ -847,6 +852,7 @@
this.fLPSettings.Controls.Add(this.hideDS4CheckBox); this.fLPSettings.Controls.Add(this.hideDS4CheckBox);
this.fLPSettings.Controls.Add(this.cBSwipeProfiles); this.fLPSettings.Controls.Add(this.cBSwipeProfiles);
this.fLPSettings.Controls.Add(this.StartWindowsCheckBox); this.fLPSettings.Controls.Add(this.StartWindowsCheckBox);
this.fLPSettings.Controls.Add(this.runStartupPanel);
this.fLPSettings.Controls.Add(this.startMinimizedCheckBox); this.fLPSettings.Controls.Add(this.startMinimizedCheckBox);
this.fLPSettings.Controls.Add(this.panel1); this.fLPSettings.Controls.Add(this.panel1);
this.fLPSettings.Controls.Add(this.cBDisconnectBT); this.fLPSettings.Controls.Add(this.cBDisconnectBT);
@ -884,6 +890,37 @@
this.StartWindowsCheckBox.UseVisualStyleBackColor = true; this.StartWindowsCheckBox.UseVisualStyleBackColor = true;
this.StartWindowsCheckBox.CheckedChanged += new System.EventHandler(this.StartWindowsCheckBox_CheckedChanged); this.StartWindowsCheckBox.CheckedChanged += new System.EventHandler(this.StartWindowsCheckBox_CheckedChanged);
// //
// runStartupPanel
//
this.runStartupPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.runStartupPanel.Controls.Add(this.runStartTaskRadio);
this.runStartupPanel.Controls.Add(this.label1);
this.runStartupPanel.Controls.Add(this.runStartProgRadio);
resources.ApplyResources(this.runStartupPanel, "runStartupPanel");
this.runStartupPanel.Name = "runStartupPanel";
//
// runStartTaskRadio
//
resources.ApplyResources(this.runStartTaskRadio, "runStartTaskRadio");
this.runStartTaskRadio.Name = "runStartTaskRadio";
this.runStartTaskRadio.TabStop = true;
this.runStartTaskRadio.UseVisualStyleBackColor = true;
this.runStartTaskRadio.Click += new System.EventHandler(this.runStartTaskRadio_Click);
//
// label1
//
resources.ApplyResources(this.label1, "label1");
this.label1.Name = "label1";
//
// runStartProgRadio
//
resources.ApplyResources(this.runStartProgRadio, "runStartProgRadio");
this.runStartProgRadio.Checked = true;
this.runStartProgRadio.Name = "runStartProgRadio";
this.runStartProgRadio.TabStop = true;
this.runStartProgRadio.UseVisualStyleBackColor = true;
this.runStartProgRadio.Click += new System.EventHandler(this.runStartProgRadio_Click);
//
// startMinimizedCheckBox // startMinimizedCheckBox
// //
resources.ApplyResources(this.startMinimizedCheckBox, "startMinimizedCheckBox"); resources.ApplyResources(this.startMinimizedCheckBox, "startMinimizedCheckBox");
@ -1192,6 +1229,8 @@
this.tabSettings.ResumeLayout(false); this.tabSettings.ResumeLayout(false);
this.fLPSettings.ResumeLayout(false); this.fLPSettings.ResumeLayout(false);
this.fLPSettings.PerformLayout(); this.fLPSettings.PerformLayout();
this.runStartupPanel.ResumeLayout(false);
this.runStartupPanel.PerformLayout();
this.panel1.ResumeLayout(false); this.panel1.ResumeLayout(false);
this.panel1.PerformLayout(); this.panel1.PerformLayout();
this.panel2.ResumeLayout(false); this.panel2.ResumeLayout(false);
@ -1336,6 +1375,10 @@
private System.Windows.Forms.ToolStripMenuItem useCustomColorToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem useCustomColorToolStripMenuItem;
private AdvancedColorDialog advColorDialog; private AdvancedColorDialog advColorDialog;
private System.Windows.Forms.CheckBox cBUseWhiteIcon; private System.Windows.Forms.CheckBox cBUseWhiteIcon;
private System.Windows.Forms.Panel runStartupPanel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.RadioButton runStartProgRadio;
private System.Windows.Forms.RadioButton runStartTaskRadio;
//private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; //private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2;
} }
} }

View File

@ -14,7 +14,10 @@ using System.Text;
using System.Globalization; using System.Globalization;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.ServiceProcess; using System.ServiceProcess;
using Microsoft.Win32.TaskScheduler;
using static DS4Windows.Global; using static DS4Windows.Global;
using System.Security.Principal;
namespace DS4Windows namespace DS4Windows
{ {
public partial class DS4Form : Form public partial class DS4Form : Form
@ -75,6 +78,9 @@ namespace DS4Windows
public DS4Form(string[] args) public DS4Form(string[] args)
{ {
InitializeComponent(); InitializeComponent();
this.StartWindowsCheckBox.CheckedChanged -= this.StartWindowsCheckBox_CheckedChanged;
saveProfiles.Filter = Properties.Resources.XMLFiles + "|*.xml"; saveProfiles.Filter = Properties.Resources.XMLFiles + "|*.xml";
openProfiles.Filter = Properties.Resources.XMLFiles + "|*.xml"; openProfiles.Filter = Properties.Resources.XMLFiles + "|*.xml";
arguements = args; arguements = args;
@ -253,7 +259,7 @@ namespace DS4Windows
} }
bool start = true; bool start = true;
bool mini = false; bool mini = false;
for (int i = 0; i < arguements.Length; i++) for (int i = 0, argslen = arguements.Length; i < argslen; i++)
{ {
if (arguements[i] == "-stop") if (arguements[i] == "-stop")
start = false; start = false;
@ -333,17 +339,34 @@ namespace DS4Windows
test.Tick += test_Tick; test.Tick += test_Tick;
if (!Directory.Exists(appdatapath + "\\Virtual Bus Driver")) if (!Directory.Exists(appdatapath + "\\Virtual Bus Driver"))
linkUninstall.Visible = false; linkUninstall.Visible = false;
if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk")) if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk"))
{ {
StartWindowsCheckBox.Checked = true; StartWindowsCheckBox.Checked = true;
runStartupPanel.Visible = true;
string lnkpath = WinProgs.ResolveShortcutAndArgument(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk"); string lnkpath = WinProgs.ResolveShortcutAndArgument(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk");
if (!lnkpath.EndsWith("-m")) string onlylnkpath = WinProgs.ResolveShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk");
if (!lnkpath.EndsWith("-runtask"))
{
runStartProgRadio.Checked = true;
}
else
{
runStartTaskRadio.Checked = true;
}
if (onlylnkpath != Process.GetCurrentProcess().MainModule.FileName)
{ {
File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk"); File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk");
appShortcutToStartup(); appShortcutToStartup();
changeStartupRoutine();
} }
} }
UpdateTheUpdater(); UpdateTheUpdater();
this.StartWindowsCheckBox.CheckedChanged += new System.EventHandler(this.StartWindowsCheckBox_CheckedChanged);
} }
private async void UpdateTheUpdater() private async void UpdateTheUpdater()
@ -353,7 +376,7 @@ namespace DS4Windows
Process[] processes = Process.GetProcessesByName("DS4Updater"); Process[] processes = Process.GetProcessesByName("DS4Updater");
while (processes.Length > 0) while (processes.Length > 0)
{ {
await Task.Delay(500); await System.Threading.Tasks.Task.Delay(500);
} }
File.Delete(exepath + "\\DS4Updater.exe"); File.Delete(exepath + "\\DS4Updater.exe");
File.Move(exepath + "\\Update Files\\DS4Updater.exe", exepath + "\\DS4Updater.exe"); File.Move(exepath + "\\Update Files\\DS4Updater.exe", exepath + "\\DS4Updater.exe");
@ -1249,12 +1272,31 @@ namespace DS4Windows
private void StartWindowsCheckBox_CheckedChanged(object sender, EventArgs e) private void StartWindowsCheckBox_CheckedChanged(object sender, EventArgs e)
{ {
bool isChecked = StartWindowsCheckBox.Checked;
RegistryKey KeyLoc = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); RegistryKey KeyLoc = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (StartWindowsCheckBox.Checked && !File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk")) if (isChecked && !File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk"))
{
appShortcutToStartup(); appShortcutToStartup();
else if (!StartWindowsCheckBox.Checked) }
else if (!isChecked)
{
File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk"); File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk");
}
KeyLoc.DeleteValue("DS4Tool", false); KeyLoc.DeleteValue("DS4Tool", false);
if (isChecked)
{
runStartupPanel.Visible = true;
}
else
{
runStartupPanel.Visible = false;
runStartTaskRadio.Checked = false;
runStartProgRadio.Checked = true;
}
changeStartupRoutine();
} }
private void appShortcutToStartup() private void appShortcutToStartup()
@ -1267,8 +1309,18 @@ namespace DS4Windows
try try
{ {
string app = Assembly.GetExecutingAssembly().Location; string app = Assembly.GetExecutingAssembly().Location;
if (runStartProgRadio.Checked)
{
lnk.TargetPath = Assembly.GetExecutingAssembly().Location; lnk.TargetPath = Assembly.GetExecutingAssembly().Location;
lnk.Arguments = "-m"; lnk.Arguments = "-m";
}
else if (runStartTaskRadio.Checked)
{
lnk.Arguments = "-runtask";
}
//lnk.TargetPath = Assembly.GetExecutingAssembly().Location;
//lnk.Arguments = "-m";
lnk.IconLocation = app.Replace('\\', '/'); lnk.IconLocation = app.Replace('\\', '/');
lnk.Save(); lnk.Save();
} }
@ -1793,6 +1845,58 @@ namespace DS4Windows
} }
} }
private void runStartProgRadio_Click(object sender, EventArgs e)
{
appShortcutToStartup();
changeStartupRoutine();
}
private void runStartTaskRadio_Click(object sender, EventArgs e)
{
appShortcutToStartup();
changeStartupRoutine();
}
private void changeStartupRoutine()
{
if (runStartTaskRadio.Checked)
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
if (principal.IsInRole(WindowsBuiltInRole.Administrator))
{
TaskService ts = new TaskService();
Microsoft.Win32.TaskScheduler.Task tasker = ts.FindTask("RunDS4Windows");
if (tasker != null)
{
ts.RootFolder.DeleteTask("RunDS4Windows");
}
TaskDefinition td = ts.NewTask();
td.Actions.Add(new ExecAction(@"%windir%\System32\cmd.exe",
"/c start \"RunDS4Windows\" \"" + Process.GetCurrentProcess().MainModule.FileName + "\" -m",
new FileInfo(Process.GetCurrentProcess().MainModule.FileName).DirectoryName));
td.Principal.RunLevel = TaskRunLevel.Highest;
ts.RootFolder.RegisterTaskDefinition("RunDS4Windows", td);
}
}
else
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
if (principal.IsInRole(WindowsBuiltInRole.Administrator))
{
TaskService ts = new TaskService();
Microsoft.Win32.TaskScheduler.Task tasker = ts.FindTask("RunDS4Windows");
if (tasker != null)
{
ts.RootFolder.DeleteTask("RunDS4Windows");
}
}
}
}
private void cBDownloadLangauge_CheckedChanged(object sender, EventArgs e) private void cBDownloadLangauge_CheckedChanged(object sender, EventArgs e)
{ {
DownloadLang = cBDownloadLangauge.Checked; DownloadLang = cBDownloadLangauge.Checked;

File diff suppressed because it is too large Load Diff

View File

@ -74,6 +74,14 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="JetBrains.Annotations, Version=10.2.1.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
<HintPath>..\packages\TaskScheduler.2.5.23\lib\net40\JetBrains.Annotations.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Win32.TaskScheduler, Version=2.5.23.0, Culture=neutral, PublicKeyToken=0d013ddd5178a2ae, processorArchitecture=MSIL">
<HintPath>..\packages\TaskScheduler.2.5.23\lib\net40\Microsoft.Win32.TaskScheduler.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.IO.Compression" /> <Reference Include="System.IO.Compression" />
@ -1026,6 +1034,7 @@
<EmbeddedResource Include="Properties\Resources.zh-hans.resx" /> <EmbeddedResource Include="Properties\Resources.zh-hans.resx" />
<EmbeddedResource Include="Properties\Resources.zh-Hant.resx" /> <EmbeddedResource Include="Properties\Resources.zh-Hant.resx" />
<None Include="app.manifest" /> <None Include="app.manifest" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@ -5,6 +5,7 @@ using System.Runtime.InteropServices;
using System.Diagnostics; using System.Diagnostics;
using System.ComponentModel; using System.ComponentModel;
using System.Globalization; using System.Globalization;
using Microsoft.Win32.TaskScheduler;
namespace DS4Windows namespace DS4Windows
{ {
@ -32,7 +33,7 @@ namespace DS4Windows
static void Main(string[] args) static void Main(string[] args)
{ {
//Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("he"); //Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("he");
for (int i = 0; i < args.Length; i++) for (int i = 0, argsLen = args.Length; i < argsLen; i++)
{ {
string s = args[i]; string s = args[i];
if (s == "driverinstall" || s == "-driverinstall") if (s == "driverinstall" || s == "-driverinstall")
@ -58,6 +59,18 @@ namespace DS4Windows
return; return;
} }
} }
else if (s == "runtask" || s == "-runtask")
{
TaskService ts = new TaskService();
Task tasker = ts.FindTask("RunDS4Windows");
if (tasker != null)
{
tasker.Run("");
}
Environment.ExitCode = 0;
return;
}
} }
System.Runtime.GCSettings.LatencyMode = System.Runtime.GCLatencyMode.LowLatency; System.Runtime.GCSettings.LatencyMode = System.Runtime.GCLatencyMode.LowLatency;
try try

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="TaskScheduler" version="2.5.23" targetFramework="net45" />
</packages>