1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-01-23 18:46:02 +01:00

Fix more analysis violations (exceptions, native method pointers, form disposal)

This commit is contained in:
chylex 2017-07-08 00:21:41 +02:00
parent 14d44528b0
commit 0ded03ab92
5 changed files with 13 additions and 12 deletions

View File

@ -70,7 +70,7 @@ public static bool AlignValueToTick(this TrackBar trackBar){
public static void SetElevated(this Button button){
button.Text = " "+button.Text;
button.FlatStyle = FlatStyle.System;
NativeMethods.SendMessage(button.Handle, NativeMethods.BCM_SETSHIELD, 0, new IntPtr(1));
NativeMethods.SendMessage(button.Handle, NativeMethods.BCM_SETSHIELD, new UIntPtr(0), new IntPtr(1));
}
public static void EnableMultilineShortcuts(this TextBox textBox){

View File

@ -67,10 +67,10 @@ private struct MSLLHOOKSTRUCT{
private static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, IntPtr lParam);
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
public static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, IntPtr lParam);
public static extern bool PostMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
public static extern uint RegisterWindowMessage(string messageName);

View File

@ -47,9 +47,9 @@ private string GetFullPathOrThrow(int token, PluginFolder folder, string path){
if (fullPath.Length == 0){
switch(folder){
case PluginFolder.Data: throw new Exception("File path has to be relative to the plugin data folder.");
case PluginFolder.Root: throw new Exception("File path has to be relative to the plugin root folder.");
default: throw new Exception("Invalid folder type "+folder+", this is a "+Program.BrandName+" error.");
case PluginFolder.Data: throw new ArgumentException("File path has to be relative to the plugin data folder.");
case PluginFolder.Root: throw new ArgumentException("File path has to be relative to the plugin root folder.");
default: throw new ArgumentException("Invalid folder type "+folder+", this is a "+Program.BrandName+" error.");
}
}
else{
@ -67,9 +67,9 @@ private string ReadFileUnsafe(int token, string cacheKey, string fullPath, bool
try{
return fileCache[token, cacheKey] = File.ReadAllText(fullPath, Encoding.UTF8);
}catch(FileNotFoundException){
throw new Exception("File not found.");
throw new FileNotFoundException("File not found.");
}catch(DirectoryNotFoundException){
throw new Exception("Directory not found.");
throw new DirectoryNotFoundException("Directory not found.");
}
}

View File

@ -109,7 +109,7 @@ private static void Main(){
if (lockResult == LockManager.Result.HasProcess){
if (LockManager.LockingProcess.MainWindowHandle == IntPtr.Zero){ // restore if the original process is in tray
NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, WindowRestoreMessage, LockManager.LockingProcess.Id, IntPtr.Zero);
NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, WindowRestoreMessage, new UIntPtr((uint)LockManager.LockingProcess.Id), IntPtr.Zero);
if (WindowsUtils.TrySleepUntil(() => {
LockManager.LockingProcess.Refresh();

View File

@ -84,9 +84,10 @@ public static void HandleEarlyFailure(string caption, string message){
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
FormMessage form = new FormMessage(caption, message, MessageBoxIcon.Error);
form.ActiveControl = form.AddButton("Exit");
form.ShowDialog();
using(FormMessage form = new FormMessage(caption, message, MessageBoxIcon.Error)){
form.ActiveControl = form.AddButton("Exit");
form.ShowDialog();
}
try{
Process.GetCurrentProcess().Kill();