Skip to content

Commit 9fd3424

Browse files
Merge pull request #32 from freshprogrammer/dev
Dev v0.4
2 parents bb5577d + 6075142 commit 9fd3424

8 files changed

Lines changed: 426 additions & 39 deletions

File tree

FreshTools/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("0.3.0.0")]
36-
[assembly: AssemblyFileVersion("0.3.0.0")]
35+
[assembly: AssemblyVersion("0.4.0.0")]
36+
[assembly: AssemblyFileVersion("0.4.0.0")]

FreshTools/code/FreshTools.cs

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Reflection;
44
using System.Threading;
55
using System.Windows.Forms;
6+
using System.Diagnostics;
67

78
namespace FreshTools
89
{
@@ -56,23 +57,38 @@ public void InitializeNotificationIcon()
5657
startIdlePreventionMenuItem = new MenuItem("Start Idle Prevention");
5758
stopIdlePreventionMenuItem = new MenuItem("Stop Idle Prevention");
5859

59-
MenuItem windowHotKeysEnabledManagerMenuItem = new MenuItem("Window Control Hot Keys");
60-
windowHotKeysEnabledManagerMenuItem.Checked = WindowManager.HotKeysEnabled;
60+
MenuItem windowManagerHotKeysEnabledMenuItem = new MenuItem("Window Control Hot Keys");
61+
windowManagerHotKeysEnabledMenuItem.Checked = WindowManager.HotKeysEnabled;
62+
63+
MenuItem windowManagerSaveWindowsMenuItem = new MenuItem("Save All Window Positions");
64+
MenuItem windowManagerRestoreWindowsMenuItem = new MenuItem("Restore All Window Positions");
65+
MenuItem windowManagerUndoRestoreWindowsMenuItem = new MenuItem("Restore All Window Positions (undo)");
66+
67+
MenuItem startupEnabledMenuItem = new MenuItem("Start With Windows");
68+
startupEnabledMenuItem.Checked = FreshArchives.IsApplicationInStartup();
6169

6270
MenuItem quitMenuItem = new MenuItem("Quit");
6371

6472
ContextMenu contextMenu = new ContextMenu();
6573
contextMenu.MenuItems.Add(titleMenuItem);
6674
contextMenu.MenuItems.Add(breakMenuItem);
6775
contextMenu.MenuItems.Add(startIdlePreventionMenuItem);
68-
contextMenu.MenuItems.Add(windowHotKeysEnabledManagerMenuItem);
76+
contextMenu.MenuItems.Add(windowManagerHotKeysEnabledMenuItem);
77+
contextMenu.MenuItems.Add(windowManagerSaveWindowsMenuItem);
78+
contextMenu.MenuItems.Add(windowManagerRestoreWindowsMenuItem);
79+
contextMenu.MenuItems.Add(windowManagerUndoRestoreWindowsMenuItem);
80+
contextMenu.MenuItems.Add(startupEnabledMenuItem);
6981
contextMenu.MenuItems.Add(quitMenuItem);
7082
freshToolsNotifyIcon.ContextMenu = contextMenu;
7183

7284
// Wire up menu items
7385
startIdlePreventionMenuItem.Click += startIdlePreventionMenuItem_Click;
7486
stopIdlePreventionMenuItem.Click += stopIdlePreventionMenuItem_Click;
75-
windowHotKeysEnabledManagerMenuItem.Click += windowHotKeysEnabledMenuItem_Click;
87+
windowManagerHotKeysEnabledMenuItem.Click += windowHotKeysEnabledMenuItem_Click;
88+
windowManagerSaveWindowsMenuItem.Click += WindowManager.SaveAllWindowPositions;
89+
windowManagerRestoreWindowsMenuItem.Click += WindowManager.RestoreAllWindowPositions;
90+
windowManagerUndoRestoreWindowsMenuItem.Click += WindowManager.UndoRestoreAllWindowPositions;
91+
startupEnabledMenuItem.Click += startupEnabledMenuItem_Click;
7692
quitMenuItem.Click += quitMenuItem_Click;
7793
}
7894

@@ -82,9 +98,24 @@ public void InitializeNotificationIcon()
8298
[STAThread]
8399
static void Main(string[] args)
84100
{
85-
Application.EnableVisualStyles();
86-
Application.SetCompatibleTextRenderingDefault(false);
87-
Application.Run(new FreshTools());
101+
string mutex_id = "FreshTools";
102+
bool createdNew = true;
103+
using (Mutex mutex = new Mutex(true, mutex_id, out createdNew))
104+
{
105+
if (!createdNew)
106+
{
107+
Process thisProccess = Process.GetCurrentProcess();
108+
foreach (var process in Process.GetProcessesByName(thisProccess.ProcessName))
109+
{
110+
if (process.Id != thisProccess.Id)
111+
process.Kill();
112+
}
113+
//MessageBox.Show("Killed old process and started new!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
114+
}
115+
Application.EnableVisualStyles();
116+
Application.SetCompatibleTextRenderingDefault(false);
117+
Application.Run(new FreshTools());
118+
}
88119
}
89120

90121
public void LoadConfig()
@@ -146,6 +177,16 @@ private void windowHotKeysEnabledMenuItem_Click(object sender, EventArgs e)
146177
WindowManager.HotKeysEnabled = i.Checked;
147178
}
148179

180+
private void startupEnabledMenuItem_Click(object sender, EventArgs e)
181+
{
182+
MenuItem i = (MenuItem)sender;
183+
if (FreshArchives.IsApplicationInStartup())
184+
FreshArchives.RemoveApplicationFromStartup();
185+
else
186+
FreshArchives.AddApplicationToStartup();
187+
i.Checked = FreshArchives.IsApplicationInStartup();
188+
}
189+
149190
/// <summary>
150191
/// Close the application on click of 'quit' button on context menu
151192
/// </summary>
@@ -171,21 +212,31 @@ private static void RegisterHotkeys()
171212
//register hotkey(s)
172213
//GenericsClass.LogSystem("Registering Hotkeys");
173214
HotKeyManager.GenericHotKeyPressedHandler += new EventHandler<HotKeyEventArgs>(GenericHotKeyPressed);
174-
HotKeyManager.RegisterHotKey((KeyModifiers.NoRepeat | KeyModifiers.Control | KeyModifiers.Alt | KeyModifiers.Shift), Keys.Oemtilde);
215+
//HotKeyManager.RegisterHotKey((KeyModifiers.NoRepeat | KeyModifiers.Control | KeyModifiers.Shift), Keys.C);
216+
//HotKeyManager.RegisterHotKey((KeyModifiers.NoRepeat | KeyModifiers.Control | KeyModifiers.Shift), Keys.X);
217+
//HotKeyManager.RegisterHotKey((KeyModifiers.NoRepeat | KeyModifiers.Control | KeyModifiers.Shift), Keys.Z);
175218
}
176219

177220
private static void GenericHotKeyPressed(object sender, HotKeyEventArgs args)
178221
{
179222
try
180223
{
181-
if (args.Modifiers == (KeyModifiers.NoRepeat | KeyModifiers.Control | KeyModifiers.Alt | KeyModifiers.Shift) && args.Key == Keys.Oemtilde)
224+
if (args.Modifiers == (KeyModifiers.Control | KeyModifiers.Shift) && args.Key == Keys.C)
225+
{
226+
//WindowManager.SaveAllWindowPositions();
227+
}
228+
else if (args.Modifiers == (KeyModifiers.Control | KeyModifiers.Shift) && args.Key == Keys.X)
229+
{
230+
//WindowManager.RestoreAllWindowPositions();
231+
}
232+
else if (args.Modifiers == (KeyModifiers.Control | KeyModifiers.Shift) && args.Key == Keys.Z)
182233
{
183-
LogSystem.Log("FreshTools.HotKeyPressed() - Super Tilde - " + args.Modifiers + "+" + args.Key + "");
234+
//WindowManager.UndoRestoreAllWindowPositions();
184235
}
185236
else //unknown hot key pressed
186237
{
187238
//uncaught hotkey
188-
LogSystem.Log("FreshTools.HotKeyPressed() - UnActioned - " + args.Modifiers + "+" + args.Key + "");
239+
LogSystem.Log("UnActioned - " + args.Modifiers + "+" + args.Key + "");
189240
}
190241
}
191242
catch (Exception e)

FreshTools/code/Generics/FreshArchives.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using System;
2+
using System.Reflection;
3+
using System.Windows.Forms;
4+
using Microsoft.Win32;
25

36
namespace FreshTools
47
{
@@ -16,5 +19,37 @@ public static string TrimVersionNumber(Version ver)
1619
if (ver.Minor != 0) return ver.ToString(2);
1720
else return ver.ToString(1);
1821
}
22+
23+
public static bool IsWindows10()
24+
{
25+
var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
26+
string productName = (string)reg.GetValue("ProductName");
27+
return productName.StartsWith("Windows 10");
28+
}
29+
30+
public static void AddApplicationToStartup()
31+
{
32+
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
33+
{
34+
key.SetValue(Assembly.GetExecutingAssembly().GetName().Name, "\"" + Application.ExecutablePath + "\"");
35+
}
36+
}
37+
38+
public static void RemoveApplicationFromStartup()
39+
{
40+
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
41+
{
42+
key.DeleteValue(Assembly.GetExecutingAssembly().GetName().Name, false);
43+
}
44+
}
45+
46+
public static bool IsApplicationInStartup()
47+
{
48+
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
49+
{
50+
var val = key.GetValue(Assembly.GetExecutingAssembly().GetName().Name);
51+
return val != null;
52+
}
53+
}
1954
}
2055
}

FreshTools/code/Generics/FreshMath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static double RadiansToDegrees(double angleInRadians)
1818
}
1919

2020
/// <summary>
21-
/// Calculates angle from Point 1, to Point 2. Result returned in degrees
21+
/// Calculates angle from Point 1, to Point 2. Result in degrees
2222
/// </summary>
2323
/// <param name="x1">X cord of Point 1</param>
2424
/// <param name="y1">Y cord of Point 1</param>

FreshTools/code/IdleMonitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class IdleMonitor
2525

2626
public IdleMonitor()
2727
{
28-
28+
2929
}
3030

3131
/// <summary>

FreshTools/code/Scripting/FreshScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ private void ProcessVariableDefinition(string line, VariableLibrary variableLibr
507507
}
508508

509509
/// <summary>
510-
/// Real workhorse of the complex variable logic. Converts variable names to values and does the math and returns final result. If value conversion fails an empty string is returned.
510+
/// Real workhorse of the complex variable logic. Converts variable names to values and does the math and returns final result. If value conversion fails returns an empty string.
511511
/// </summary>
512512
/// <param name="original">string to be parsed into a value</param>
513513
/// <returns>value in the form of a Variable</returns>

0 commit comments

Comments
 (0)