Skip to content

Commit 7952deb

Browse files
committed
- Added start menu shortcut creation when the app opens
- Removed the code that tried to validate the code signature, as it was causing errors with package managers - UI & Code enhancements
1 parent 19e10ad commit 7952deb

41 files changed

Lines changed: 122 additions & 159 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/App.xaml.cs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Globalization;
66
using System.IO;
77
using System.Linq;
8-
using System.Reflection;
98
using System.Security.Principal;
109
using System.ServiceProcess;
1110
using System.Threading;
@@ -163,19 +162,34 @@ protected virtual void Dispose(bool disposing)
163162

164163
#region Methods
165164

166-
private void Initialize()
165+
/// <summary>
166+
/// Creates the start menu shortcut.
167+
/// </summary>
168+
private void CreateStartMenuShortcut()
167169
{
168-
// Check if the app is secure to run
169-
SecurityCheck();
170+
try
171+
{
172+
Helper.CreateShortcut(Path, System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), Constants.App.Shortcut), Constants.App.Title);
173+
}
174+
catch (Exception e)
175+
{
176+
Logger.Debug("Failed to create Start Menu shortcut: " + e.GetMessage());
177+
}
178+
}
170179

180+
private void Initialize()
181+
{
171182
// DI/IOC
172183
DependencyInjection.Container.Register<IComputerService, ComputerService>();
173184
DependencyInjection.Container.Register<IHotkeyService, HotkeyService>();
174185
DependencyInjection.Container.Register<INotificationService, NotificationService>();
175186

176187
// App properties
177-
Path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.FriendlyName);
178-
Version = Assembly.GetExecutingAssembly().GetName().Version;
188+
Path = Helper.GetExecutablePath();
189+
Version = Helper.GetVersion();
190+
191+
// App startup shortcut
192+
CreateStartMenuShortcut();
179193

180194
// Check if app is already running
181195
bool createdNew;
@@ -723,28 +737,6 @@ public static void RunOnStartup(bool enable)
723737
}
724738
}
725739

726-
/// <summary>
727-
/// Verify if the app is secure to run
728-
/// </summary>
729-
private void SecurityCheck()
730-
{
731-
if (IsInDebugMode)
732-
return;
733-
734-
if (!Validator.IsCertificateValid())
735-
{
736-
try
737-
{
738-
ShowDialog(Localizer.String.SecurityWarning, MessageBoxButton.OK, MessageBoxImage.Warning);
739-
Navigate(Constants.App.Repository.DownloadUri);
740-
}
741-
finally
742-
{
743-
Shutdown(true);
744-
}
745-
}
746-
}
747-
748740
/// <summary>
749741
/// Sets the app priority for the Windows
750742
/// </summary>

src/Core/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public static class App
2020
public const string License = "GPL-3.0";
2121
public const string LocalizationResourcePath = EmbeddedResourcePath + "Localization.";
2222
public const string Name = "WinMemoryCleaner";
23+
public const string Shortcut = "Windows Memory Cleaner.lnk";
2324
public const string ThemesResourcePath = EmbeddedResourcePath + "Themes.";
2425
public const string Title = "Windows Memory Cleaner";
2526
public const string VersionFormat = "{0}.{1}.{2}";

src/Core/Helper.cs

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq.Expressions;
55
using System.Reflection;
6+
using System.Runtime.InteropServices.ComTypes;
67
using System.Text;
78
using System.Web.Script.Serialization;
89

@@ -26,18 +27,22 @@ private static void AppendIndent(StringBuilder sb, int level, string indent)
2627
}
2728

2829
/// <summary>
29-
/// Creates a directory exists. Ignores failures.
30+
/// Creates a shortcut (.lnk) at the specified path pointing to the target executable.
3031
/// </summary>
31-
public static void CreateDirectory(string path)
32+
/// <param name="targetExePath">The full path to the .exe file.</param>
33+
/// <param name="destinationLinkPath">The full path where the .lnk file will be saved.</param>
34+
/// <param name="description">The tooltip description for the shortcut.</param>
35+
public static void CreateShortcut(string targetExePath, string destinationLinkPath, string description)
3236
{
33-
try
34-
{
35-
if (!string.IsNullOrEmpty(path) && !Directory.Exists(path))
36-
Directory.CreateDirectory(path);
37-
}
38-
catch
39-
{
40-
}
37+
var link = (ShellInterop.IShellLink)new ShellInterop.ShellLink();
38+
39+
link.SetDescription(description);
40+
link.SetPath(targetExePath);
41+
link.SetWorkingDirectory(Path.GetDirectoryName(targetExePath));
42+
43+
IPersistFile file = (IPersistFile)link;
44+
45+
file.Save(destinationLinkPath, false);
4146
}
4247

4348
/// <summary>
@@ -144,25 +149,22 @@ private static string FormatJson(string json)
144149
}
145150

146151
/// <summary>
147-
/// Gets the current application's assembly version.
152+
/// Returns the executable application's path
148153
/// </summary>
149-
public static Version GetCurrentVersion()
154+
public static string GetExecutablePath()
150155
{
151156
try
152157
{
153-
return (Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly()).GetName().Version ?? new Version(0, 0, 0, 0);
158+
var path = Process.GetCurrentProcess().MainModule.FileName;
159+
160+
if (!string.IsNullOrEmpty(path) && File.Exists(path))
161+
return path;
154162
}
155-
catch
163+
catch
156164
{
157-
return new Version(0, 0, 0, 0);
165+
// ignored
158166
}
159-
}
160167

161-
/// <summary>
162-
/// Returns the executable path of the current process.
163-
/// </summary>
164-
public static string GetExecutablePath()
165-
{
166168
try
167169
{
168170
var entry = Assembly.GetEntryAssembly();
@@ -172,15 +174,24 @@ public static string GetExecutablePath()
172174
}
173175
catch
174176
{
177+
// ignored
175178
}
176179

180+
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.FriendlyName);
181+
}
182+
183+
/// <summary>
184+
/// Gets the application's assembly version
185+
/// </summary>
186+
public static Version GetVersion()
187+
{
177188
try
178189
{
179-
return Process.GetCurrentProcess().MainModule.FileName;
190+
return (Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly()).GetName().Version ?? new Version(0, 0, 0, 0);
180191
}
181192
catch
182193
{
183-
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.FriendlyName);
194+
return new Version(0, 0, 0, 0);
184195
}
185196
}
186197

src/Core/Updater.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,13 @@ private static void OnVersionCheckCompleted(object sender, DownloadStringComplet
8585
return;
8686
}
8787

88-
var exe = AppDomain.CurrentDomain.FriendlyName;
89-
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, exe);
88+
var exe = Path.GetFileName(App.Path);
9089
var temp = Path.Combine(Path.GetTempPath(), exe);
9190

9291
if (File.Exists(temp))
9392
File.Delete(temp);
9493

95-
var updateInfo = Tuple.Create(temp, path, exe, newestVersion, (string[])e.UserState);
94+
var updateInfo = Tuple.Create(temp, App.Path, exe, newestVersion, (string[])e.UserState);
9695

9796
_client.DownloadFileAsync(Constants.App.Repository.LatestExeUri, temp, updateInfo);
9897
}

src/Core/Validator.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/Interop/ShellInterop.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using System.Text;
4+
5+
namespace WinMemoryCleaner
6+
{
7+
/// <summary>
8+
/// Windows Shell API
9+
/// </summary>
10+
internal static class ShellInterop
11+
{
12+
#region Classes
13+
14+
[ComImport]
15+
[Guid("00021401-0000-0000-C000-000000000046")]
16+
internal class ShellLink
17+
{
18+
}
19+
20+
#endregion
21+
22+
#region Interfaces
23+
24+
[ComImport]
25+
[Guid("000214F9-0000-0000-C000-000000000046")]
26+
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
27+
internal interface IShellLink
28+
{
29+
void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cch, out IntPtr pfd, int fFlags);
30+
void GetIDList(out IntPtr ppidl);
31+
void SetIDList(IntPtr pidl);
32+
void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cch);
33+
void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
34+
void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cch);
35+
void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
36+
void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cch);
37+
void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
38+
void GetHotkey(out short pwHotkey);
39+
void SetHotkey(short wHotkey);
40+
void GetShowCmd(out int piShowCmd);
41+
void SetShowCmd(int iShowCmd);
42+
void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cch, out int piIcon);
43+
void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
44+
void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, int dwReserved);
45+
void Resolve(IntPtr hwnd, int fFlags);
46+
void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
47+
}
48+
49+
#endregion
50+
}
51+
}

src/Model/Localization.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class Localization
2727
private string _optimizationHotkey, _optimize, _optimizeOnMiddleMouseClick, _optimizing;
2828
private string _physicalMemory, _processExclusionList;
2929
private string _reason, _registryCache, _remove, _reset, _resetConfirmation, _runOnLowPriority, _runOnStartup;
30-
private string _schedule, _seconds, _securityWarning, _settings, _showMemoryUsage, _showOptimizationNotifications, _showVirtualMemory, _standbyList, _standbyListLowPriority, _startMinimized, _systemFileCache;
30+
private string _schedule, _seconds, _settings, _showMemoryUsage, _showOptimizationNotifications, _showVirtualMemory, _standbyList, _standbyListLowPriority, _startMinimized, _systemFileCache;
3131
private string _text, _trayIcon;
3232
private string _updatedToVersion, _used, _useTransparentBackground;
3333
private string _virtualMemory;
@@ -402,13 +402,6 @@ public string Seconds
402402
private set { _seconds = value.Capitalize(); }
403403
}
404404

405-
[DataMember]
406-
public string SecurityWarning
407-
{
408-
get { return _securityWarning; }
409-
private set { _securityWarning = value.Capitalize(); }
410-
}
411-
412405
[DataMember]
413406
public string Settings
414407
{

src/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[assembly: AssemblyKeyFile(Constants.App.KeyFile)]
1212
[assembly: AssemblyProduct(Constants.App.Name)]
1313
[assembly: AssemblyTitle(Constants.App.Title)]
14-
[assembly: AssemblyVersion("3.0.6.0")]
14+
[assembly: AssemblyVersion("3.0.7.0")]
1515
[assembly: ComVisible(false)]
1616
[assembly: CLSCompliant(true)]
1717
[assembly: Guid(Constants.App.Id)]

src/Resources/Localization/Albanian.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"RunOnStartup": "vazhdo në fillim",
5252
"Schedule": "orari",
5353
"Seconds": "sekonda",
54-
"SecurityWarning": "ky aplikacion mund të jetë manipuluar. do të ridrejtoheni në depozitat zyrtare për të shkarkuar një version të sigurt.",
5554
"Settings": "cilësimet",
5655
"ShowMemoryUsage": "shfaq përdorimin e memories",
5756
"ShowOptimizationNotifications": "shfaq njoftimet e optimizimit",

0 commit comments

Comments
 (0)