1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-01 08:34:11 +02: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){ public static void SetElevated(this Button button){
button.Text = " "+button.Text; button.Text = " "+button.Text;
button.FlatStyle = FlatStyle.System; 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){ 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); 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")] [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")] [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")] [DllImport("user32.dll")]
public static extern uint RegisterWindowMessage(string messageName); 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){ if (fullPath.Length == 0){
switch(folder){ switch(folder){
case PluginFolder.Data: throw new Exception("File path has to be relative to the plugin data folder."); case PluginFolder.Data: throw new ArgumentException("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."); case PluginFolder.Root: throw new ArgumentException("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."); default: throw new ArgumentException("Invalid folder type "+folder+", this is a "+Program.BrandName+" error.");
} }
} }
else{ else{
@ -67,9 +67,9 @@ private string ReadFileUnsafe(int token, string cacheKey, string fullPath, bool
try{ try{
return fileCache[token, cacheKey] = File.ReadAllText(fullPath, Encoding.UTF8); return fileCache[token, cacheKey] = File.ReadAllText(fullPath, Encoding.UTF8);
}catch(FileNotFoundException){ }catch(FileNotFoundException){
throw new Exception("File not found."); throw new FileNotFoundException("File not found.");
}catch(DirectoryNotFoundException){ }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 (lockResult == LockManager.Result.HasProcess){
if (LockManager.LockingProcess.MainWindowHandle == IntPtr.Zero){ // restore if the original process is in tray 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(() => { if (WindowsUtils.TrySleepUntil(() => {
LockManager.LockingProcess.Refresh(); LockManager.LockingProcess.Refresh();

View File

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