public static async Task AddOrRemoveDesktopFileAsync(bool runOnSystemStartup) { string pathToDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config", "autostart"); string pathToDesktopFile = Path.Combine(pathToDir, "Wasabi.desktop"); IoHelpers.EnsureContainingDirectoryExists(pathToDesktopFile); if (runOnSystemStartup) { string pathToExec = EnvironmentHelpers.GetExecutablePath(); string pathToExecWithArgs = $"{pathToExec} {StartupHelper.SilentArgument}"; IoHelpers.EnsureFileExists(pathToExec); string fileContents = string.Join( "\n", "[Desktop Entry]", $"Name={Constants.AppName}", "Type=Application", $"Exec={pathToExecWithArgs}", "Hidden=false", "Terminal=false", "X-GNOME-Autostart-enabled=true"); await File.WriteAllTextAsync(pathToDesktopFile, fileContents).ConfigureAwait(false); } else { File.Delete(pathToDesktopFile); } }
private async Task InitializeTransactionsNoMutexAsync() { try { IoHelpers.EnsureFileExists(TransactionsFileManager.FilePath); var allLines = await TransactionsFileManager.ReadAllLinesAsync().ConfigureAwait(false); var allTransactions = allLines .Select(x => SmartTransaction.FromLine(x, Network)) .OrderByBlockchain(); lock (TransactionsLock) { TryAddNoLockNoSerialization(allTransactions); } if (allTransactions.Count() != Transactions.Count) { // Another process worked into the file and appended the same transaction into it. // In this case we correct the file by serializing the unique set. await SerializeAllTransactionsNoMutexAsync().ConfigureAwait(false); } } catch { // We found a corrupted entry. Stop here. // Delete the currupted file. // Do not try to autocorrect, because the internal data structures are throwing events that may confuse the consumers of those events. Logger.LogError($"{TransactionsFileManager.FileNameWithoutExtension} file got corrupted. Deleting it..."); TransactionsFileManager.DeleteMe(); throw; } }
private async Task InitializeTransactionsNoLockAsync(CancellationToken cancel) { try { IoHelpers.EnsureFileExists(TransactionsFileManager.FilePath); cancel.ThrowIfCancellationRequested(); var allLines = await TransactionsFileManager.ReadAllLinesAsync(cancel).ConfigureAwait(false); var allTransactions = allLines .Select(x => SmartTransaction.FromLine(x, Network)) .OrderByBlockchain(); var added = false; var updated = false; lock (TransactionsLock) { foreach (var tx in allTransactions) { var(isAdded, isUpdated) = TryAddOrUpdateNoLockNoSerialization(tx); if (isAdded) { added = true; } if (isUpdated) { updated = true; } } } if (added || updated) { cancel.ThrowIfCancellationRequested(); // Another process worked into the file and appended the same transaction into it. // In this case we correct the file by serializing the unique set. await SerializeAllTransactionsNoLockAsync().ConfigureAwait(false); } } catch (Exception ex) when(ex is not OperationCanceledException) { // We found a corrupted entry. Stop here. // Delete the currupted file. // Do not try to autocorrect, because the internal data structures are throwing events that may confuse the consumers of those events. Logger.LogError($"{TransactionsFileManager.FileNameWithoutExtension} file got corrupted. Deleting it..."); TransactionsFileManager.DeleteMe(); throw; } }