Allow launching on startup.
If this is used to play GIF animations on the pad, being able to have it launch on startup is useful. This is disabled by default and there's no UI to enable it yet.
This commit is contained in:
parent
5cf5eddc81
commit
42a99e775b
@ -1,8 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<configSections>
|
<configSections>
|
||||||
|
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
|
||||||
|
<section name="smx_config.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
|
||||||
|
</sectionGroup>
|
||||||
</configSections>
|
</configSections>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||||
</startup>
|
</startup>
|
||||||
|
<userSettings>
|
||||||
|
<smx_config.Properties.Settings>
|
||||||
|
<setting name="LaunchOnStartup" serializeAs="String">
|
||||||
|
<value>False</value>
|
||||||
|
</setting>
|
||||||
|
</smx_config.Properties.Settings>
|
||||||
|
</userSettings>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -24,6 +24,18 @@ namespace smx_config
|
|||||||
{
|
{
|
||||||
base.OnStartup(e);
|
base.OnStartup(e);
|
||||||
|
|
||||||
|
// If we're being launched on startup, but the LaunchOnStartup setting is false,
|
||||||
|
// then the user turned off auto-launching but we're still being launched for some
|
||||||
|
// reason (eg. a renamed launch shortcut that we couldn't find to remove). As
|
||||||
|
// a safety so we don't launch when the user doesn't want us to, just exit in this
|
||||||
|
// case.
|
||||||
|
if(Helpers.LaunchedOnStartup() && !LaunchOnStartup.Enable)
|
||||||
|
{
|
||||||
|
Shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchOnStartup.Enable = true;
|
||||||
if(!SMX.SMX.DLLExists())
|
if(!SMX.SMX.DLLExists())
|
||||||
{
|
{
|
||||||
MessageBox.Show("SMXConfig encountered an unexpected error.\n\nSMX.dll couldn't be found:\n\n" + Helpers.GetLastWin32ErrorString(), "SMXConfig");
|
MessageBox.Show("SMXConfig encountered an unexpected error.\n\nSMX.dll couldn't be found:\n\n" + Helpers.GetLastWin32ErrorString(), "SMXConfig");
|
||||||
|
@ -75,17 +75,29 @@ namespace smx_config
|
|||||||
|
|
||||||
static class Helpers
|
static class Helpers
|
||||||
{
|
{
|
||||||
// Return true if we're in debug mode.
|
// Return true if arg is in the commandline.
|
||||||
public static bool GetDebug()
|
public static bool HasCommandlineArgument(string arg)
|
||||||
{
|
{
|
||||||
foreach(string arg in Environment.GetCommandLineArgs())
|
foreach(string s in Environment.GetCommandLineArgs())
|
||||||
{
|
{
|
||||||
if(arg == "-d")
|
if(s == arg)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return true if we're in debug mode.
|
||||||
|
public static bool GetDebug()
|
||||||
|
{
|
||||||
|
return HasCommandlineArgument("-d");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return true if we were launched on startup.
|
||||||
|
public static bool LaunchedOnStartup()
|
||||||
|
{
|
||||||
|
return HasCommandlineArgument("-s");
|
||||||
|
}
|
||||||
|
|
||||||
// Return the last Win32 error as a string.
|
// Return the last Win32 error as a string.
|
||||||
public static string GetLastWin32ErrorString()
|
public static string GetLastWin32ErrorString()
|
||||||
{
|
{
|
||||||
@ -332,6 +344,19 @@ namespace smx_config
|
|||||||
string error;
|
string error;
|
||||||
SMX.SMX.LightsAnimation_Load(gif, pad, type, out error);
|
SMX.SMX.LightsAnimation_Load(gif, pad, type, out error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a .lnk.
|
||||||
|
public static void CreateShortcut(string outputFile, string targetPath, string arguments)
|
||||||
|
{
|
||||||
|
Type shellType = Type.GetTypeFromProgID("WScript.Shell");
|
||||||
|
dynamic shell = Activator.CreateInstance(shellType);
|
||||||
|
dynamic shortcut = shell.CreateShortcut(outputFile);
|
||||||
|
|
||||||
|
shortcut.TargetPath = targetPath;
|
||||||
|
shortcut.Arguments = arguments;
|
||||||
|
shortcut.WindowStyle = 0;
|
||||||
|
shortcut.Save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This class just makes it easier to assemble binary command packets.
|
// This class just makes it easier to assemble binary command packets.
|
||||||
@ -368,6 +393,46 @@ namespace smx_config
|
|||||||
private LinkedList<byte[]> parts = new LinkedList<byte[]>();
|
private LinkedList<byte[]> parts = new LinkedList<byte[]>();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Manage launching on startup.
|
||||||
|
static class LaunchOnStartup
|
||||||
|
{
|
||||||
|
public static string GetLaunchShortcutFilename()
|
||||||
|
{
|
||||||
|
string startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
|
||||||
|
return startupFolder + "/StepManiaX.lnk";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable or disable launching on startup.
|
||||||
|
public static bool Enable
|
||||||
|
{
|
||||||
|
get {
|
||||||
|
return Properties.Settings.Default.LaunchOnStartup;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
// Remember whether we want to be launched on startup. This is used as a sanity
|
||||||
|
// check in case we're not able to remove our launch shortcut.
|
||||||
|
Properties.Settings.Default.LaunchOnStartup = value;
|
||||||
|
Properties.Settings.Default.Save();
|
||||||
|
|
||||||
|
string shortcutFilename = GetLaunchShortcutFilename();
|
||||||
|
if(value)
|
||||||
|
{
|
||||||
|
string filename = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
|
||||||
|
Helpers.CreateShortcut(shortcutFilename, filename, "-s");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.IO.File.Delete(shortcutFilename);
|
||||||
|
} catch {
|
||||||
|
// If there's an error deleting the shortcut (most likely it doesn't exist),
|
||||||
|
// don't do anything.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// When enabled, periodically set all lights to the current auto-lighting color. This
|
// When enabled, periodically set all lights to the current auto-lighting color. This
|
||||||
// is enabled while manipulating the step color slider.
|
// is enabled while manipulating the step color slider.
|
||||||
class ShowAutoLightsColor
|
class ShowAutoLightsColor
|
||||||
|
12
smx-config/Properties/Settings.Designer.cs
generated
12
smx-config/Properties/Settings.Designer.cs
generated
@ -22,5 +22,17 @@ namespace smx_config.Properties {
|
|||||||
return defaultInstance;
|
return defaultInstance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Configuration.DefaultSettingValueAttribute("False")]
|
||||||
|
public bool LaunchOnStartup {
|
||||||
|
get {
|
||||||
|
return ((bool)(this["LaunchOnStartup"]));
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this["LaunchOnStartup"] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="smx_config.Properties" GeneratedClassName="Settings">
|
||||||
<Profiles />
|
<Profiles />
|
||||||
<Settings />
|
<Settings>
|
||||||
|
<Setting Name="LaunchOnStartup" Type="System.Boolean" Scope="User">
|
||||||
|
<Value Profile="(Default)">False</Value>
|
||||||
|
</Setting>
|
||||||
|
</Settings>
|
||||||
</SettingsFile>
|
</SettingsFile>
|
Loading…
x
Reference in New Issue
Block a user