/// <inheritdoc /> public void LaunchUpdater(Version version, bool restart = true) { version.GuardNotNull(nameof(version)); // Ensure update has been prepared if (!IsUpdatePrepared(version)) { throw new UpdateNotPreparedException(version); } // Ensure updater hasn't been launched yet if (_updaterLaunched) { throw new UpdaterAlreadyLaunchedException(); } // Get current process ID var currentProcessId = ProcessEx.GetCurrentProcessId(); // Get package content directory path var packageContentDirPath = GetPackageContentDirPath(version); // Prepare arguments var args = $"{currentProcessId} " + $"\"{_updatee.FilePath}\" " + $"\"{packageContentDirPath}\" " + $"{restart}"; // Decide if updater needs to be elevated var isElevated = !DirectoryEx.CheckWriteAccess(_updatee.DirectoryPath); // Launch the updater ProcessEx.StartCli(_updaterFilePath, args, isElevated); _updaterLaunched = true; }
/// <inheritdoc /> public void LaunchUpdater(Version version, bool restart = true) { version.GuardNotNull(nameof(version)); // Ensure that the current state is valid for this operation EnsureNotDisposed(); EnsureLockFileAcquired(); EnsureUpdaterNotLaunched(); EnsureUpdatePrepared(version); // Get package content directory path var packageContentDirPath = GetPackageContentDirPath(version); // Prepare arguments var updaterArgs = $"\"{_updatee.FilePath}\" \"{packageContentDirPath}\" {restart}"; // Decide if updater needs to be elevated var updateeDirPath = Path.GetDirectoryName(_updatee.FilePath); var isUpdaterElevated = !DirectoryEx.CheckWriteAccess(updateeDirPath); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // Create updater process start info var updaterStartInfo = new ProcessStartInfo { FileName = "dotnet", Arguments = _updaterFilePath + " " + updaterArgs, CreateNoWindow = true, UseShellExecute = true }; // If updater needs to be elevated - use shell execute with "runas" if (isUpdaterElevated) { updaterStartInfo.Verb = "runas"; updaterStartInfo.UseShellExecute = true; } // Create and start updater process var updaterProcess = new Process { StartInfo = updaterStartInfo }; using (updaterProcess) updaterProcess.Start(); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = "/bin/bash"; proc.StartInfo.Arguments = "-c \" " + "dotnet " + _updaterFilePath + " " + updaterArgs + " \""; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.Start(); } }
/// <inheritdoc /> public void LaunchUpdater(Version version, bool restart, string restartArguments) { // Ensure that the current state is valid for this operation EnsureNotDisposed(); EnsureLockFileAcquired(); EnsureUpdaterNotLaunched(); EnsureUpdatePrepared(version); // Get package content directory path var packageContentDirPath = GetPackageContentDirPath(version); // Get original command line arguments and encode them to avoid issues with quotes var routedArgs = restartArguments.GetBytes().ToBase64(); // Prepare arguments var updaterArgs = $"\"{Updatee.FilePath}\" \"{packageContentDirPath}\" \"{restart}\" \"{routedArgs}\""; // Decide if updater needs to be elevated var updateeDirPath = Path.GetDirectoryName(Updatee.FilePath); var isUpdaterElevated = !string.IsNullOrWhiteSpace(updateeDirPath) && !DirectoryEx.CheckWriteAccess(updateeDirPath); // Create updater process start info var updaterStartInfo = new ProcessStartInfo(); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { updaterStartInfo.FileName = _updaterFilePath; updaterStartInfo.Arguments = updaterArgs; updaterStartInfo.CreateNoWindow = true; updaterStartInfo.UseShellExecute = false; } else { updaterStartInfo.FileName = "dotnet"; updaterStartInfo.Arguments = $"{_updaterFilePath} {updaterArgs}"; } // If updater needs to be elevated - use shell execute with "runas" if (isUpdaterElevated) { updaterStartInfo.Verb = "runas"; updaterStartInfo.UseShellExecute = true; } // Create and start updater process var updaterProcess = new Process { StartInfo = updaterStartInfo }; using (updaterProcess) updaterProcess.Start(); }
/// <inheritdoc /> public void LaunchUpdater(Version version, bool restart = true) { // Ensure that the current state is valid for this operation EnsureNotDisposed(); EnsureLockFileAcquired(); EnsureUpdaterNotLaunched(); EnsureUpdatePrepared(version); // Get package content directory path var packageContentDirPath = GetPackageContentDirPath(version); // Get original command line arguments and encode them to avoid issues with quotes var routedArgs = EnvironmentEx.GetCommandLineWithoutExecutable().GetString().ToBase64(); // Prepare arguments var updaterArgs = $"\"{_updatee.FilePath}\" \"{packageContentDirPath}\" \"{restart}\" \"{routedArgs}\""; // Decide if updater needs to be elevated var updateeDirPath = Path.GetDirectoryName(_updatee.FilePath); var isUpdaterElevated = !DirectoryEx.CheckWriteAccess(updateeDirPath); // Create updater process start info var updaterStartInfo = new ProcessStartInfo { FileName = _updaterFilePath, Arguments = updaterArgs, CreateNoWindow = true, UseShellExecute = false }; // If updater needs to be elevated - use shell execute with "runas" if (isUpdaterElevated) { updaterStartInfo.Verb = "runas"; updaterStartInfo.UseShellExecute = true; } // Create and start updater process var updaterProcess = new Process { StartInfo = updaterStartInfo }; using (updaterProcess) updaterProcess.Start(); }
/// <inheritdoc /> public void LaunchUpdater(Version version, bool restart = true) { version.GuardNotNull(nameof(version)); // Ensure that the current state is valid for this operation EnsureNotDisposed(); EnsureLockFileAcquired(); EnsureUpdaterNotLaunched(); EnsureUpdatePrepared(version); // Get package content directory path var packageContentDirPath = GetPackageContentDirPath(version); // Prepare arguments var updaterArgs = $"\"{_updatee.FilePath}\" \"{packageContentDirPath}\" {restart}"; // Decide if updater needs to be elevated var updateeDirPath = Path.GetDirectoryName(_updatee.FilePath); var isUpdaterElevated = !DirectoryEx.CheckWriteAccess(updateeDirPath); // Create updater process start info var updaterStartInfo = new ProcessStartInfo { FileName = _updaterFilePath, Arguments = updaterArgs, CreateNoWindow = true, UseShellExecute = false }; // If updater needs to be elevated - use shell execute with "runas" if (isUpdaterElevated) { updaterStartInfo.Verb = "runas"; updaterStartInfo.UseShellExecute = true; } // Create and start updater process var updaterProcess = new Process { StartInfo = updaterStartInfo }; using (updaterProcess) updaterProcess.Start(); }
public SettingsService() { var installerMarker = Path.Combine(AppDomain.CurrentDomain.BaseDirectory ?? Directory.GetCurrentDirectory(), ".installed"); var isInstalled = File.Exists(installerMarker); // Prefer storing settings in appdata when installed or when current directory is write-protected if (isInstalled || !DirectoryEx.CheckWriteAccess(App.ExecutableDirPath)) { Configuration.StorageSpace = StorageSpace.SyncedUserDomain; Configuration.SubDirectoryPath = "LightBulb"; } // Otherwise, store them in the current directory else { Configuration.StorageSpace = StorageSpace.Instance; Configuration.SubDirectoryPath = ""; } Configuration.FileName = "Settings.json"; Configuration.ThrowIfCannotLoad = false; Configuration.ThrowIfCannotSave = true; }
public SettingsService() { var applicationDirPath = AppDomain.CurrentDomain.BaseDirectory; // If we have write access to application directory - store configuration file there if (DirectoryEx.CheckWriteAccess(applicationDirPath)) { Configuration.FileName = "Settings.dat"; Configuration.SubDirectoryPath = ""; Configuration.StorageSpace = StorageSpace.Instance; } // Otherwise - store settings in roaming app data directory else { Configuration.FileName = "Settings.dat"; Configuration.SubDirectoryPath = "LightBulb"; Configuration.StorageSpace = StorageSpace.SyncedUserDomain; } // Ignore failures when loading/saving settings Configuration.ThrowIfCannotLoad = false; Configuration.ThrowIfCannotSave = false; }
public SettingsService() { // If we have write access to application directory - store configuration file there if (DirectoryEx.CheckWriteAccess(App.ExecutableDirPath)) { Configuration.SubDirectoryPath = ""; Configuration.StorageSpace = StorageSpace.Instance; } // Otherwise - store settings in roaming app data directory else { Configuration.SubDirectoryPath = "LightBulb"; Configuration.StorageSpace = StorageSpace.SyncedUserDomain; } Configuration.FileName = "Settings.json"; Configuration.ThrowIfCannotLoad = false; Configuration.ThrowIfCannotSave = true; // Auto-start by default in release builds #if !DEBUG IsAutoStartEnabled = true; #endif }