2014-03-28 02:50:40 +01:00
using System ;
using System.Windows.Forms ;
using System.Runtime.InteropServices ;
using DS4Control ;
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-21 19:39:56 +02:00
using Microsoft.Win32 ;
2014-03-28 02:50:40 +01:00
namespace ScpServer
{
public partial class ScpForm : Form
{
2014-05-24 04:30:43 +02:00
double version = 7.6 ;
2014-03-28 02:50:40 +01:00
private DS4Control . Control rootHub ;
delegate void LogDebugDelegate ( DateTime Time , String Data ) ;
2014-04-27 21:32:09 +02:00
protected Label [ ] Pads ;
protected ComboBox [ ] cbs ;
protected Button [ ] ebns ;
protected Button [ ] dbns ;
protected Label [ ] protexts ;
2014-04-29 03:14:01 +02:00
protected ToolStripMenuItem [ ] shortcuts ;
2014-05-14 09:12:15 +02:00
WebClient wc = new WebClient ( ) ;
2014-03-28 02:50:40 +01:00
public ScpForm ( )
{
InitializeComponent ( ) ;
ThemeUtil . SetTheme ( lvDebug ) ;
2014-04-27 21:32:09 +02:00
Pads = new Label [ 4 ] { lbPad1 , lbPad2 , lbPad3 , lbPad4 } ;
cbs = new ComboBox [ 4 ] { cBController1 , cBController2 , cBController3 , cBController4 } ;
ebns = new Button [ 4 ] { bnEditC1 , bnEditC2 , bnEditC3 , bnEditC4 } ;
dbns = new Button [ 4 ] { bnDeleteC1 , bnDeleteC2 , bnDeleteC3 , bnDeleteC4 } ;
protexts = new Label [ 4 ] { lbSelPro1 , lbSelPro2 , lbSelPro3 , lbSelPro4 } ;
2014-05-17 21:53:46 +02:00
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-04-29 03:14:01 +02:00
foreach ( ToolStripMenuItem t in shortcuts )
t . DropDownItemClicked + = Profile_Changed_Menu ;
2014-05-21 23:42:25 +02:00
CheckDrivers ( ) ;
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-16 00:10:17 +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 )
if ( MessageBox . Show ( "Download now?" , "New Version Available!" , MessageBoxButtons . YesNo , MessageBoxIcon . Question ) = = System . Windows . Forms . DialogResult . Yes )
{
2014-05-21 19:39:56 +02:00
if ( ! File . Exists ( "Updater.exe" ) )
{
Uri url2 = new Uri ( "https://dl.dropboxusercontent.com/u/16364552/DS4Tool/Updater.exe" ) ;
WebClient wc2 = new WebClient ( ) ;
wc2 . DownloadFile ( url2 , "Updater.exe" ) ;
}
2014-05-16 00:10:17 +02:00
System . Diagnostics . Process . Start ( "Updater.exe" ) ;
this . Close ( ) ;
}
else
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-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
}
protected void Form_Load ( object sender , EventArgs e )
{
Icon = Properties . Resources . DS4 ;
notifyIcon1 . Icon = Properties . Resources . DS4 ;
rootHub = new DS4Control . Control ( ) ;
rootHub . Debug + = On_Debug ;
Log . GuiLog + = On_Debug ;
Log . TrayIconLog + = ShowNotification ;
2014-03-29 06:29:08 +01:00
// tmrUpdate.Enabled = true; TODO remove tmrUpdate and leave tick()
2014-03-28 02:50:40 +01:00
Global . Load ( ) ;
2014-05-17 21:53:46 +02:00
Global . setVersion ( version ) ;
Global . Save ( ) ;
2014-03-28 02:50:40 +01:00
hideDS4CheckBox . CheckedChanged - = hideDS4CheckBox_CheckedChanged ;
hideDS4CheckBox . Checked = Global . getUseExclusiveMode ( ) ;
hideDS4CheckBox . CheckedChanged + = hideDS4CheckBox_CheckedChanged ;
// New settings
this . Width = Global . getFormWidth ( ) ;
this . Height = Global . getFormHeight ( ) ;
startMinimizedCheckBox . CheckedChanged - = startMinimizedCheckBox_CheckedChanged ;
startMinimizedCheckBox . Checked = Global . getStartMinimized ( ) ;
startMinimizedCheckBox . CheckedChanged + = startMinimizedCheckBox_CheckedChanged ;
2014-05-21 19:39:56 +02:00
RegistryKey KeyLoc = Registry . CurrentUser . OpenSubKey ( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run" , false ) ;
StartWindowsCheckBox . Checked = ( KeyLoc . GetValue ( "DS4Tool" ) ! = null ) ;
2014-05-23 04:42:07 +02:00
Pads = new Label [ 4 ] { lbPad1 , lbPad2 , lbPad3 , lbPad4 } ;
cbs = new ComboBox [ 4 ] { cBController1 , cBController2 , cBController3 , cBController4 } ;
ebns = new Button [ 4 ] { bnEditC1 , bnEditC2 , bnEditC3 , bnEditC4 } ;
dbns = new Button [ 4 ] { bnDeleteC1 , bnDeleteC2 , bnDeleteC3 , bnDeleteC4 } ;
protexts = new Label [ 4 ] { lbSelPro1 , lbSelPro2 , lbSelPro3 , lbSelPro4 } ;
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-03-28 02:50:40 +01:00
if ( startMinimizedCheckBox . Checked )
{
this . WindowState = FormWindowState . Minimized ;
Form_Resize ( sender , e ) ;
}
2014-04-27 21:32:09 +02:00
RefreshProfiles ( ) ;
for ( int i = 0 ; i < 4 ; i + + )
2014-04-29 10:01:13 +02:00
Global . LoadProfile ( i ) ;
2014-03-29 06:29:08 +01:00
Global . ControllerStatusChange + = ControllerStatusChange ;
ControllerStatusChanged ( ) ;
if ( btnStartStop . Enabled )
btnStartStop_Clicked ( ) ;
2014-05-21 19:39:56 +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
Directory . CreateDirectory ( Global . appdatapath ) ;
if ( DateTime . Now > = Global . getLastChecked ( ) + TimeSpan . FromHours ( 1 ) )
{
wc . DownloadFileAsync ( url , Global . appdatapath + "\\version.txt" ) ;
wc . DownloadFileCompleted + = Check_Version ;
Global . setLastChecked ( DateTime . Now ) ;
}
2014-03-28 02:50:40 +01:00
}
2014-04-27 21:32:09 +02:00
public void RefreshProfiles ( )
{
try
{
2014-05-21 07:36:05 +02:00
string [ ] profiles = Directory . GetFiles ( Global . appdatapath + @"\Profiles\" ) ;
2014-04-29 03:14:01 +02:00
List < string > profilenames = new List < string > ( ) ;
foreach ( String s in profiles )
if ( s . EndsWith ( ".xml" ) )
2014-05-21 07:36:05 +02:00
profilenames . Add ( Path . GetFileNameWithoutExtension ( s ) ) ;
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
cbs [ i ] . Items . Add ( "+New Profile" ) ;
2014-04-29 10:01:13 +02:00
shortcuts [ i ] . DropDownItems . Add ( "-" ) ;
2014-04-29 03:14:01 +02:00
shortcuts [ i ] . DropDownItems . Add ( "+New Profile" ) ;
2014-04-27 21:32:09 +02:00
}
}
catch ( DirectoryNotFoundException )
{
2014-05-16 00:10:17 +02:00
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\" ) ;
2014-04-27 21:32:09 +02:00
for ( int i = 0 ; i < 4 ; i + + )
{
2014-05-19 07:55:12 +02:00
cbs [ i ] . Text = "(No Profile Loaded)" ;
2014-05-16 00:10:17 +02:00
shortcuts [ i ] . Text = "Make Profile for Controller " + ( i + 1 ) ;
ebns [ i ] . Text = "New" ;
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-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 )
{
notifyIcon1 . BalloonTipText = args . Data ;
notifyIcon1 . BalloonTipTitle = "DS4Windows" ;
notifyIcon1 . ShowBalloonTip ( 1 ) ;
}
protected void Form_Resize ( object sender , EventArgs e )
{
if ( FormWindowState . Minimized = = this . WindowState )
{
notifyIcon1 . Visible = true ;
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 )
{
notifyIcon1 . Visible = false ;
this . Show ( ) ;
this . ShowInTaskbar = true ;
}
2014-05-21 07:36:05 +02:00
2014-05-19 07:55:12 +02:00
//Added last message alternative
2014-05-21 07:36:05 +02:00
2014-05-19 07:55:12 +02:00
if ( this . Height > 220 )
lbLastMessage . Visible = false ;
else lbLastMessage . Visible = true ;
2014-05-21 07:36:05 +02:00
if ( protexts ! = null )
for ( int i = 0 ; i < 4 ; i + + )
2014-05-24 01:44:30 +02:00
protexts [ i ] . Visible = ( this . Width > 665 ) ;
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" )
{
for ( int i = 0 ; i < 4 ; i + + )
Global . LoadProfile ( i ) ;
rootHub . Start ( ) ;
btnStartStop . Text = "Stop" ;
}
else if ( btnStartStop . Text = = "Stop" )
2014-03-28 02:50:40 +01:00
{
2014-05-24 01:44:30 +02:00
for ( int i = 0 ; i < 4 ; i + + )
{
Global . setRainbow ( i , 0 ) ;
Global . setLedAsBatteryIndicator ( i , false ) ;
Global . saveColor ( i , 128 , 255 , 255 ) ;
}
rootHub . Stop ( ) ;
btnStartStop . Text = "Start" ;
2014-03-28 02:50:40 +01:00
}
}
2014-05-24 01:44:30 +02:00
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 ;
}
protected override void WndProc ( ref Message m )
{
try
{
if ( m . Msg = = ScpDevice . WM_DEVICECHANGE )
{
Int32 Type = m . WParam . ToInt32 ( ) ;
lock ( this )
{
rootHub . HotPlug ( ) ;
}
}
}
catch { }
base . WndProc ( ref m ) ;
}
2014-03-29 06:29:08 +01:00
delegate void ControllerStatusChangedDelegate ( object sender , EventArgs e ) ;
protected void ControllerStatusChange ( object sender , EventArgs e )
{
if ( InvokeRequired )
Invoke ( new ControllerStatusChangedDelegate ( ControllerStatusChange ) , new object [ ] { sender , e } ) ;
else
ControllerStatusChanged ( ) ;
}
protected void ControllerStatusChanged ( )
{
2014-03-28 02:50:40 +01:00
// If controllers are detected, but not checked, automatically check #1
2014-04-27 21:32:09 +02:00
//bool checkFirst = true;
String tooltip = "DS4Windows" ;
for ( Int32 Index = 0 ; Index < Pads . Length ; Index + + )
2014-03-28 02:50:40 +01:00
{
2014-04-27 21:32:09 +02:00
Pads [ Index ] . Text = rootHub . getDS4ControllerInfo ( Index ) ;
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 ;
cbs [ Index ] . Enabled = true ;
ebns [ Index ] . Enabled = true ;
dbns [ Index ] . Enabled = true ;
2014-04-30 02:58:18 +02:00
protexts [ Index ] . Enabled = true ;
2014-04-29 03:14:01 +02:00
shortcuts [ Index ] . Enabled = true ;
2014-03-28 02:50:40 +01:00
// As above
2014-04-27 21:32:09 +02:00
//if (checkFirst && (Pads[Index].Checked && Index != 0))
2014-04-30 02:58:18 +02:00
// checkFirst = false;
2014-03-28 02:50:40 +01:00
}
else
{
2014-04-27 21:32:09 +02:00
Pads [ Index ] . Text = "Disconnected" ;
Pads [ Index ] . Enabled = false ;
cbs [ Index ] . Enabled = false ;
ebns [ Index ] . Enabled = false ;
dbns [ Index ] . Enabled = false ;
protexts [ Index ] . Enabled = false ;
if ( OptionsDialog [ Index ] ! = null )
OptionsDialog [ Index ] . Close ( ) ;
2014-04-29 03:14:01 +02:00
shortcuts [ Index ] . Enabled = false ;
2014-03-28 02:50:40 +01:00
// As above
2014-04-27 21:32:09 +02:00
//if (Index == 0)
2014-04-30 02:58:18 +02:00
// checkFirst = 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 ;
// As above
2014-04-27 21:32:09 +02:00
//if (checkFirst && btnClear.Enabled)
2014-04-30 02:58:18 +02:00
// Pads[0].Checked = true;
2014-04-27 21:32:09 +02:00
notifyIcon1 . Text = tooltip ;
2014-03-28 02:50:40 +01:00
}
protected void On_Debug ( object sender , DS4Control . DebugEventArgs e )
{
LogDebug ( e . Time , e . Data ) ;
}
2014-04-27 21:32:09 +02:00
private Options [ ] OptionsDialog = { null , null , null , null } ;
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-12 07:48:50 +02:00
if ( OptionsDialog [ devID ] = = null )
2014-03-28 02:50:40 +01:00
{
2014-05-06 20:49:18 +02:00
Options opt ;
2014-05-12 07:48:50 +02:00
opt = OptionsDialog [ devID ] = new Options ( rootHub , devID , profile ) ;
opt . Text = "Options for Controller " + ( devID + 1 ) ;
2014-05-05 09:31:24 +02:00
opt . Icon = this . Icon ;
2014-05-12 07:48:50 +02:00
opt . FormClosed + = delegate { OptionsDialog [ devID ] = null ; RefreshProfiles ( ) ; } ;
2014-05-05 09:31:24 +02:00
opt . Show ( ) ;
}
2014-04-29 03:14:01 +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-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
}
private void Enable_Controls ( int device , bool on )
{
ebns [ device ] . Enabled = on ;
dbns [ device ] . Enabled = on ;
cbs [ device ] . Enabled = on ;
shortcuts [ device ] . Enabled = on ;
2014-04-27 21:32:09 +02:00
}
private void deleteButtons_Click ( object sender , EventArgs e )
{
Button bn = ( Button ) sender ;
int tdevice = Int32 . Parse ( bn . Tag . ToString ( ) ) ;
string filename = cbs [ tdevice ] . Items [ cbs [ tdevice ] . SelectedIndex ] . ToString ( ) ;
if ( MessageBox . Show ( "\"" + filename + "\" cannot be restored." , "Delete Profile?" , MessageBoxButtons . YesNo , MessageBoxIcon . Question ) = = System . Windows . Forms . DialogResult . Yes )
{
2014-05-22 21:13:38 +02:00
System . IO . File . Delete ( Global . appdatapath + "\\Profiles\\" + filename + ".xml" ) ;
2014-04-27 21:32:09 +02:00
Global . setAProfile ( tdevice , null ) ;
RefreshProfiles ( ) ;
2014-03-28 02:50:40 +01:00
}
}
2014-04-27 21:32:09 +02:00
2014-03-28 02:50:40 +01:00
private void hotkeysButton_Click ( object sender , EventArgs e )
{
Hotkeys hotkeysForm = new Hotkeys ( ) ;
hotkeysForm . Icon = this . Icon ;
hotkeysForm . ShowDialog ( ) ;
}
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 ( ) ;
}
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
private void Profile_Changed ( object sender , EventArgs e )
{
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-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
if ( ( ( ToolStripMenuItem ) e . ClickedItem ) . Checked )
ShowOptions ( tdevice , e . ClickedItem . Text ) ;
2014-04-29 10:01:13 +02:00
else
{
for ( int i = 0 ; i < tS . DropDownItems . Count ; i + + )
2014-04-30 02:58:18 +02:00
if ( ! ( shortcuts [ tdevice ] . DropDownItems [ i ] is ToolStripSeparator ) )
( ( ToolStripMenuItem ) tS . DropDownItems [ i ] ) . Checked = false ;
2014-04-29 10:01:13 +02:00
( ( ToolStripMenuItem ) e . ClickedItem ) . Checked = true ;
2014-05-06 20:49:18 +02:00
shortcuts [ tdevice ] . Text = "Edit Profile for Controller " + ( tdevice + 1 ) ;
2014-04-29 10:01:13 +02:00
cbs [ tdevice ] . SelectedIndex = tS . DropDownItems . IndexOf ( e . ClickedItem ) ;
Global . setAProfile ( tdevice , e . ClickedItem . Text ) ;
Global . Save ( ) ;
Global . LoadProfile ( tdevice ) ;
}
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 )
{
2014-04-30 02:58:18 +02:00
notifyIcon_Click ( sender , e ) ;
2014-04-29 03:14:01 +02:00
}
private void notifyIcon_Click ( object sender , EventArgs e )
{
this . Show ( ) ;
WindowState = FormWindowState . Normal ;
2014-04-27 21:32:09 +02:00
}
2014-04-29 23:56:58 +02:00
2014-05-16 00:10:17 +02:00
private void linkProfiles_LinkClicked ( object sender , LinkLabelLinkClickedEventArgs e )
{
openProfiles . InitialDirectory = Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location ) . FullName + @"\Profiles\" ;
if ( openProfiles . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK )
{
string [ ] files = openProfiles . FileNames ;
for ( int i = 0 ; i < files . Length ; i + + )
{
string [ ] temp = files [ i ] . Split ( '\\' ) ;
files [ i ] = temp [ temp . Length - 1 ] ;
File . Copy ( openProfiles . FileNames [ i ] , Global . appdatapath + "\\Profiles\\" + files [ i ] , true ) ;
}
RefreshProfiles ( ) ;
}
}
private void llbHelp_LinkClicked ( object sender , LinkLabelLinkClickedEventArgs e )
{
Hotkeys hotkeysForm = new Hotkeys ( ) ;
hotkeysForm . Icon = this . Icon ;
hotkeysForm . ShowDialog ( ) ;
}
private void btnImportProfiles_Click ( object sender , EventArgs e )
{
openProfiles . InitialDirectory = Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location ) . FullName + @"\Profiles\" ;
if ( openProfiles . ShowDialog ( ) = = System . Windows . Forms . DialogResult . OK )
{
string [ ] files = openProfiles . FileNames ;
for ( int i = 0 ; i < files . Length ; i + + )
{
string [ ] temp = files [ i ] . Split ( '\\' ) ;
files [ i ] = temp [ temp . Length - 1 ] ;
File . Copy ( openProfiles . FileNames [ i ] , Global . appdatapath + "\\Profiles\\" + files [ i ] , true ) ;
}
RefreshProfiles ( ) ;
}
}
2014-05-19 07:55:12 +02:00
protected void Form_Close ( object sender , FormClosingEventArgs e )
{
Global . setFormWidth ( this . Width ) ;
Global . setFormHeight ( this . Height ) ;
Global . Save ( ) ;
2014-05-24 01:44:30 +02:00
for ( int i = 0 ; i < 4 ; i + + )
{
Global . setRainbow ( i , 0 ) ;
Global . setLedAsBatteryIndicator ( i , false ) ;
Global . saveColor ( i , 128 , 255 , 255 ) ;
}
2014-05-19 07:55:12 +02:00
rootHub . Stop ( ) ;
}
private void ScpForm_Deactivate ( object sender , EventArgs e )
{
try { notifyIcon1 . Visible = true ; }
catch { }
}
private void ScpForm_Activated ( object sender , EventArgs e )
{
notifyIcon1 . Visible = false ;
}
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 ) ;
if ( StartWindowsCheckBox . Checked )
KeyLoc . SetValue ( "DS4Tool" , "\"" + Application . ExecutablePath . ToString ( ) + "\"" ) ;
else
KeyLoc . DeleteValue ( "DS4Tool" , false ) ;
}
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 { }
}
}
}