Skip to content

Commit

Permalink
added debug logging to startup checks and setups
Browse files Browse the repository at this point in the history
  • Loading branch information
YSX7 committed Jul 1, 2017
1 parent 357d79a commit 6fd8f3e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
16 changes: 9 additions & 7 deletions ScreamControl.View/Helpers/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ namespace ScreamControl.View
{
static class Startup
{
public static void SetAutostart()
{
Assembly curAssembly = Assembly.GetEntryAssembly();
static Assembly curAssembly = Assembly.GetEntryAssembly();

public static void SetAutostart(bool debugMode = false)
{
try
{
//if (!IsStartupItem(curAssembly))
Expand All @@ -35,6 +35,8 @@ public static void SetAutostart()
string lnkPath = startUpFolderPath + "\\" +
curAssembly.GetName().Name + ".lnk";

if (debugMode) Trace.TraceInformation("Startup assembly name: {0}", curAssembly.GetName().Name);

if (!System.IO.File.Exists(lnkPath))
{
WshShell wshShell = new WshShell();
Expand All @@ -54,21 +56,21 @@ public static void SetAutostart()
Trace.TraceError("Something happened at Autostart set: {0}", e);
}

CheckAutostartEnabled(curAssembly.GetName().Name);
CheckAutostartEnabled(debugMode);
}

public static void CheckAutostartEnabled(String appName)
public static void CheckAutostartEnabled(bool debugMode)
{
try
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\StartupFolder", true);
if (key != null)
{
byte[] newValue = (byte[])key.GetValue(appName + ".lnk");
byte[] newValue = (byte[])key.GetValue(curAssembly.GetName().Name + ".lnk");
if (newValue[0] != 2)
{
newValue[0] = 2;
key.SetValue(appName + ".lnk", newValue);
key.SetValue(curAssembly.GetName().Name + ".lnk", newValue);
Trace.TraceInformation("Autostart Enabled");
}
}
Expand Down
9 changes: 6 additions & 3 deletions ScreamControl.View/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public partial class MainWindow : ExtendedMetroWindow
private Hotkey _hotkeyStealth;
private double _availableHeight;
private bool _isController;
private bool _isDebugMode;

delegate float MonitorVolumeCallback();

public MainWindow()
public MainWindow(bool debugMode = false)
{
_isDebugMode = debugMode;

InitializeComponent();

Expand All @@ -64,8 +66,9 @@ public MainWindow()

private void Window_Loaded(object sender, RoutedEventArgs e)
{

#if !DEBUG
Startup.SetAutostart();
Startup.SetAutostart(_isDebugMode);
#endif

Trace.TraceInformation("Window loaded");
Expand All @@ -88,7 +91,7 @@ private void Window_Closing(object sender, CancelEventArgs e)
private void wMain_Closed(object sender, EventArgs e)
{
#if !DEBUG
Startup.CheckAutostartEnabled(Assembly.GetEntryAssembly().GetName().Name);
Startup.CheckAutostartEnabled(_isDebugMode);
#endif

Trace.TraceInformation("Window closed");
Expand Down
2 changes: 1 addition & 1 deletion ScreamControl_Client/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void Application_Startup(object sender, StartupEventArgs e)
}

Language = ScreamControl.Client.Properties.Settings.Default.CurrentLanguage;
MainWindow window = new MainWindow();
MainWindow window = new MainWindow(_isDebugMode);
window.DataContext = new MainViewModel();
window.Show();
}
Expand Down

0 comments on commit 6fd8f3e

Please sign in to comment.