diff --git a/.gitignore b/.gitignore index f1adef99e..133458559 100644 --- a/.gitignore +++ b/.gitignore @@ -286,7 +286,7 @@ paket-files/ *.VC.db ## Wox specific - +Output/* /Python.Runtime.dll Wox/Images/websearch/Thumbs.db Wox/Images/Thumbs.db diff --git a/Plugins/Wox.Plugin.CMD/Main.cs b/Plugins/Wox.Plugin.CMD/Main.cs index be6043d51..1a65f21e2 100644 --- a/Plugins/Wox.Plugin.CMD/Main.cs +++ b/Plugins/Wox.Plugin.CMD/Main.cs @@ -87,7 +87,7 @@ namespace Wox.Plugin.CMD } catch (Exception e) { - Log.Error(e); + Log.Exception(e); } return results; } diff --git a/Plugins/Wox.Plugin.PluginManagement/Main.cs b/Plugins/Wox.Plugin.PluginManagement/Main.cs index 33abd1718..18af05f06 100644 --- a/Plugins/Wox.Plugin.PluginManagement/Main.cs +++ b/Plugins/Wox.Plugin.PluginManagement/Main.cs @@ -118,7 +118,7 @@ namespace Wox.Plugin.PluginManagement catch (WebException e) { Log.Warn("Can't connect to Wox plugin website, check your conenction"); - Log.Error(e); + Log.Exception(e); return new List(); } List searchedPlugins; @@ -129,7 +129,7 @@ namespace Wox.Plugin.PluginManagement catch(JsonSerializationException e) { context.API.ShowMsg("Coundn't parse api search results", "Please update your Wox!", string.Empty); - Log.Error(e); + Log.Exception(e); return results; } @@ -164,7 +164,7 @@ namespace Wox.Plugin.PluginManagement var info = "download plugin " + r.name + "failed."; MessageBox.Show(info); Log.Warn(info); - Log.Error(e); + Log.Exception(e); return false; } context.API.InstallPlugin(filePath); diff --git a/Plugins/Wox.Plugin.Program/ProgramSources/AppPathsProgramSource.cs b/Plugins/Wox.Plugin.Program/ProgramSources/AppPathsProgramSource.cs index 51caa7caf..47c2b7bae 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSources/AppPathsProgramSource.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSources/AppPathsProgramSource.cs @@ -61,7 +61,7 @@ namespace Wox.Plugin.Program.ProgramSources } catch (Exception e) { - Log.Error(e); + Log.Exception(e); } } } diff --git a/Plugins/Wox.Plugin.Program/ProgramSources/FileSystemProgramSource.cs b/Plugins/Wox.Plugin.Program/ProgramSources/FileSystemProgramSource.cs index f408ae7a8..420d6172a 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSources/FileSystemProgramSource.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSources/FileSystemProgramSource.cs @@ -72,7 +72,7 @@ namespace Wox.Plugin.Program.ProgramSources catch (Exception e) { var woxPluginException = new WoxPluginException("Program", $"GetAppFromDirectory failed: {path}", e); - Log.Error(woxPluginException); + Log.Exception(woxPluginException); } } diff --git a/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Baidu.cs b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Baidu.cs index b10bbf379..2b889cb78 100644 --- a/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Baidu.cs +++ b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Baidu.cs @@ -29,7 +29,7 @@ namespace Wox.Plugin.WebSearch.SuggestionSources catch (WebException e) { Log.Warn("Can't get suggestion from baidu"); - Log.Error(e); + Log.Exception(e); return new List(); ; } @@ -45,7 +45,7 @@ namespace Wox.Plugin.WebSearch.SuggestionSources } catch (JsonSerializationException e) { - Log.Error(e); + Log.Exception(e); return new List(); } diff --git a/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Google.cs b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Google.cs index c62376020..5cea59a8e 100644 --- a/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Google.cs +++ b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Google.cs @@ -24,7 +24,7 @@ namespace Wox.Plugin.WebSearch.SuggestionSources catch (WebException e) { Log.Warn("Can't get suggestion from google"); - Log.Error(e); + Log.Exception(e); return new List(); ; } if (string.IsNullOrEmpty(result)) return new List(); @@ -35,7 +35,7 @@ namespace Wox.Plugin.WebSearch.SuggestionSources } catch (JsonSerializationException e) { - Log.Error(e); + Log.Exception(e); return new List(); } if (json != null) diff --git a/Wox.Core/Plugin/JsonRPCPlugin.cs b/Wox.Core/Plugin/JsonRPCPlugin.cs index 2c6c72e1c..3d7fb006f 100644 --- a/Wox.Core/Plugin/JsonRPCPlugin.cs +++ b/Wox.Core/Plugin/JsonRPCPlugin.cs @@ -74,7 +74,7 @@ namespace Wox.Core.Plugin } catch (Exception e) { - Log.Error(e); + Log.Exception(e); } } return null; diff --git a/Wox.Core/Plugin/PluginConfig.cs b/Wox.Core/Plugin/PluginConfig.cs index 075bf2707..0b59c06f5 100644 --- a/Wox.Core/Plugin/PluginConfig.cs +++ b/Wox.Core/Plugin/PluginConfig.cs @@ -78,7 +78,7 @@ namespace Wox.Core.Plugin catch (Exception e) { string msg = $"Parse plugin config {configPath} failed: json format is not valid"; - Log.Error(new WoxException(msg)); + Log.Exception(new WoxException(msg)); return null; } @@ -86,14 +86,14 @@ namespace Wox.Core.Plugin if (!AllowedLanguage.IsAllowed(metadata.Language)) { string msg = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}"; - Log.Error(new WoxException(msg)); + Log.Exception(new WoxException(msg)); return null; } if (!File.Exists(metadata.ExecuteFilePath)) { string msg = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist"; - Log.Error(new WoxException(msg)); + Log.Exception(new WoxException(msg)); return null; } diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 3f6e87b6c..cc68357b4 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -228,7 +228,7 @@ namespace Wox.Core.Plugin } catch (Exception e) { - Log.Error(new WoxPluginException(metadata.Name, "Couldn't load plugin context menus", e)); + Log.Exception(new WoxPluginException(metadata.Name, "Couldn't load plugin context menus", e)); return new List(); } } diff --git a/Wox.Core/Plugin/PluginsLoader.cs b/Wox.Core/Plugin/PluginsLoader.cs index 369e1f72e..b62a9a9c7 100644 --- a/Wox.Core/Plugin/PluginsLoader.cs +++ b/Wox.Core/Plugin/PluginsLoader.cs @@ -39,7 +39,7 @@ namespace Wox.Core.Plugin } catch (Exception e) { - Log.Error(new WoxPluginException(metadata.Name, "Couldn't load assembly", e)); + Log.Exception(new WoxPluginException(metadata.Name, "Couldn't load assembly", e)); continue; } var types = assembly.GetTypes(); @@ -50,7 +50,7 @@ namespace Wox.Core.Plugin } catch (InvalidOperationException e) { - Log.Error(new WoxPluginException(metadata.Name, "Can't find class implement IPlugin", e)); + Log.Exception(new WoxPluginException(metadata.Name, "Can't find class implement IPlugin", e)); continue; } IPlugin plugin; @@ -60,7 +60,7 @@ namespace Wox.Core.Plugin } catch (Exception e) { - Log.Error(new WoxPluginException(metadata.Name, "Can't create instance", e)); + Log.Exception(new WoxPluginException(metadata.Name, "Can't create instance", e)); continue; } PluginPair pair = new PluginPair @@ -90,13 +90,13 @@ namespace Wox.Core.Plugin } else { - Log.Error(new WoxException("Python can't be found in PATH.")); + Log.Exception(new WoxException("Python can't be found in PATH.")); return new List(); } } else { - Log.Error(new WoxException("Path variable is not set.")); + Log.Exception(new WoxException("Path variable is not set.")); return new List(); } } @@ -109,7 +109,7 @@ namespace Wox.Core.Plugin } else { - Log.Error(new WoxException("Can't find python executable in python directory")); + Log.Exception(new WoxException("Can't find python executable in python directory")); return new List(); } } diff --git a/Wox.Core/Resource/Internationalization.cs b/Wox.Core/Resource/Internationalization.cs index cce468624..4396fd249 100644 --- a/Wox.Core/Resource/Internationalization.cs +++ b/Wox.Core/Resource/Internationalization.cs @@ -29,7 +29,7 @@ namespace Wox.Core.Resource } catch (Exception e) { - Log.Error(e); + Log.Exception(e); } } } @@ -117,7 +117,7 @@ namespace Wox.Core.Resource catch (Exception e) { var woxPluginException = new WoxPluginException(pluginPair.Metadata.Name, "Update Plugin metadata translation failed:", e); - Log.Error(woxPluginException); + Log.Exception(woxPluginException); } } diff --git a/Wox.Core/Resource/Theme.cs b/Wox.Core/Resource/Theme.cs index 7782b55ad..d3473ad90 100644 --- a/Wox.Core/Resource/Theme.cs +++ b/Wox.Core/Resource/Theme.cs @@ -36,7 +36,7 @@ namespace Wox.Core.Resource } catch (Exception e) { - Log.Error(e); + Log.Exception(e); } } } diff --git a/Wox.Core/Updater.cs b/Wox.Core/Updater.cs index bfd06219a..1f3246852 100644 --- a/Wox.Core/Updater.cs +++ b/Wox.Core/Updater.cs @@ -34,16 +34,16 @@ namespace Wox.Core } catch (HttpRequestException he) { - Log.Error(he); + Log.Exception(he); } catch (WebException we) { - Log.Error(we); + Log.Exception(we); } catch (SocketException sc) { Log.Info("Socket exception happened!, which method cause this exception??"); - Log.Error(sc); + Log.Exception(sc); } catch (Exception exception) { @@ -72,7 +72,7 @@ namespace Wox.Core catch (WebException e) { Log.Warn("Can't connect to github api to check new version"); - Log.Error(e); + Log.Exception(e); return string.Empty; } @@ -85,7 +85,7 @@ namespace Wox.Core } catch (JsonSerializationException e) { - Log.Error(e); + Log.Exception(e); return string.Empty; } var version = json?["tag_name"]?.ToString(); diff --git a/Wox.Infrastructure/Image/ImageLoader.cs b/Wox.Infrastructure/Image/ImageLoader.cs index 478b1c7d5..f01b72f31 100644 --- a/Wox.Infrastructure/Image/ImageLoader.cs +++ b/Wox.Infrastructure/Image/ImageLoader.cs @@ -63,7 +63,7 @@ namespace Wox.Infrastructure.Image } catch (System.Exception e) { - Log.Error(e); + Log.Exception(e); return ImageSources[ErrorIcon]; } } @@ -94,7 +94,7 @@ namespace Wox.Infrastructure.Image } catch (System.Exception e) { - Log.Error(e); + Log.Exception(e); return ImageSources[ErrorIcon]; } } diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index 9931d1dae..acf90fbd3 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -35,19 +35,29 @@ namespace Wox.Infrastructure.Logger var type = $"{method.DeclaringType.NonNull().FullName}.{method.Name}"; return type; } - public static void Error(System.Exception e) + + public static void Error(string msg) { var type = CallerType(); var logger = LogManager.GetLogger(type); + System.Diagnostics.Debug.WriteLine($"ERROR: {msg}"); + logger.Error(msg); + } + + public static void Exception(System.Exception e) + { #if DEBUG throw e; #else - while (e.InnerException != null) + var type = CallerType(); + var logger = LogManager.GetLogger(type); + + do { logger.Error(e.Message); - logger.Error(e.StackTrace); + logger.Error($"\n{e.StackTrace}"); e = e.InnerException; - } + } while (e != null); #endif } diff --git a/Wox.Infrastructure/Storage/BinaryStorage.cs b/Wox.Infrastructure/Storage/BinaryStorage.cs index ed1246720..bc6d5919f 100644 --- a/Wox.Infrastructure/Storage/BinaryStorage.cs +++ b/Wox.Infrastructure/Storage/BinaryStorage.cs @@ -63,12 +63,12 @@ namespace Wox.Infrastructure.Storage } catch (SerializationException e) { - Log.Error(e); + Log.Exception(e); LoadDefault(); } catch (InvalidCastException e) { - Log.Error(e); + Log.Exception(e); LoadDefault(); } finally @@ -114,7 +114,7 @@ namespace Wox.Infrastructure.Storage } catch (SerializationException e) { - Log.Error(e); + Log.Exception(e); } } } diff --git a/Wox.Infrastructure/Storage/JsonStorage.cs b/Wox.Infrastructure/Storage/JsonStorage.cs index b67c02230..8a208bcc2 100644 --- a/Wox.Infrastructure/Storage/JsonStorage.cs +++ b/Wox.Infrastructure/Storage/JsonStorage.cs @@ -60,7 +60,7 @@ namespace Wox.Infrastructure.Storage catch (JsonSerializationException e) { LoadDefault(); - Log.Error(e); + Log.Exception(e); } } diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index e465eff63..e56d8eac5 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -6,6 +6,7 @@ using Wox.Core.Plugin; using Wox.Core.UserSettings; using Wox.Helper; using Wox.Infrastructure.Image; +using Wox.Infrastructure.Logger; using Wox.Infrastructure.Storage; using Wox.ViewModel; using Stopwatch = Wox.Infrastructure.Stopwatch; @@ -22,7 +23,8 @@ namespace Wox [STAThread] public static void Main() { - RegisterAppDomainUnhandledException(); + RegisterAppDomainExceptions(); + if (SingleInstance.InitializeAsFirstInstance(Unique)) { using (var application = new App()) @@ -74,18 +76,31 @@ namespace Wox Current.Exit += (s, e) => Dispose(); Current.SessionEnding += (s, e) => Dispose(); } + + /// + /// let exception throw as normal is better for Debug + /// [Conditional("RELEASE")] private void RegisterDispatcherUnhandledException() { - // let exception throw as normal is better for Debug DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException; } + + + /// + /// let exception throw as normal is better for Debug + /// [Conditional("RELEASE")] - private static void RegisterAppDomainUnhandledException() + private static void RegisterAppDomainExceptions() { - // let exception throw as normal is better for Debug + AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle; + AppDomain.CurrentDomain.FirstChanceException += (s, e) => + { + Log.Error("First Chance Exception:"); + Log.Exception(e.Exception); + }; } public void Dispose() diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 56af73314..289ae6df8 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -405,29 +405,30 @@ - xcopy /Y $(ProjectDir)Themes\* $(TargetDir)Themes\ - xcopy /Y /E $(ProjectDir)Images\* $(TargetDir)Images\ - xcopy /Y /D /E $(SolutionDir)Plugins\HelloWorldPython\* $(TargetDir)Plugins\HelloWorldPython\* +xcopy /Y $(ProjectDir)Themes\* $(TargetDir)Themes\ +xcopy /Y /E $(ProjectDir)Images\* $(TargetDir)Images\ +xcopy /Y /D /E $(SolutionDir)Plugins\HelloWorldPython\* $(TargetDir)Plugins\HelloWorldPython\* +cd $(SolutionDir)packages\squirrel*\tools +copy /Y Squirrel.exe $(TargetDir)..\Update.exe +cd $(SolutionDir) - - if $(ConfigurationName) == Release ( - cd "$(TargetDir)Plugins" & del /s /q NLog.dll - cd "$(TargetDir)Plugins" & del /s /q NLog.config - cd "$(TargetDir)Plugins" & del /s /q Wox.Plugin.pdb - cd "$(TargetDir)Plugins" & del /s /q Wox.Plugin.dll - cd "$(TargetDir)Plugins" & del /s /q Wox.Core.dll - cd "$(TargetDir)Plugins" & del /s /q Wox.Core.pdb - cd "$(TargetDir)Plugins" & del /s /q ICSharpCode.SharpZipLib.dll - cd "$(TargetDir)Plugins" & del /s /q NAppUpdate.Framework.dll - cd "$(TargetDir)Plugins" & del /s /q Wox.Infrastructure.dll - cd "$(TargetDir)Plugins" & del /s /q Wox.Infrastructure.pdb - cd "$(TargetDir)Plugins" & del /s /q Newtonsoft.Json.dll - cd "$(TargetDir)Plugins" & del /s /q JetBrains.Annotations.dll - cd "$(TargetDir)Plugins" & del /s /q Pinyin4Net.dll - - cd "$(TargetDir)" & del /s /q *.xml - ) +if $(ConfigurationName) == Release ( +cd "$(TargetDir)Plugins" & del /s /q NLog.dll +cd "$(TargetDir)Plugins" & del /s /q NLog.config +cd "$(TargetDir)Plugins" & del /s /q Wox.Plugin.pdb +cd "$(TargetDir)Plugins" & del /s /q Wox.Plugin.dll +cd "$(TargetDir)Plugins" & del /s /q Wox.Core.dll +cd "$(TargetDir)Plugins" & del /s /q Wox.Core.pdb +cd "$(TargetDir)Plugins" & del /s /q ICSharpCode.SharpZipLib.dll +cd "$(TargetDir)Plugins" & del /s /q NAppUpdate.Framework.dll +cd "$(TargetDir)Plugins" & del /s /q Wox.Infrastructure.dll +cd "$(TargetDir)Plugins" & del /s /q Wox.Infrastructure.pdb +cd "$(TargetDir)Plugins" & del /s /q Newtonsoft.Json.dll +cd "$(TargetDir)Plugins" & del /s /q JetBrains.Annotations.dll +cd "$(TargetDir)Plugins" & del /s /q Pinyin4Net.dll +cd "$(TargetDir)" & del /s /q *.xml +) @@ -438,11 +439,6 @@ !--> - - - - - - + \ No newline at end of file