private static void CopyOtherPrograms(List <string> otherAppPaths) { foreach (string path in otherAppPaths) { if (File.Exists($"{path}\\{_appConfigFilename}")) { BootstrapAppConfig tempConfig = GetSettingInfo(path); CopyProgramsToLaunchPath(tempConfig.AppPaths, tempConfig.FullLaunchPath, tempConfig.CopyRecursive ?? false); CopyOtherPrograms(tempConfig.OtherAppPaths); } } }
public static bool MustBootstrap(string[] args) { string joinedArgs = (args == null) ? "" : string.Join(" ", args); string currPath = Environment.CurrentDirectory; if (currPath.ToLower().Contains("\\debug\\") || currPath.ToLower().EndsWith("\\debug")) { return(false); // no bootstrapping when debugging } // not debugging bool result = true; string mainAppConfigPath = GetSettingsFilePath(); BootstrapAppConfig appConfig = GetSettingInfo(mainAppConfigPath); if (currPath.StartsWith(Environment.GetEnvironmentVariable("USERPROFILE"), StringComparison.OrdinalIgnoreCase)) { result = false; } if (!result) { // check if master program is newer/different than this program foreach (string path in appConfig.AppPaths) { string masterAppFilePath = $"{path}\\{AppDomain.CurrentDomain.FriendlyName}"; if (File.Exists(masterAppFilePath)) { FileInfo currAppInfo = new FileInfo($"{currPath}\\{AppDomain.CurrentDomain.FriendlyName}"); FileInfo masterAppInfo = new FileInfo(masterAppFilePath); if (currAppInfo.Length != masterAppInfo.Length // ignore differences less than one second, in case server filesystems are different || currAppInfo.LastWriteTimeUtc.Ticks + 10000000 < masterAppInfo.LastWriteTimeUtc.Ticks) { // double-bounce DoLaunchProgram(path, AppDomain.CurrentDomain.FriendlyName, joinedArgs); return(true); } } } } if (result) { // does need normal bootstrapping CopyProgramsToLaunchPath(appConfig.AppPaths, appConfig.FullLaunchPath, appConfig.CopyRecursive ?? false); CopyOtherPrograms(appConfig.OtherAppPaths); DoLaunchProgram(appConfig.FullLaunchPath, AppDomain.CurrentDomain.FriendlyName, joinedArgs); } return(result); }
private static BootstrapAppConfig GetSettingInfo(string appConfigPath) { BootstrapAppConfig result = new BootstrapAppConfig(); JObject appConfigSettings = JObject.Parse(File.ReadAllText($"{appConfigPath}\\{_appConfigFilename}")); string envName = (string)appConfigSettings.GetValueOrNull("RunFolderSuffix"); if (string.IsNullOrEmpty(envName)) { envName = (string)appConfigSettings.GetValueOrNull("Environment"); } string appName = (string)appConfigSettings.GetValueOrNull("Application"); result.FullLaunchPath = $"{_baseLaunchPath}\\{appName}_{envName}"; result.CopyRecursive = (bool?)appConfigSettings.GetValueOrNull("CopyRecursive"); result.OtherLaunchPaths = new List <string>(); result.AppPaths = new List <string>(); result.OtherAppPaths = new List <string>(); if (appConfigSettings.GetValueOrNull("OtherApplications") != null) { foreach (string tempAppName in (JArray)appConfigSettings.GetValueOrNull("OtherApplications")) { result.OtherLaunchPaths.Add($"{_baseLaunchPath}\\{tempAppName}_{envName}"); } } if (appConfigSettings.GetValueOrNull("AppPaths") != null) { foreach (string tempPath in (JArray)appConfigSettings.GetValueOrNull("AppPaths")) { result.AppPaths.Add(tempPath); } ; } if (appConfigSettings.GetValueOrNull("OtherAppPaths") != null) { foreach (string tempPath in (JArray)appConfigSettings.GetValueOrNull("OtherAppPaths")) { result.OtherAppPaths.Add(tempPath); } ; } return(result); }
public static Process LaunchApplication(string appName, string arguments) { string mainAppConfigPath = GetSettingsFilePath(); BootstrapAppConfig appConfig = GetSettingInfo(mainAppConfigPath); string launchPath = appConfig.FullLaunchPath; if (!File.Exists($"{appConfig.FullLaunchPath}\\{appName}.exe")) { launchPath = null; foreach (string tempLaunchPath in appConfig.OtherLaunchPaths) { if (File.Exists($"{tempLaunchPath}\\{appName}.exe")) { launchPath = tempLaunchPath; break; } } if (launchPath == null) { throw new FileNotFoundException(ErrorHandler.FixMessage($"File not found: {appConfig.FullLaunchPath}\\{appName}.exe")); } } return(DoLaunchProgram(launchPath, $"{appName}.exe", arguments)); }