2014-03-28 02:50:40 +01:00
using System ;
using System.Windows.Forms ;
using System.Runtime.InteropServices ;
using DS4Control ;
2014-05-30 22:39:39 +02:00
using DS4Library ;
2014-04-27 21:32:09 +02:00
using System.IO ;
using System.Reflection ;
using System.Collections.Generic ;
2014-05-14 09:12:15 +02:00
using System.Net ;
2014-05-21 07:36:05 +02:00
using System.Management ;
2014-05-30 22:39:39 +02:00
using System.Drawing ;
2014-05-21 19:39:56 +02:00
using Microsoft.Win32 ;
2014-05-28 21:47:25 +02:00
using System.Diagnostics ;
2014-06-06 22:38:52 +02:00
using System.Xml ;
2014-06-09 01:41:36 +02:00
using System.Text ;
2014-03-28 02:50:40 +01:00
namespace ScpServer
{
public partial class ScpForm : Form
{
2014-06-14 21:14:27 +02:00
double version = 10.4 ;
2014-03-28 02:50:40 +01:00
private DS4Control . Control rootHub ;
delegate void LogDebugDelegate ( DateTime Time , String Data ) ;
2014-05-30 22:39:39 +02:00
protected Label [ ] Pads , Batteries ;
2014-04-27 21:32:09 +02:00
protected ComboBox [ ] cbs ;
protected Button [ ] ebns ;
2014-05-30 22:39:39 +02:00
protected PictureBox [ ] statPB ;
2014-04-29 03:14:01 +02:00
protected ToolStripMenuItem [ ] shortcuts ;
2014-05-14 09:12:15 +02:00
WebClient wc = new WebClient ( ) ;
2014-06-02 05:19:04 +02:00
Timer test = new Timer ( ) , hotkeystimer = new Timer ( ) ;
2014-06-06 22:38:52 +02:00
string exepath = Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location ) . FullName ;
2014-06-13 21:52:25 +02:00
string appdatapath = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) + "\\DS4Tool" ;
2014-06-06 22:38:52 +02:00
float dpix , dpiy ;
DateTime oldnow = DateTime . UtcNow ;
string tempprofile = "null" ;
2014-06-09 01:41:36 +02:00
List < string > profilenames = new List < string > ( ) ;
2014-06-06 22:38:52 +02:00
List < string > programpaths = new List < string > ( ) ;
List < string > [ ] proprofiles ;
private static int WM_QUERYENDSESSION = 0x11 ;
private static bool systemShutdown = false ;
delegate void ControllerStatusChangedDelegate ( object sender , EventArgs e ) ;
delegate void HotKeysDelegate ( object sender , EventArgs e ) ;
Options opt ;
private System . Drawing . Size oldsize ;
2014-06-09 01:41:36 +02:00
WinProgs WP ;
2014-05-30 22:39:39 +02:00
protected void SetupArrays ( )
{
2014-04-27 21:32:09 +02:00
Pads = new Label [ 4 ] { lbPad1 , lbPad2 , lbPad3 , lbPad4 } ;
2014-05-30 22:39:39 +02:00
Batteries = new Label [ 4 ] { lBBatt1 , lBBatt2 , lBBatt3 , lBBatt4 } ;
2014-04-27 21:32:09 +02:00
cbs = new ComboBox [ 4 ] { cBController1 , cBController2 , cBController3 , cBController4 } ;
ebns = new Button [ 4 ] { bnEditC1 , bnEditC2 , bnEditC3 , bnEditC4 } ;
2014-05-30 22:39:39 +02:00
statPB = new PictureBox [ 4 ] { pBStatus1 , pBStatus2 , pBStatus3 , pBStatus4 } ;
2014-04-30 05:54:41 +02:00
shortcuts = new ToolStripMenuItem [ 4 ] { ( ToolStripMenuItem ) notifyIcon1 . ContextMenuStrip . Items [ 0 ] ,
( ToolStripMenuItem ) notifyIcon1 . ContextMenuStrip . Items [ 1 ] ,
( ToolStripMenuItem ) notifyIcon1 . ContextMenuStrip . Items [ 2 ] ,
( ToolStripMenuItem ) notifyIcon1 . ContextMenuStrip . Items [ 3 ] } ;
2014-05-30 22:39:39 +02:00
}
2014-06-09 01:41:36 +02:00
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow ( ) ;
[DllImport("user32.dll")]
private static extern uint GetWindowThreadProcessId ( IntPtr hWnd , out uint lpdwProcessId ) ;
[DllImport("kernel32.dll")]
private static extern IntPtr OpenProcess ( uint dwDesiredAccess , bool bInheritHandle , uint dwProcessId ) ;
[DllImport("kernel32.dll")]
private static extern bool CloseHandle ( IntPtr handle ) ;
[DllImport("psapi.dll")]
private static extern uint GetModuleBaseName ( IntPtr hWnd , IntPtr hModule , StringBuilder lpFileName , int nSize ) ;
[DllImport("psapi.dll")]
private static extern uint GetModuleFileNameEx ( IntPtr hWnd , IntPtr hModule , StringBuilder lpFileName , int nSize ) ;
2014-05-30 22:39:39 +02:00
public ScpForm ( )
{
InitializeComponent ( ) ;
ThemeUtil . SetTheme ( lvDebug ) ;
SetupArrays ( ) ;
2014-06-09 01:41:36 +02:00
//CheckDrivers();
2014-06-06 22:38:52 +02:00
SystemEvents . PowerModeChanged + = OnPowerChange ;
2014-06-02 19:29:38 +02:00
tSOptions . Visible = false ;
2014-06-06 22:38:52 +02:00
ToolTip tt = new ToolTip ( ) ;
2014-06-13 21:52:25 +02:00
if ( File . Exists ( appdatapath + "\\Profiles.xml" ) )
2014-06-12 20:46:00 +02:00
tt . SetToolTip ( linkUninstall , "If removing DS4Windows, You can delete the settings following the profile folder link" ) ;
2014-06-09 01:41:36 +02:00
}
public static string GetTopWindowName ( )
{
IntPtr hWnd = GetForegroundWindow ( ) ;
uint lpdwProcessId ;
GetWindowThreadProcessId ( hWnd , out lpdwProcessId ) ;
IntPtr hProcess = OpenProcess ( 0x0410 , false , lpdwProcessId ) ;
StringBuilder text = new StringBuilder ( 1000 ) ;
GetModuleFileNameEx ( hProcess , IntPtr . Zero , text , text . Capacity ) ;
CloseHandle ( hProcess ) ;
return text . ToString ( ) ;
2014-05-31 06:37:02 +02:00
}
2014-06-06 22:38:52 +02:00
private void OnPowerChange ( object s , PowerModeChangedEventArgs e )
{
switch ( e . Mode )
{
case PowerModes . Resume :
if ( btnStartStop . Text = = "Start" )
btnStartStop_Clicked ( ) ;
break ;
case PowerModes . Suspend :
if ( btnStartStop . Text = = "Stop" )
btnStartStop_Clicked ( ) ;
break ;
}
}
2014-05-31 06:37:02 +02:00
protected void Form_Load ( object sender , EventArgs e )
{
2014-06-03 07:29:42 +02:00
SetupArrays ( ) ;
2014-06-13 21:52:25 +02:00
if ( File . Exists ( exepath + "\\Profiles.xml" )
& & File . Exists ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) + "\\DS4Tool\\Profiles.xml" ) )
new SaveWhere ( true ) . ShowDialog ( ) ;
else if ( File . Exists ( exepath + "\\Profiles.xml" ) )
Global . SaveWhere ( exepath ) ;
else if ( File . Exists ( appdatapath + "\\Profiles.xml" ) )
Global . SaveWhere ( appdatapath ) ;
else if ( ! File . Exists ( exepath + "\\Profiles.xml" )
& & ! File . Exists ( appdatapath + "\\Profiles.xml" ) )
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
{
2014-06-12 20:46:00 +02:00
new WelcomeDialog ( ) . ShowDialog ( ) ;
new SaveWhere ( false ) . ShowDialog ( ) ;
}
2014-06-13 21:52:25 +02:00
2014-06-12 20:46:00 +02:00
if ( String . IsNullOrEmpty ( Global . appdatapath ) )
{
Close ( ) ;
return ;
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
}
2014-06-03 07:29:42 +02:00
Graphics g = this . CreateGraphics ( ) ;
try
{
dpix = g . DpiX ;
dpiy = g . DpiY ;
}
finally
{
g . Dispose ( ) ;
}
2014-05-31 06:37:02 +02:00
Icon = Properties . Resources . DS4 ;
notifyIcon1 . Icon = Properties . Resources . DS4 ;
rootHub = new DS4Control . Control ( ) ;
rootHub . Debug + = On_Debug ;
Log . GuiLog + = On_Debug ;
Log . TrayIconLog + = ShowNotification ;
// tmrUpdate.Enabled = true; TODO remove tmrUpdate and leave tick()
2014-06-12 20:46:00 +02:00
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
Directory . CreateDirectory ( Global . appdatapath ) ;
2014-05-31 06:37:02 +02:00
Global . Load ( ) ;
Global . setVersion ( version ) ;
2014-06-12 20:46:00 +02:00
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
{
2014-06-13 21:52:25 +02:00
Directory . CreateDirectory ( appdatapath ) ;
File . Copy ( exepath + "\\Profiles.xml" , appdatapath + "\\Profiles.xml" ) ;
File . Copy ( exepath + "\\Auto Profiles.xml" , appdatapath + "\\Auto Profiles.xml" ) ;
Directory . CreateDirectory ( appdatapath + "\\Profiles" ) ;
foreach ( string s in Directory . GetFiles ( exepath + "\\Profiles" ) )
2014-06-12 20:46:00 +02:00
{
2014-06-13 21:52:25 +02:00
File . Copy ( s , appdatapath + "\\Profiles\\" + Path . GetFileName ( s ) ) ;
2014-06-12 20:46:00 +02:00
}
}
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 ;
}
2014-06-02 05:19:04 +02:00
foreach ( ToolStripMenuItem t in shortcuts )
t . DropDownItemClicked + = Profile_Changed_Menu ;
2014-05-31 06:37:02 +02:00
hideDS4CheckBox . CheckedChanged - = hideDS4CheckBox_CheckedChanged ;
hideDS4CheckBox . Checked = Global . getUseExclusiveMode ( ) ;
2014-06-14 21:14:27 +02:00
hideDS4CheckBox . CheckedChanged + = hideDS4CheckBox_CheckedChanged ;
2014-05-31 06:37:02 +02:00
// New settings
this . Width = Global . getFormWidth ( ) ;
this . Height = Global . getFormHeight ( ) ;
startMinimizedCheckBox . CheckedChanged - = startMinimizedCheckBox_CheckedChanged ;
startMinimizedCheckBox . Checked = Global . getStartMinimized ( ) ;
startMinimizedCheckBox . CheckedChanged + = startMinimizedCheckBox_CheckedChanged ;
if ( startMinimizedCheckBox . Checked )
this . WindowState = FormWindowState . Minimized ;
2014-06-03 07:29:42 +02:00
Form_Resize ( sender , e ) ;
2014-05-31 06:37:02 +02:00
RefreshProfiles ( ) ;
for ( int i = 0 ; i < 4 ; i + + )
Global . LoadProfile ( i ) ;
2014-06-14 21:14:27 +02:00
LoadP ( ) ;
2014-05-31 06:37:02 +02:00
Global . ControllerStatusChange + = ControllerStatusChange ;
ControllerStatusChanged ( ) ;
if ( btnStartStop . Enabled )
btnStartStop_Clicked ( ) ;
2014-06-06 22:38:52 +02:00
cBNotifications . Checked = Global . getNotifications ( ) ;
int checkwhen = Global . getCheckWhen ( ) ;
cBUpdate . Checked = checkwhen > 0 ;
if ( checkwhen > 23 )
{
cBUpdateTime . SelectedIndex = 1 ;
nUDUpdateTime . Value = checkwhen / 24 ;
}
else
{
cBUpdateTime . SelectedIndex = 0 ;
nUDUpdateTime . Value = checkwhen ;
}
2014-05-31 06:37:02 +02:00
Uri url = new Uri ( "https://dl.dropboxusercontent.com/u/16364552/DS4Tool/newest%20version.txt" ) ; //Sorry other devs, gonna have to find your own server
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
2014-06-06 22:38:52 +02:00
if ( checkwhen > 0 & & DateTime . Now > = Global . getLastChecked ( ) + TimeSpan . FromHours ( checkwhen ) )
2014-05-31 06:37:02 +02:00
{
wc . DownloadFileAsync ( url , Global . appdatapath + "\\version.txt" ) ;
wc . DownloadFileCompleted + = Check_Version ;
Global . setLastChecked ( DateTime . Now ) ;
}
2014-06-06 22:38:52 +02:00
2014-06-13 21:52:25 +02:00
if ( File . Exists ( exepath + "\\Updater.exe" ) )
2014-06-06 22:38:52 +02:00
{
System . Threading . Thread . Sleep ( 2000 ) ;
2014-06-13 21:52:25 +02:00
File . Delete ( exepath + "\\Updater.exe" ) ;
2014-06-06 22:38:52 +02:00
}
2014-05-28 21:47:25 +02:00
//test.Start();
2014-06-02 05:19:04 +02:00
hotkeystimer . Start ( ) ;
hotkeystimer . Tick + = Hotkeys ;
2014-06-06 22:38:52 +02:00
test . Tick + = test_Tick ;
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
if ( ! System . IO . Directory . Exists ( Global . appdatapath + "\\Virtual Bus Driver" ) )
linkUninstall . Visible = false ;
2014-06-14 21:14:27 +02:00
StartWindowsCheckBox . Checked = File . Exists ( Environment . GetFolderPath ( Environment . SpecialFolder . Startup ) + "\\DS4Windows.lnk" ) ;
2014-05-28 21:47:25 +02:00
}
2014-06-06 22:38:52 +02:00
2014-06-02 19:29:38 +02:00
private void test_Tick ( object sender , EventArgs e )
{
2014-06-06 22:38:52 +02:00
lBTest . Visible = true ;
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
lBTest . Text = Mapping . getByteMapping ( DS4Controls . R1 , rootHub . getDS4State ( 0 ) ) . ToString ( ) + " " + rootHub . getDS4StateMapped ( 0 ) . R2 . ToString ( ) ;
//lBTest.Text = rootHub.getDS4StateMapped(0).L2.ToString();
2014-06-02 19:29:38 +02:00
}
2014-06-02 05:19:04 +02:00
void Hotkeys ( object sender , EventArgs e )
2014-05-28 21:47:25 +02:00
{
2014-06-02 05:19:04 +02:00
for ( int i = 0 ; i < 4 ; i + + )
{
string slide = rootHub . TouchpadSlide ( i ) ;
if ( slide = = "left" )
if ( cbs [ i ] . SelectedIndex < = 0 )
cbs [ i ] . SelectedIndex = cbs [ i ] . Items . Count - 2 ;
else
cbs [ i ] . SelectedIndex - - ;
else if ( slide = = "right" )
if ( cbs [ i ] . SelectedIndex = = cbs [ i ] . Items . Count - 2 )
cbs [ i ] . SelectedIndex = 0 ;
else
cbs [ i ] . SelectedIndex + + ;
if ( slide . Contains ( "t" ) )
ShowNotification ( this , "Controller " + ( i + 1 ) + " is now using Profile \"" + cbs [ i ] . Text + "\"" ) ;
}
2014-06-06 22:38:52 +02:00
//Check for process for auto profiles
2014-06-09 01:41:36 +02:00
if ( tempprofile = = "null" )
for ( int i = 0 ; i < programpaths . Count ; i + + )
{
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
string name = programpaths [ i ] . ToLower ( ) . Replace ( '/' , '\\' ) ;
if ( name = = GetTopWindowName ( ) . ToLower ( ) . Replace ( '/' , '\\' ) )
2014-06-09 01:41:36 +02:00
{
for ( int j = 0 ; j < 4 ; j + + )
if ( proprofiles [ j ] [ i ] ! = "(none)" )
Global . LoadTempProfile ( j , proprofiles [ j ] [ i ] ) ; //j is controller index, i is filename
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
tempprofile = name ;
2014-06-09 01:41:36 +02:00
}
}
else
{
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
if ( tempprofile ! = GetTopWindowName ( ) . ToLower ( ) . Replace ( '/' , '\\' ) )
2014-06-09 01:41:36 +02:00
{
tempprofile = "null" ;
for ( int j = 0 ; j < 4 ; j + + )
Global . LoadProfile ( j ) ;
}
}
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
if ( Process . GetProcessesByName ( "DS4Tool" ) . Length + Process . GetProcessesByName ( "DS4Windows" ) . Length > 1 )
{ //The second process closes and this one comes in focus
Show ( ) ;
WindowState = FormWindowState . Normal ;
ShowInTaskbar = true ;
Focus ( ) ;
}
2014-06-09 01:41:36 +02:00
#region Old Process check
/ * DateTime now = DateTime . UtcNow ;
if ( now > = oldnow + TimeSpan . FromSeconds ( 2 ) )
2014-06-06 22:38:52 +02:00
{
oldnow = now ;
if ( tempprofile = = "null" )
{
for ( int i = 0 ; i < programpaths . Count ; i + + )
{
string name = Path . GetFileNameWithoutExtension ( programpaths [ i ] ) ;
if ( Process . GetProcessesByName ( name ) . Length > 0 )
{
if ( programpaths [ i ] . ToLower ( ) = = Process . GetProcessesByName ( name ) [ 0 ] . Modules [ 0 ] . FileName . ToLower ( ) )
{
for ( int j = 0 ; j < 4 ; j + + )
if ( proprofiles [ j ] [ i ] ! = "(none)" )
Global . LoadTempProfile ( j , proprofiles [ j ] [ i ] ) ; //j is filename, i is controller index
tempprofile = name ;
filename = Process . GetProcessesByName ( name ) [ 0 ] . Modules [ 0 ] . FileName ;
break ;
}
}
}
}
else if ( Process . GetProcessesByName ( tempprofile ) . Length < = 0 )
{
for ( int j = 0 ; j < 4 ; j + + )
Global . LoadProfile ( j ) ;
tempprofile = "null" ;
}
PerformanceCounter . CloseSharedResources ( ) ;
}
else
2014-06-09 01:41:36 +02:00
PerformanceCounter . CloseSharedResources ( ) ; * /
#endregion
2014-06-06 22:38:52 +02:00
GC . Collect ( ) ;
}
public void LoadP ( )
{
XmlDocument doc = new XmlDocument ( ) ;
proprofiles = new List < string > [ 4 ] { new List < string > ( ) , new List < string > ( ) ,
new List < string > ( ) , new List < string > ( ) } ;
programpaths . Clear ( ) ;
if ( ! File . Exists ( Global . appdatapath + "\\Auto Profiles.xml" ) )
return ;
doc . Load ( Global . appdatapath + "\\Auto Profiles.xml" ) ;
XmlNodeList programslist = doc . SelectNodes ( "Programs/Program" ) ;
foreach ( XmlNode x in programslist )
programpaths . Add ( x . Attributes [ "path" ] . Value ) ;
foreach ( string s in programpaths )
for ( int i = 0 ; i < 4 ; i + + )
{
proprofiles [ i ] . Add ( doc . SelectSingleNode ( "/Programs/Program[@path=\"" + s + "\"]"
+ "/Controller" + ( i + 1 ) ) . InnerText ) ;
}
2014-05-28 04:49:58 +02:00
}
2014-05-21 07:36:05 +02:00
private void CheckDrivers ( )
{
bool deriverinstalled = false ;
ManagementObjectSearcher searcher = new ManagementObjectSearcher ( "SELECT * FROM Win32_PnPSignedDriver" ) ;
foreach ( ManagementObject obj in searcher . Get ( ) )
{
try
{
if ( obj . GetPropertyValue ( "DeviceName" ) . ToString ( ) = = "Scp Virtual Bus Driver" )
{
deriverinstalled = true ;
break ;
}
}
catch { }
}
if ( ! deriverinstalled )
{
WelcomeDialog wd = new WelcomeDialog ( ) ;
wd . ShowDialog ( ) ;
}
2014-05-14 09:12:15 +02:00
}
2014-05-30 22:39:39 +02:00
2014-05-14 09:12:15 +02:00
private void Check_Version ( object sender , System . ComponentModel . AsyncCompletedEventArgs e )
{
double newversion ;
2014-05-16 00:10:17 +02:00
try
2014-05-14 09:12:15 +02:00
{
2014-05-16 00:10:17 +02:00
if ( double . TryParse ( File . ReadAllText ( Global . appdatapath + "\\version.txt" ) , out newversion ) )
if ( newversion > version )
2014-06-06 22:38:52 +02:00
if ( MessageBox . Show ( "Download Version " + newversion + " now?" , "DS4Windows Update Available!" , MessageBoxButtons . YesNo , MessageBoxIcon . Question ) = = System . Windows . Forms . DialogResult . Yes )
2014-05-16 00:10:17 +02:00
{
2014-06-13 21:52:25 +02:00
if ( ! File . Exists ( exepath + "\\DS4Updater.exe" ) )
2014-05-21 19:39:56 +02:00
{
2014-06-06 22:38:52 +02:00
Uri url2 = new Uri ( "https://dl.dropboxusercontent.com/u/16364552/DS4Tool/DS4Updater.exe" ) ;
2014-05-21 19:39:56 +02:00
WebClient wc2 = new WebClient ( ) ;
2014-06-13 21:52:25 +02:00
if ( Global . appdatapath = = exepath )
wc2 . DownloadFile ( url2 , exepath + "\\DS4Updater.exe" ) ;
else
{
MessageBox . Show ( "Please Download the Updater now, and place it in the programs folder, then check for update again" ) ;
Process . Start ( "https://www.dropbox.com/s/tlqtdkdumdo0yir/DS4Updater.exe" ) ;
}
}
if ( Global . appdatapath = = exepath )
{
Process p = new Process ( ) ;
p . StartInfo . FileName = exepath + "\\DS4Updater.exe" ;
if ( Global . AdminNeeded ( ) )
p . StartInfo . Verb = "runas" ;
p . Start ( ) ;
Close ( ) ;
2014-05-21 19:39:56 +02:00
}
2014-05-16 00:10:17 +02:00
}
else
File . Delete ( Global . appdatapath + "\\version.txt" ) ;
2014-05-14 09:12:15 +02:00
else
2014-05-30 22:39:39 +02:00
File . Delete ( Global . appdatapath + "\\version.txt" ) ;
2014-05-14 09:12:15 +02:00
else
2014-05-16 00:10:17 +02:00
File . Delete ( Global . appdatapath + "\\version.txt" ) ;
}
2014-05-21 19:39:56 +02:00
catch { } ;
2014-03-28 02:50:40 +01:00
}
2014-06-09 01:41:36 +02:00
2014-04-27 21:32:09 +02:00
public void RefreshProfiles ( )
{
try
{
2014-05-28 21:47:25 +02:00
profilenames . Clear ( ) ;
2014-06-09 01:41:36 +02:00
string [ ] profiles = Directory . GetFiles ( Global . appdatapath + @"\Profiles\" ) ;
2014-04-29 03:14:01 +02:00
foreach ( String s in profiles )
if ( s . EndsWith ( ".xml" ) )
2014-05-21 07:36:05 +02:00
profilenames . Add ( Path . GetFileNameWithoutExtension ( s ) ) ;
2014-05-30 22:39:39 +02:00
lBProfiles . Items . Clear ( ) ;
lBProfiles . Items . AddRange ( profilenames . ToArray ( ) ) ;
2014-04-27 21:32:09 +02:00
for ( int i = 0 ; i < 4 ; i + + )
{
cbs [ i ] . Items . Clear ( ) ;
2014-04-29 03:14:01 +02:00
shortcuts [ i ] . DropDownItems . Clear ( ) ;
cbs [ i ] . Items . AddRange ( profilenames . ToArray ( ) ) ;
foreach ( string s in profilenames )
2014-05-21 07:36:05 +02:00
shortcuts [ i ] . DropDownItems . Add ( Path . GetFileNameWithoutExtension ( s ) ) ;
2014-04-29 03:14:01 +02:00
for ( int j = 0 ; j < cbs [ i ] . Items . Count ; j + + )
2014-05-21 07:36:05 +02:00
if ( cbs [ i ] . Items [ j ] . ToString ( ) = = Path . GetFileNameWithoutExtension ( Global . getAProfile ( i ) ) )
2014-04-27 21:32:09 +02:00
{
cbs [ i ] . SelectedIndex = j ;
2014-04-29 03:14:01 +02:00
( ( ToolStripMenuItem ) shortcuts [ i ] . DropDownItems [ j ] ) . Checked = true ;
Global . setAProfile ( i , cbs [ i ] . Text ) ;
2014-05-06 20:49:18 +02:00
shortcuts [ i ] . Text = "Edit Profile for Controller " + ( i + 1 ) ;
ebns [ i ] . Text = "Edit" ;
2014-04-27 21:32:09 +02:00
break ;
2014-04-29 03:14:01 +02:00
}
2014-05-06 20:49:18 +02:00
else
{
2014-05-19 07:55:12 +02:00
cbs [ i ] . Text = "(No Profile Loaded)" ;
2014-05-06 20:49:18 +02:00
shortcuts [ i ] . Text = "Make Profile for Controller " + ( i + 1 ) ;
ebns [ i ] . Text = "New" ;
}
2014-04-27 21:32:09 +02:00
}
}
catch ( DirectoryNotFoundException )
{
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
if ( Global . appdatapath = = Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location ) . FullName )
2014-04-27 21:32:09 +02:00
{
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
if ( Directory . Exists ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) + "\\DS4Tool" + @"\Profiles\" ) )
MessageBox . Show ( "Please import or make a profile" , "Profile Folder Moved to program folder" ) ;
Directory . CreateDirectory ( Global . appdatapath + @"\Profiles\" ) ;
for ( int i = 0 ; i < 4 ; i + + )
{
cbs [ i ] . Text = "(No Profile Loaded)" ;
shortcuts [ i ] . Text = "Make Profile for Controller " + ( i + 1 ) ;
ebns [ i ] . Text = "New" ;
}
}
else
{
if ( Directory . Exists ( Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location ) . FullName + @"\Profiles\" ) )
MessageBox . Show ( "Please import or make a profile" , "Profile Folder Moved" ) ;
Directory . CreateDirectory ( Global . appdatapath + @"\Profiles\" ) ;
for ( int i = 0 ; i < 4 ; i + + )
{
cbs [ i ] . Text = "(No Profile Loaded)" ;
shortcuts [ i ] . Text = "Make Profile for Controller " + ( i + 1 ) ;
ebns [ i ] . Text = "New" ;
}
2014-06-02 05:19:04 +02:00
}
}
finally
{
for ( int i = 0 ; i < 4 ; i + + )
{
2014-04-27 21:32:09 +02:00
cbs [ i ] . Items . Add ( "+New Profile" ) ;
2014-05-16 00:10:17 +02:00
shortcuts [ i ] . DropDownItems . Add ( "-" ) ;
shortcuts [ i ] . DropDownItems . Add ( "+New Profile" ) ;
2014-04-27 21:32:09 +02:00
}
2014-06-09 01:41:36 +02:00
RefreshAutoProfilesPage ( ) ;
}
2014-04-27 21:32:09 +02:00
}
2014-05-19 07:55:12 +02:00
2014-06-09 01:41:36 +02:00
2014-06-06 22:38:52 +02:00
public void RefreshAutoProfilesPage ( )
{
tabAutoProfiles . Controls . Clear ( ) ;
2014-06-09 01:41:36 +02:00
WP = new WinProgs ( profilenames . ToArray ( ) , this ) ;
2014-06-06 22:38:52 +02:00
WP . TopLevel = false ;
WP . FormBorderStyle = System . Windows . Forms . FormBorderStyle . None ;
WP . Visible = true ;
WP . Dock = DockStyle . Fill ;
tabAutoProfiles . Controls . Add ( WP ) ;
}
2014-05-19 07:55:12 +02:00
protected void LogDebug ( DateTime Time , String Data )
2014-03-28 02:50:40 +01:00
{
2014-05-19 07:55:12 +02:00
if ( lvDebug . InvokeRequired )
{
LogDebugDelegate d = new LogDebugDelegate ( LogDebug ) ;
try
{
this . Invoke ( d , new Object [ ] { Time , Data } ) ;
}
catch { }
}
else
{
2014-05-21 07:36:05 +02:00
String Posted = Time . ToString ( "G" ) ;
2014-05-19 07:55:12 +02:00
lvDebug . Items . Add ( new ListViewItem ( new String [ ] { Posted , Data } ) ) . EnsureVisible ( ) ;
//Added alternative
lbLastMessage . Text = Data ;
}
}
protected void ShowNotification ( object sender , DebugEventArgs args )
{
2014-06-06 22:38:52 +02:00
if ( Form . ActiveForm ! = this & & cBNotifications . Checked )
2014-05-28 04:49:58 +02:00
{
this . notifyIcon1 . BalloonTipText = args . Data ;
notifyIcon1 . BalloonTipTitle = "DS4Windows" ;
notifyIcon1 . ShowBalloonTip ( 1 ) ;
}
2014-05-19 07:55:12 +02:00
}
2014-05-30 22:39:39 +02:00
protected void ShowNotification ( object sender , string text )
{
2014-06-06 22:38:52 +02:00
if ( Form . ActiveForm ! = this & & cBNotifications . Checked )
2014-05-30 22:39:39 +02:00
{
this . notifyIcon1 . BalloonTipText = text ;
notifyIcon1 . BalloonTipTitle = "DS4Windows" ;
notifyIcon1 . ShowBalloonTip ( 1 ) ;
}
}
2014-05-19 07:55:12 +02:00
protected void Form_Resize ( object sender , EventArgs e )
{
if ( FormWindowState . Minimized = = this . WindowState )
{
this . Hide ( ) ;
this . ShowInTaskbar = false ;
}
2014-05-21 07:36:05 +02:00
2014-05-19 07:55:12 +02:00
else if ( FormWindowState . Normal = = this . WindowState )
{
this . Show ( ) ;
this . ShowInTaskbar = true ;
}
//Added last message alternative
2014-05-21 07:36:05 +02:00
2014-06-14 21:14:27 +02:00
/ * if ( this . Height > 220 )
2014-05-30 22:39:39 +02:00
lbLastMessage . Visible = tabMain . SelectedIndex ! = 2 ;
2014-06-14 21:14:27 +02:00
else lbLastMessage . Visible = true ; * /
2014-03-28 02:50:40 +01:00
}
protected void btnStartStop_Click ( object sender , EventArgs e )
2014-03-29 06:29:08 +01:00
{
btnStartStop_Clicked ( ) ;
}
protected void btnStartStop_Clicked ( )
2014-03-28 02:50:40 +01:00
{
2014-05-24 01:44:30 +02:00
if ( btnStartStop . Text = = "Start" )
{
rootHub . Start ( ) ;
2014-06-06 22:38:52 +02:00
hotkeystimer . Start ( ) ;
2014-05-24 01:44:30 +02:00
btnStartStop . Text = "Stop" ;
}
else if ( btnStartStop . Text = = "Stop" )
2014-06-02 05:19:04 +02:00
{
2014-05-24 01:44:30 +02:00
rootHub . Stop ( ) ;
2014-06-06 22:38:52 +02:00
hotkeystimer . Stop ( ) ;
2014-05-24 01:44:30 +02:00
btnStartStop . Text = "Start" ;
2014-03-28 02:50:40 +01:00
}
}
protected void btnClear_Click ( object sender , EventArgs e )
{
lvDebug . Items . Clear ( ) ;
//Added alternative
lbLastMessage . Text = string . Empty ;
}
2014-06-06 22:38:52 +02:00
2014-03-28 02:50:40 +01:00
protected override void WndProc ( ref Message m )
{
try
{
if ( m . Msg = = ScpDevice . WM_DEVICECHANGE )
{
Int32 Type = m . WParam . ToInt32 ( ) ;
lock ( this )
{
rootHub . HotPlug ( ) ;
}
}
}
catch { }
2014-06-02 19:29:38 +02:00
if ( m . Msg = = WM_QUERYENDSESSION )
systemShutdown = true ;
2014-03-28 02:50:40 +01:00
2014-06-02 19:29:38 +02:00
// If this is WM_QUERYENDSESSION, the closing event should be
// raised in the base WndProc.
2014-03-28 02:50:40 +01:00
base . WndProc ( ref m ) ;
}
2014-06-06 22:38:52 +02:00
2014-03-29 06:29:08 +01:00
protected void ControllerStatusChange ( object sender , EventArgs e )
{
if ( InvokeRequired )
Invoke ( new ControllerStatusChangedDelegate ( ControllerStatusChange ) , new object [ ] { sender , e } ) ;
else
ControllerStatusChanged ( ) ;
}
protected void ControllerStatusChanged ( )
{
2014-05-30 22:39:39 +02:00
String tooltip = "DS4Windows v" + version ;
2014-04-27 21:32:09 +02:00
for ( Int32 Index = 0 ; Index < Pads . Length ; Index + + )
2014-03-28 02:50:40 +01:00
{
2014-05-30 22:39:39 +02:00
Pads [ Index ] . Text = rootHub . getDS4MacAddress ( Index ) ;
switch ( rootHub . getDS4Status ( Index ) )
{
case "USB" : statPB [ Index ] . Image = Properties . Resources . USB ; break ;
case "BT" : statPB [ Index ] . Image = Properties . Resources . BT ; break ;
default : statPB [ Index ] . Image = Properties . Resources . none ; break ;
}
Batteries [ Index ] . Text = rootHub . getDS4Battery ( Index ) ;
2014-04-27 21:32:09 +02:00
if ( Pads [ Index ] . Text ! = String . Empty )
2014-03-28 02:50:40 +01:00
{
2014-04-27 21:32:09 +02:00
Pads [ Index ] . Enabled = true ;
2014-05-28 04:49:58 +02:00
if ( Pads [ Index ] . Text ! = "Connecting..." )
{
2014-05-31 06:37:02 +02:00
Enable_Controls ( Index , true ) ;
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
//MinimumSize = new Size(MinimumSize.Width, 137 + 29 * Index);
2014-05-28 04:49:58 +02:00
}
2014-03-28 02:50:40 +01:00
}
else
{
2014-04-27 21:32:09 +02:00
Pads [ Index ] . Text = "Disconnected" ;
2014-05-31 06:37:02 +02:00
Enable_Controls ( Index , false ) ;
2014-04-29 03:14:01 +02:00
shortcuts [ Index ] . Enabled = false ;
2014-03-28 02:50:40 +01:00
}
2014-04-30 21:32:44 +02:00
if ( rootHub . getShortDS4ControllerInfo ( Index ) ! = "None" )
tooltip + = "\n" + ( Index + 1 ) + ": " + rootHub . getShortDS4ControllerInfo ( Index ) ; // Carefully stay under the 63 character limit.
2014-03-28 02:50:40 +01:00
}
btnClear . Enabled = lvDebug . Items . Count > 0 ;
2014-04-27 21:32:09 +02:00
notifyIcon1 . Text = tooltip ;
2014-03-28 02:50:40 +01:00
}
2014-05-30 22:39:39 +02:00
2014-05-31 06:37:02 +02:00
private void Enable_Controls ( int device , bool on )
{
2014-05-31 19:27:43 +02:00
Pads [ device ] . Enabled = on ;
2014-05-31 06:37:02 +02:00
ebns [ device ] . Enabled = on ;
cbs [ device ] . Enabled = on ;
shortcuts [ device ] . Enabled = on ;
Batteries [ device ] . Enabled = on ;
}
2014-06-06 22:38:52 +02:00
2014-05-30 22:39:39 +02:00
void ScpForm_Report ( object sender , EventArgs e )
{
if ( InvokeRequired )
Invoke ( new HotKeysDelegate ( Hotkeys ) , new object [ ] { sender , e } ) ;
else
Hotkeys ( sender , e ) ;
}
2014-03-28 02:50:40 +01:00
protected void On_Debug ( object sender , DS4Control . DebugEventArgs e )
{
LogDebug ( e . Time , e . Data ) ;
}
2014-05-30 22:39:39 +02:00
private void lBProfiles_MouseDoubleClick ( object sender , MouseEventArgs e )
{
if ( lBProfiles . SelectedIndex > = 0 )
ShowOptions ( 4 , lBProfiles . SelectedItem . ToString ( ) ) ;
}
2014-05-31 06:37:02 +02:00
private void lBProfiles_KeyDown ( object sender , KeyEventArgs e )
{
if ( lBProfiles . SelectedIndex > = 0 & & opt = = null )
{
if ( e . KeyValue = = 13 )
ShowOptions ( 4 , lBProfiles . SelectedItem . ToString ( ) ) ;
if ( e . KeyValue = = 46 )
tsBDeleteProfle_Click ( this , e ) ;
if ( e . KeyValue = = 67 & & e . Modifiers = = Keys . Control )
tSBDupProfile_Click ( this , e ) ;
}
}
2014-05-31 19:27:43 +02:00
private void assignToController1ToolStripMenuItem_Click ( object sender , EventArgs e )
{
cbs [ 0 ] . SelectedIndex = lBProfiles . SelectedIndex ;
}
private void assignToController2ToolStripMenuItem_Click ( object sender , EventArgs e )
{
cbs [ 1 ] . SelectedIndex = lBProfiles . SelectedIndex ;
}
private void assignToController3ToolStripMenuItem_Click ( object sender , EventArgs e )
{
cbs [ 2 ] . SelectedIndex = lBProfiles . SelectedIndex ;
}
private void assignToController4ToolStripMenuItem_Click ( object sender , EventArgs e )
{
cbs [ 3 ] . SelectedIndex = lBProfiles . SelectedIndex ;
}
private void tsBNewProfile_Click ( object sender , EventArgs e ) //Also used for context menu
2014-05-30 22:39:39 +02:00
{
ShowOptions ( 4 , "" ) ;
}
private void tsBNEditProfile_Click ( object sender , EventArgs e )
{
if ( lBProfiles . SelectedIndex > = 0 )
ShowOptions ( 4 , lBProfiles . SelectedItem . ToString ( ) ) ;
}
private void tsBDeleteProfle_Click ( object sender , EventArgs e )
{
if ( lBProfiles . SelectedIndex > = 0 )
{
string filename = lBProfiles . SelectedItem . ToString ( ) ;
if ( MessageBox . Show ( "\"" + filename + "\" cannot be restored." , "Delete Profile?" , MessageBoxButtons . YesNo , MessageBoxIcon . Question ) = = System . Windows . Forms . DialogResult . Yes )
{
2014-06-13 21:52:25 +02:00
System . IO . File . Delete ( Global . appdatapath + @"\Profiles\" + filename + ".xml" ) ;
2014-05-30 22:39:39 +02:00
RefreshProfiles ( ) ;
}
}
}
private void tSBDupProfile_Click ( object sender , EventArgs e )
{
string filename = "" ;
if ( lBProfiles . SelectedIndex > = 0 )
{
filename = lBProfiles . SelectedItem . ToString ( ) ;
MessageTextBox MTB = new MessageTextBox ( filename , this ) ;
MTB . TopLevel = false ;
MTB . Dock = DockStyle . Top ;
MTB . Visible = true ;
MTB . FormBorderStyle = System . Windows . Forms . FormBorderStyle . None ;
tabProfiles . Controls . Add ( MTB ) ;
lBProfiles . SendToBack ( ) ;
toolStrip1 . SendToBack ( ) ;
toolStrip1 . Enabled = false ;
lBProfiles . Enabled = false ;
MTB . FormClosed + = delegate { toolStrip1 . Enabled = true ; lBProfiles . Enabled = true ; } ;
}
}
2014-05-31 06:37:02 +02:00
private void tSBImportProfile_Click ( object sender , EventArgs e )
{
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
if ( Global . appdatapath = = Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location ) . FullName )
openProfiles . InitialDirectory = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) + "\\DS4Tool" + @"\Profiles\" ;
else
openProfiles . InitialDirectory = Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location ) . FullName + @"\Profiles\" ;
2014-05-31 06:37:02 +02:00
if ( openProfiles . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK )
{
string [ ] files = openProfiles . FileNames ;
for ( int i = 0 ; i < files . Length ; i + + )
File . Copy ( openProfiles . FileNames [ i ] , Global . appdatapath + "\\Profiles\\" + Path . GetFileName ( files [ i ] ) , true ) ;
RefreshProfiles ( ) ;
}
}
private void tSBExportProfile_Click ( object sender , EventArgs e )
{
if ( lBProfiles . SelectedIndex > = 0 )
{
Stream stream ;
Stream profile = new StreamReader ( Global . appdatapath + "\\Profiles\\" + lBProfiles . SelectedItem . ToString ( ) + ".xml" ) . BaseStream ;
if ( saveProfiles . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK )
if ( ( stream = saveProfiles . OpenFile ( ) ) ! = null )
{
profile . CopyTo ( stream ) ;
profile . Close ( ) ;
stream . Close ( ) ;
}
}
}
2014-06-06 22:38:52 +02:00
2014-05-12 07:48:50 +02:00
private void ShowOptions ( int devID , string profile )
2014-03-28 02:50:40 +01:00
{
2014-05-30 22:39:39 +02:00
if ( opt = = null )
2014-03-28 02:50:40 +01:00
{
2014-05-30 22:39:39 +02:00
this . Show ( ) ;
WindowState = FormWindowState . Normal ;
toolStrip1 . Enabled = false ;
2014-06-02 19:29:38 +02:00
tSOptions . Visible = true ;
toolStrip1 . Visible = false ;
if ( profile ! = "" )
2014-06-03 07:29:42 +02:00
tSTBProfile . Text = profile ;
else
tSTBProfile . Text = "<type profile name here>" ;
2014-05-30 22:39:39 +02:00
opt = new Options ( rootHub , devID , profile , this ) ;
2014-05-12 07:48:50 +02:00
opt . Text = "Options for Controller " + ( devID + 1 ) ;
2014-05-05 09:31:24 +02:00
opt . Icon = this . Icon ;
2014-05-30 22:39:39 +02:00
opt . TopLevel = false ;
opt . FormBorderStyle = System . Windows . Forms . FormBorderStyle . None ;
opt . Visible = true ;
opt . Dock = DockStyle . Fill ;
tabProfiles . Controls . Add ( opt ) ;
lBProfiles . SendToBack ( ) ;
toolStrip1 . SendToBack ( ) ;
2014-06-02 19:29:38 +02:00
tSOptions . SendToBack ( ) ;
2014-05-30 22:39:39 +02:00
FormBorderStyle = System . Windows . Forms . FormBorderStyle . FixedSingle ;
opt . FormClosed + = delegate
{
opt = null ;
RefreshProfiles ( ) ;
FormBorderStyle = System . Windows . Forms . FormBorderStyle . Sizable ;
this . Size = oldsize ;
oldsize = new System . Drawing . Size ( 0 , 0 ) ;
2014-06-02 19:29:38 +02:00
tSOptions . Visible = false ;
toolStrip1 . Visible = true ;
2014-05-30 22:39:39 +02:00
toolStrip1 . Enabled = true ;
} ;
oldsize = this . Size ;
2014-06-03 07:29:42 +02:00
if ( dpix = = 120 )
{
2014-06-06 22:38:52 +02:00
if ( this . Size . Height < 518 )
this . Size = new System . Drawing . Size ( this . Size . Width , 518 ) ;
2014-06-03 07:29:42 +02:00
if ( this . Size . Width < 1125 )
this . Size = new System . Drawing . Size ( 1125 , this . Size . Height ) ;
}
else
{
2014-06-06 22:38:52 +02:00
if ( this . Size . Height < 418 )
this . Size = new System . Drawing . Size ( this . Size . Width , 418 ) ;
2014-06-03 07:29:42 +02:00
if ( this . Size . Width < 910 )
this . Size = new System . Drawing . Size ( 910 , this . Size . Height ) ;
}
2014-05-30 22:39:39 +02:00
tabMain . SelectedIndex = 1 ;
2014-05-05 09:31:24 +02:00
}
2014-04-29 03:14:01 +02:00
}
2014-06-06 22:38:52 +02:00
2014-05-12 07:48:50 +02:00
private void editButtons_Click ( object sender , EventArgs e )
{
Button bn = ( Button ) sender ;
int i = Int32 . Parse ( bn . Tag . ToString ( ) ) ;
2014-05-19 07:55:12 +02:00
if ( cbs [ i ] . Text = = "(No Profile Loaded)" )
2014-05-12 07:48:50 +02:00
ShowOptions ( i , "" ) ;
else
ShowOptions ( i , cbs [ i ] . Text ) ;
}
2014-06-06 22:38:52 +02:00
2014-04-29 03:14:01 +02:00
private void editMenu_Click ( object sender , EventArgs e )
{
ToolStripMenuItem em = ( ToolStripMenuItem ) sender ;
int i = Int32 . Parse ( em . Tag . ToString ( ) ) ;
2014-05-06 20:49:18 +02:00
if ( em . Text = = "Make Profile for Controller " + ( i + 1 ) )
2014-05-12 07:48:50 +02:00
ShowOptions ( i , "" ) ;
2014-05-06 20:49:18 +02:00
else
2014-05-12 07:48:50 +02:00
for ( int t = 0 ; t < em . DropDownItems . Count - 2 ; t + + )
if ( ( ( ToolStripMenuItem ) em . DropDownItems [ t ] ) . Checked )
ShowOptions ( i , ( ( ToolStripMenuItem ) em . DropDownItems [ t ] ) . Text ) ;
2014-04-29 03:14:01 +02:00
}
2014-05-30 22:39:39 +02:00
2014-03-28 02:50:40 +01:00
private void lnkControllers_LinkClicked ( object sender , LinkLabelLinkClickedEventArgs e )
{
System . Diagnostics . Process . Start ( "control" , "joy.cpl" ) ;
}
private void hideDS4CheckBox_CheckedChanged ( object sender , EventArgs e )
{
// Prevent the Game Controllers window from throwing an error when controllers are un/hidden
System . Diagnostics . Process [ ] rundll32 = System . Diagnostics . Process . GetProcessesByName ( "rundll32" ) ;
foreach ( System . Diagnostics . Process rundll32Instance in rundll32 )
foreach ( System . Diagnostics . ProcessModule module in rundll32Instance . Modules )
if ( module . FileName . Contains ( "joy.cpl" ) )
module . Dispose ( ) ;
Global . setUseExclusiveMode ( hideDS4CheckBox . Checked ) ;
2014-03-29 06:29:08 +01:00
btnStartStop_Clicked ( ) ;
btnStartStop_Clicked ( ) ;
2014-03-28 02:50:40 +01:00
Global . Save ( ) ;
}
2014-06-06 22:38:52 +02:00
2014-03-28 02:50:40 +01:00
private void startMinimizedCheckBox_CheckedChanged ( object sender , EventArgs e )
{
Global . setStartMinimized ( startMinimizedCheckBox . Checked ) ;
Global . Save ( ) ;
}
private void lvDebug_ItemActivate ( object sender , EventArgs e )
{
2014-04-30 02:58:18 +02:00
MessageBox . Show ( ( ( ListView ) sender ) . FocusedItem . SubItems [ 1 ] . Text , "Log" ) ;
2014-03-28 02:50:40 +01:00
}
2014-04-27 21:32:09 +02:00
2014-06-02 05:19:04 +02:00
private void Profile_Changed ( object sender , EventArgs e ) //cbs[i] changed
2014-04-27 21:32:09 +02:00
{
2014-04-29 03:14:01 +02:00
ComboBox cb = ( ComboBox ) sender ;
2014-04-27 21:32:09 +02:00
int tdevice = Int32 . Parse ( cb . Tag . ToString ( ) ) ;
if ( cb . Items [ cb . Items . Count - 1 ] . ToString ( ) = = "+New Profile" )
{
if ( cb . SelectedIndex < cb . Items . Count - 1 )
{
2014-04-29 03:14:01 +02:00
for ( int i = 0 ; i < shortcuts [ tdevice ] . DropDownItems . Count ; i + + )
2014-04-29 10:01:13 +02:00
if ( ! ( shortcuts [ tdevice ] . DropDownItems [ i ] is ToolStripSeparator ) )
2014-04-30 02:58:18 +02:00
( ( ToolStripMenuItem ) shortcuts [ tdevice ] . DropDownItems [ i ] ) . Checked = false ;
2014-04-29 03:14:01 +02:00
( ( ToolStripMenuItem ) shortcuts [ tdevice ] . DropDownItems [ cb . SelectedIndex ] ) . Checked = true ;
2014-05-07 06:46:36 +02:00
LogDebug ( DateTime . Now , "Controller " + ( tdevice + 1 ) + " is now using Profile \"" + cb . Text + "\"" ) ;
2014-05-06 20:49:18 +02:00
shortcuts [ tdevice ] . Text = "Edit Profile for Controller " + ( tdevice + 1 ) ;
2014-04-27 21:32:09 +02:00
Global . setAProfile ( tdevice , cb . Items [ cb . SelectedIndex ] . ToString ( ) ) ;
Global . Save ( ) ;
Global . LoadProfile ( tdevice ) ;
}
else if ( cb . SelectedIndex = = cb . Items . Count - 1 & & cb . Items . Count > 1 ) //if +New Profile selected
2014-05-12 07:48:50 +02:00
ShowOptions ( tdevice , "" ) ;
2014-05-19 07:55:12 +02:00
if ( cb . Text = = "(No Profile Loaded)" )
2014-04-29 03:14:01 +02:00
ebns [ tdevice ] . Text = "New" ;
else
ebns [ tdevice ] . Text = "Edit" ;
2014-04-27 21:32:09 +02:00
}
2014-06-02 05:19:04 +02:00
ControllerStatusChanged ( ) ; //to update profile name in notify icon
2014-04-29 03:14:01 +02:00
}
private void Profile_Changed_Menu ( object sender , ToolStripItemClickedEventArgs e )
{
ToolStripMenuItem tS = ( ToolStripMenuItem ) sender ;
int tdevice = Int32 . Parse ( tS . Tag . ToString ( ) ) ;
2014-04-29 10:01:13 +02:00
if ( ! ( e . ClickedItem is ToolStripSeparator ) )
2014-05-12 07:48:50 +02:00
if ( e . ClickedItem ! = tS . DropDownItems [ tS . DropDownItems . Count - 1 ] ) //if +New Profile not selected
2014-06-02 05:19:04 +02:00
cbs [ tdevice ] . SelectedIndex = tS . DropDownItems . IndexOf ( e . ClickedItem ) ;
2014-05-12 07:48:50 +02:00
else //if +New Profile selected
ShowOptions ( tdevice , "" ) ;
2014-04-29 03:14:01 +02:00
}
private void exitToolStripMenuItem_Click ( object sender , EventArgs e )
{
this . Close ( ) ;
}
private void openToolStripMenuItem_Click ( object sender , EventArgs e )
{
this . Show ( ) ;
WindowState = FormWindowState . Normal ;
2014-05-30 22:39:39 +02:00
}
2014-04-29 23:56:58 +02:00
2014-05-30 22:39:39 +02:00
private void notifyIcon1_MouseClick ( object sender , MouseEventArgs e )
2014-05-16 00:10:17 +02:00
{
2014-05-30 22:39:39 +02:00
if ( e . Button = = System . Windows . Forms . MouseButtons . Left )
2014-05-16 00:10:17 +02:00
{
2014-05-30 22:39:39 +02:00
this . Show ( ) ;
WindowState = FormWindowState . Normal ;
2014-05-16 00:10:17 +02:00
}
2014-05-30 22:39:39 +02:00
else if ( e . Button = = System . Windows . Forms . MouseButtons . Middle )
this . Close ( ) ;
}
private void notifyIcon1_BalloonTipClicked ( object sender , EventArgs e )
{
this . Show ( ) ;
WindowState = FormWindowState . Normal ;
2014-05-16 00:10:17 +02:00
}
private void llbHelp_LinkClicked ( object sender , LinkLabelLinkClickedEventArgs e )
{
2014-05-31 06:37:02 +02:00
Hotkeys hotkeysForm = new Hotkeys ( this ) ;
2014-05-16 00:10:17 +02:00
hotkeysForm . Icon = this . Icon ;
hotkeysForm . ShowDialog ( ) ;
}
2014-05-21 19:39:56 +02:00
private void StartWindowsCheckBox_CheckedChanged ( object sender , EventArgs e )
{
RegistryKey KeyLoc = Registry . CurrentUser . OpenSubKey ( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run" , true ) ;
2014-06-14 21:14:27 +02:00
if ( StartWindowsCheckBox . Checked & & ! File . Exists ( Environment . GetFolderPath ( Environment . SpecialFolder . Startup ) + "\\DS4Windows.lnk" ) )
2014-06-13 21:52:25 +02:00
appShortcutToStartup ( ) ;
2014-06-14 21:14:27 +02:00
else if ( ! StartWindowsCheckBox . Checked )
2014-06-13 21:52:25 +02:00
File . Delete ( Environment . GetFolderPath ( Environment . SpecialFolder . Startup ) + "\\DS4Windows.lnk" ) ;
KeyLoc . DeleteValue ( "DS4Tool" , false ) ;
}
private void appShortcutToStartup ( )
{
Type t = Type . GetTypeFromCLSID ( new Guid ( "72C24DD5-D70A-438B-8A42-98424B88AFB8" ) ) ; //Windows Script Host Shell Object
dynamic shell = Activator . CreateInstance ( t ) ;
try
{
var lnk = shell . CreateShortcut ( Environment . GetFolderPath ( Environment . SpecialFolder . Startup ) + "\\DS4Windows.lnk" ) ;
try
{
string app = Assembly . GetExecutingAssembly ( ) . Location ;
lnk . TargetPath = Assembly . GetExecutingAssembly ( ) . Location ;
lnk . IconLocation = app . Replace ( '\\' , '/' ) ;
lnk . Save ( ) ;
}
finally
{
Marshal . FinalReleaseComObject ( lnk ) ;
}
}
finally
{
Marshal . FinalReleaseComObject ( shell ) ;
}
2014-05-21 19:39:56 +02:00
}
2014-05-31 06:37:02 +02:00
private void tabMain_SelectedIndexChanged ( object sender , EventArgs e )
2014-05-30 22:39:39 +02:00
{
lbLastMessage . Visible = tabMain . SelectedIndex ! = 2 ;
}
2014-05-31 19:27:43 +02:00
private void lBProfiles_MouseDown ( object sender , MouseEventArgs e )
{
lBProfiles . SelectedIndex = lBProfiles . IndexFromPoint ( e . X , e . Y ) ;
if ( e . Button = = System . Windows . Forms . MouseButtons . Right )
{
if ( lBProfiles . SelectedIndex < 0 )
{
2014-06-02 05:19:04 +02:00
cMProfile . ShowImageMargin = false ;
2014-05-31 19:27:43 +02:00
assignToController1ToolStripMenuItem . Visible = false ;
assignToController2ToolStripMenuItem . Visible = false ;
assignToController3ToolStripMenuItem . Visible = false ;
assignToController4ToolStripMenuItem . Visible = false ;
deleteToolStripMenuItem . Visible = false ;
editToolStripMenuItem . Visible = false ;
duplicateToolStripMenuItem . Visible = false ;
exportToolStripMenuItem . Visible = false ;
}
else
{
2014-06-02 05:19:04 +02:00
cMProfile . ShowImageMargin = true ;
2014-05-31 19:27:43 +02:00
assignToController1ToolStripMenuItem . Visible = true ;
assignToController2ToolStripMenuItem . Visible = true ;
assignToController3ToolStripMenuItem . Visible = true ;
assignToController4ToolStripMenuItem . Visible = true ;
2014-06-02 05:19:04 +02:00
ToolStripMenuItem [ ] assigns = { assignToController1ToolStripMenuItem ,
assignToController2ToolStripMenuItem ,
assignToController3ToolStripMenuItem ,
assignToController4ToolStripMenuItem } ;
for ( int i = 0 ; i < 4 ; i + + )
{
if ( lBProfiles . SelectedIndex = = cbs [ i ] . SelectedIndex )
assigns [ i ] . Checked = true ;
else
assigns [ i ] . Checked = false ;
}
2014-05-31 19:27:43 +02:00
deleteToolStripMenuItem . Visible = true ;
editToolStripMenuItem . Visible = true ;
duplicateToolStripMenuItem . Visible = true ;
exportToolStripMenuItem . Visible = true ;
}
}
}
2014-06-02 05:19:04 +02:00
private void ScpForm_DragDrop ( object sender , DragEventArgs e )
{
bool therewasanxml = false ;
string [ ] files = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop , false ) ;
for ( int i = 0 ; i < files . Length ; i + + )
if ( files [ i ] . EndsWith ( ".xml" ) )
{
File . Copy ( files [ i ] , Global . appdatapath + "\\Profiles\\" + Path . GetFileName ( files [ i ] ) , true ) ;
therewasanxml = true ;
}
if ( therewasanxml )
RefreshProfiles ( ) ;
}
private void ScpForm_DragEnter ( object sender , DragEventArgs e )
{
if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) )
e . Effect = DragDropEffects . Copy ; // Okay
else
e . Effect = DragDropEffects . None ; // Unknown data, ignore it
}
2014-06-12 20:46:00 +02:00
2014-06-02 19:29:38 +02:00
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 ( "|" ) )
tSTBProfile . ForeColor = System . Drawing . SystemColors . WindowText ;
else
tSTBProfile . ForeColor = System . Drawing . SystemColors . GrayText ;
}
private void tBProfile_Enter ( object sender , EventArgs e )
{
if ( tSTBProfile . Text = = "<type profile name here>" )
tSTBProfile . Text = "" ;
}
private void tBProfile_Leave ( object sender , EventArgs e )
{
if ( tSTBProfile . Text = = "" )
tSTBProfile . Text = "<type profile name here>" ;
}
private void tSBCancel_Click ( object sender , EventArgs e )
{
if ( opt ! = null )
opt . Close ( ) ;
}
2014-06-13 21:52:25 +02:00
private void tSBSaveProfile_Click ( object sender , EventArgs e )
2014-06-02 19:29:38 +02:00
{
if ( opt ! = null )
{
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 ( "|" ) )
{
System . IO . File . Delete ( Global . appdatapath + @"\Profiles\" + opt . filename + ".xml" ) ;
Global . setAProfile ( opt . device , tSTBProfile . Text ) ;
Global . SaveProfile ( opt . device , tSTBProfile . Text , opt . buttons . ToArray ( ) ) ;
Global . Save ( ) ;
opt . Close ( ) ;
}
else
MessageBox . Show ( "Please enter a valid name" , "Not valid" , MessageBoxButtons . OK , MessageBoxIcon . Exclamation ) ;
}
}
2014-06-06 22:38:52 +02:00
private void cBUpdate_CheckedChanged ( object sender , EventArgs e )
{
if ( ! cBUpdate . Checked )
{
nUDUpdateTime . Value = 0 ;
pNUpdate . Enabled = false ;
}
else
{
nUDUpdateTime . Value = 1 ;
cBUpdateTime . SelectedIndex = 0 ;
pNUpdate . Enabled = true ;
}
}
private void nUDUpdateTime_ValueChanged ( object sender , EventArgs e )
{
if ( cBUpdateTime . SelectedIndex = = 0 )
Global . setCheckWhen ( ( int ) nUDUpdateTime . Value ) ;
else if ( cBUpdateTime . SelectedIndex = = 1 )
Global . setCheckWhen ( ( int ) nUDUpdateTime . Value * 24 ) ;
if ( nUDUpdateTime . Value < 1 )
cBUpdate . Checked = false ;
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
if ( nUDUpdateTime . Value = = 1 )
{
int index = cBUpdateTime . SelectedIndex ;
cBUpdateTime . Items . Clear ( ) ;
cBUpdateTime . Items . Add ( "hour" ) ;
cBUpdateTime . Items . Add ( "day" ) ;
cBUpdateTime . SelectedIndex = index ;
}
else if ( cBUpdateTime . Items [ 0 ] . ToString ( ) = = "hour" )
{
int index = cBUpdateTime . SelectedIndex ;
cBUpdateTime . Items . Clear ( ) ;
cBUpdateTime . Items . Add ( "hours" ) ;
cBUpdateTime . Items . Add ( "days" ) ;
cBUpdateTime . SelectedIndex = index ;
}
2014-06-06 22:38:52 +02:00
}
private void cBUpdateTime_SelectedIndexChanged ( object sender , EventArgs e )
{
if ( cBUpdateTime . SelectedIndex = = 0 )
Global . setCheckWhen ( ( int ) nUDUpdateTime . Value ) ;
else if ( cBUpdateTime . SelectedIndex = = 1 )
Global . setCheckWhen ( ( int ) nUDUpdateTime . Value * 24 ) ;
}
private void lLBUpdate_LinkClicked ( object sender , LinkLabelLinkClickedEventArgs e )
{
Uri url = new Uri ( "https://dl.dropboxusercontent.com/u/16364552/DS4Tool/newest%20version.txt" ) ; //Sorry other devs, gonna have to find your own server
WebClient wct = new WebClient ( ) ;
wct . DownloadFileAsync ( url , Global . appdatapath + "\\version.txt" ) ;
wct . DownloadFileCompleted + = wct_DownloadFileCompleted ;
}
void wct_DownloadFileCompleted ( object sender , System . ComponentModel . AsyncCompletedEventArgs e )
{
Global . setLastChecked ( DateTime . Now ) ;
double newversion ;
try
{
if ( double . TryParse ( File . ReadAllText ( Global . appdatapath + "\\version.txt" ) , out newversion ) )
if ( newversion > Global . getVersion ( ) )
if ( MessageBox . Show ( "Download Version " + newversion + " now?" , "DS4Windows Update Available!" , MessageBoxButtons . YesNo , MessageBoxIcon . Question ) = = System . Windows . Forms . DialogResult . Yes )
{
2014-06-13 21:52:25 +02:00
if ( ! File . Exists ( exepath + "\\DS4Updater.exe" ) )
2014-06-06 22:38:52 +02:00
{
Uri url2 = new Uri ( "https://dl.dropboxusercontent.com/u/16364552/DS4Tool/DS4Updater.exe" ) ;
WebClient wc2 = new WebClient ( ) ;
2014-06-13 21:52:25 +02:00
if ( Global . appdatapath = = exepath )
wc2 . DownloadFile ( url2 , exepath + "\\DS4Updater.exe" ) ;
else
{
MessageBox . Show ( "Please Download the Updater now, and place it in the programs folder, then check for update again" ) ;
Process . Start ( "https://www.dropbox.com/s/tlqtdkdumdo0yir/DS4Updater.exe" ) ;
}
}
if ( Global . appdatapath = = exepath )
{
Process p = new Process ( ) ;
p . StartInfo . FileName = exepath + "\\DS4Updater.exe" ;
if ( Global . AdminNeeded ( ) )
p . StartInfo . Verb = "runas" ;
p . Start ( ) ;
Close ( ) ;
2014-06-06 22:38:52 +02:00
}
}
else
File . Delete ( Global . appdatapath + "\\version.txt" ) ;
else
{
File . Delete ( Global . appdatapath + "\\version.txt" ) ;
MessageBox . Show ( "You are up to date" , "DS4 Updater" ) ;
}
else
File . Delete ( Global . appdatapath + "\\version.txt" ) ;
}
catch { } ;
}
private void linkProfiles_LinkClicked ( object sender , LinkLabelLinkClickedEventArgs e )
{
System . Diagnostics . Process . Start ( Global . appdatapath + "\\Profiles" ) ;
}
private void linkUninstall_LinkClicked ( object sender , LinkLabelLinkClickedEventArgs e )
{
2014-06-13 21:52:25 +02:00
if ( File . Exists ( Global . appdatapath + "\\Virtual Bus Driver\\ScpDriver.exe" ) )
2014-06-06 22:38:52 +02:00
try { System . Diagnostics . Process . Start ( Global . appdatapath + "\\Virtual Bus Driver\\ScpDriver.exe" ) ; }
catch { System . Diagnostics . Process . Start ( Global . appdatapath + "\\Virtual Bus Driver" ) ; }
}
private void cBNotifications_CheckedChanged ( object sender , EventArgs e )
{
Global . setNotifications ( cBNotifications . Checked ) ;
}
2014-06-09 01:41:36 +02:00
private void lLSetup_LinkClicked ( object sender , LinkLabelLinkClickedEventArgs e )
{
WelcomeDialog wd = new WelcomeDialog ( ) ;
wd . ShowDialog ( ) ;
}
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
2014-06-13 21:52:25 +02:00
protected void ScpForm_Closing ( object sender , FormClosingEventArgs e )
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
{
2014-06-13 21:52:25 +02:00
if ( opt ! = null )
{
opt . Close ( ) ;
e . Cancel = true ;
return ;
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
}
2014-06-12 20:46:00 +02:00
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 ( ) ;
}
}
2014-03-28 02:50:40 +01:00
}
public class ThemeUtil
{
[DllImport("UxTheme", CharSet = CharSet.Unicode, ExactSpelling = true)]
private static extern int SetWindowTheme ( IntPtr hWnd , String appName , String partList ) ;
public static void SetTheme ( ListView lv )
{
try
{
SetWindowTheme ( lv . Handle , "Explorer" , null ) ;
}
catch { }
}
public static void SetTheme ( TreeView tv )
{
try
{
SetWindowTheme ( tv . Handle , "Explorer" , null ) ;
}
catch { }
}
}
}