public static CheckForUpdatesResponse CheckForUpdates(bool verbose = false) { try { CheckForUpdatesResponse response; AppUsageData data = AppSettings.Default.UsageData; data.Reload(); if (data.LastCheckedForUpdates.GetValueOrDefault() < DateTime.Now.AddHours(-1)) { response = WebApiClient.CheckForUpdates(AppSettings.Default.SdkTable.Revision); if (!string.IsNullOrEmpty(response.NewSdkTable) && SerDes.TryXmlStringToObject(response.NewSdkTable, out SdkTable table)) { SerDes.ObjectToXmlFile(table, AppSettings.Default.SdkTableCurrentPath); AppSettings.Default.SdkTable = table; } data.LastCheckedForUpdates = DateTime.Now; data.UpToDate = response.UpToDate; data.NewVersion = response.NewVersion; data.DownloadUrl = response.DownloadUrl; data.Save(); } else { // prevent new Flutnet installations to report // old server responses if (!data.UpToDate && !string.IsNullOrEmpty(data.NewVersion)) { string productVersion = Assembly.GetEntryAssembly().GetProductVersion(); int compare = VersionUtils.Compare(productVersion, data.NewVersion); if (compare >= 0) { data.UpToDate = true; data.Save(); } } response = new CheckForUpdatesResponse { UpToDate = data.UpToDate, NewVersion = data.NewVersion, DownloadUrl = data.DownloadUrl }; } return(response); } catch (Exception ex) { Log.Ex(ex); Console.WriteLine(ex); throw; } }
public AppSettings() { AppPath = AppDataFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); UsageData = new AppUsageData(Path.Combine(AppDataFolder, AppUsageDataFilename)); string repoRootFolder = Path.GetFullPath(Path.Combine(AppPath, "../../../../..")); TemplatesFolder = Path.Combine(repoRootFolder, "assets", "templates"); SdkTableDefaultPath = Path.Combine(repoRootFolder, "assets", SdkTableFilename); SdkTableCurrentPath = Path.Combine(AppDataFolder, SdkTableFilename); }
public void Configure(IConfiguration configuration) { string path = configuration.GetValue("AppDataFolder", string.Empty); if (!string.IsNullOrEmpty(path)) { AppDataFolder = path; if (!Directory.Exists(AppDataFolder)) { Directory.CreateDirectory(AppDataFolder); } UsageData = new AppUsageData(Path.Combine(AppDataFolder, AppUsageDataFilename)); } path = configuration.GetValue("TemplatesFolder", string.Empty); if (!string.IsNullOrEmpty(path)) { TemplatesFolder = path; } }
public AppSettings() { //To get the location the assembly is executing from (not necessarily where the it normally resides on disk) //In case of shadow copies usage, for instance in NUnit tests, this will be in a temp directory. //string path = Assembly.GetExecutingAssembly().Location; //To get the location the assembly normally resides on disk or the install directory string path = Assembly.GetExecutingAssembly().CodeBase; if (path.StartsWith("file:///", StringComparison.InvariantCultureIgnoreCase)) { path = path.Substring(8); } //once you have the path you get the directory with: AppPath = Path.GetDirectoryName(path); Assembly assembly = Assembly.GetExecutingAssembly(); string company = assembly.GetCustomAttribute <AssemblyCompanyAttribute>()?.Company ?? "Novagem Solutions"; string product = assembly.GetCustomAttribute <AssemblyProductAttribute>()?.Product ?? "Flutnet"; if (Utilities.OperatingSystem.IsMacOS()) { AppDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Library", "Application Support", company, product); TemplatesFolder = Path.GetFullPath(Path.Combine(AppPath, "..", "Resources", "Templates")); SdkTableDefaultPath = Path.GetFullPath(Path.Combine(AppPath, "..", "Resources", SdkTableFilename)); } else { AppDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), company, product); TemplatesFolder = Path.GetFullPath(Path.Combine(AppPath, "..", "resources", "templates")); SdkTableDefaultPath = Path.GetFullPath(Path.Combine(AppPath, "..", "resources", SdkTableFilename)); } if (!Directory.Exists(AppDataFolder)) { Directory.CreateDirectory(AppDataFolder); } UsageData = new AppUsageData(Path.Combine(AppDataFolder, AppUsageDataFilename)); SdkTableCurrentPath = Path.Combine(AppDataFolder, SdkTableFilename); }