Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Fix issue #95
Browse files Browse the repository at this point in the history
  • Loading branch information
aleab committed Sep 2, 2018
1 parent f7b07df commit 64279e8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
11 changes: 10 additions & 1 deletion InstallationScript/Install.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,14 @@ Section "${APPNAME} (required)"
File "LICENSE"
File "LICENSE-3RD-PARTY"

# Create directories in AppData
CreateDirectory "$APPDATA\Toastify"
CreateDirectory "$LOCALAPPDATA\Toastify"

# Remove files belonging to old versions
Delete "$INSTDIR\Garlic.dll"
Delete "$INSTDIR\uninstall.exe"

# Write the uninstall keys for Windows
WriteRegStr HKLM "${RegUninstallKey}" "DisplayName" "${APPNAME}"
WriteRegStr HKLM "${RegUninstallKey}" "DisplayIcon" "$INSTDIR\Toastify.exe,0"
Expand Down Expand Up @@ -244,6 +248,11 @@ Function .onInit
Pop $R0
FunctionEnd

Function un.onUninstSuccess
RMDir "$APPDATA\Toastify"
RMDir "$LOCALAPPDATA\Toastify"
FunctionEnd

Function LaunchApplication
# Should we use some command line argument?
${If} $PrevAutostartArgs != ""
Expand Down
58 changes: 44 additions & 14 deletions Toastify/src/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,8 @@ public static void Main(string[] args)
}
catch (Exception e)
{
App.EmergencyLog(e);
Debug.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {e}\n");
try
{
File.AppendAllText(Path.Combine(App.LocalApplicationData, "log.log"), $@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {e}{Environment.NewLine}");
}
catch (Exception ee)
{
MessageBox.Show(ee.ToString(), "FATAL ERROR!", MessageBoxButton.OK, MessageBoxImage.Error);
}
}

logger.Info($"Architecture: IntPtr = {IntPtr.Size * 8}bit, Is64BitProcess = {Environment.Is64BitProcess}, Is64BitOS = {Environment.Is64BitOperatingSystem}");
Expand Down Expand Up @@ -110,13 +103,11 @@ private static void ProcessCommandLineArguments(string[] args)
{
try
{
if (args != null)
File.AppendAllText(Path.Combine(App.LocalApplicationData, "log.log"), $@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - args: {string.Join(" ", args)}{Environment.NewLine}");
AppArgs = args != null && args.Length > 0 ? Args.Parse<MainArgs>(args) : new MainArgs();
}
catch (Exception e)
{
File.AppendAllText(Path.Combine(App.LocalApplicationData, "log.log"), $@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {e.Message}{Environment.NewLine}");
App.EmergencyLog(e);
logger.Warn("Invalid command-line arguments. Toastify will ignore them all.", e);

MessageBox.Show("Invalid command-line arguments. Toastify will ignore them all.", "Invalid arguments", MessageBoxButton.OK, MessageBoxImage.Warning);
Expand Down Expand Up @@ -506,15 +497,32 @@ public partial class App : Application
#region Static Fields and Properties

private static readonly ProxyConfig noProxy = new ProxyConfig();
private static readonly string _applicationData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Toastify");
private static readonly string _localApplicationData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Toastify");

// ReSharper disable once InconsistentNaming
private static ProxyConfigAdapter _proxyConfig;

public static WindsorContainer Container { get; private set; }

public static string ApplicationData { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Toastify");
public static string ApplicationData
{
get
{
if (!Directory.Exists(_applicationData))
Directory.CreateDirectory(_applicationData);
return _applicationData;
}
}

public static string LocalApplicationData { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Toastify");
public static string LocalApplicationData
{
get
{
if (!Directory.Exists(_localApplicationData))
Directory.CreateDirectory(_localApplicationData);
return _localApplicationData;
}
}

public static CultureInfo UserUICulture { get; set; }

Expand Down Expand Up @@ -585,6 +593,28 @@ public App(string spotifyArgs)

#region Static Members

public static void EmergencyLog(string logMessage)
{
if (string.IsNullOrWhiteSpace(logMessage))
return;

try
{
File.AppendAllText(Path.Combine(LocalApplicationData, "log.log"), $@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {logMessage}{Environment.NewLine}");
}
catch
{
// ignored
}
}

public static void EmergencyLog(Exception exception)
{
if (string.IsNullOrWhiteSpace(exception?.Message))
return;
EmergencyLog(exception.ToString());
}

public static void ShowConfigProxyDialog()
{
CallInSTAThread(() =>
Expand Down

0 comments on commit 64279e8

Please sign in to comment.