static Logger() { // Set log level //LogLevel = (Status)Properties.Settings.Default.LogLevel; LogLevel = Status.Info; // Get working AppData Local directory string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NotCoffee418\\TrinityCreator"); if (Debugger.IsAttached) // Seperate directory for debugger { path = Path.Combine(path, "Debug"); } // Enter logs subdirectory & create if it doesn't exist. path = Path.Combine(path, "Logs"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // Create log filename with timestamp LogFilePath = Path.Combine(path, string.Format("tc-{0}.log", DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss"))); // Start log writer GHelper.SafeThreadStart(() => StartLogWriter()); // Application exit event Application.Current.Exit += Application_Exit; // Clean log files older than 6 months GHelper.SafeThreadStart(() => CleanLogs()); }
static Logger() { // Set log level //LogLevel = (Status)Properties.Settings.Default.LogLevel; LogLevel = Status.Info; string logsDir = GetLogsDirectory(); // Create log filename with timestamp LogFilePath = Path.Combine(logsDir, string.Format("tc-{0}.log", DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss"))); // Start log writer GHelper.SafeThreadStart(() => StartLogWriter()); // Application exit event Application.Current.Exit += Application_Exit; // Clean log files older than 6 months GHelper.SafeThreadStart(() => CleanLogs()); }
public static void UpdateProfiles() { // Update Profiles from https://github.com/NotCoffee418/TrinityCreatorProfiles Logger.Log("Updating Profiles from GitHub."); // Get relevant directories string sysProfilesDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Profiles"); string usrProfilesDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "TrinityCreator", "Profiles"); string tmpDir = Path.Combine(Path.GetTempPath(), "tc-" + GHelper.RandomString(6)); // Download repository, update any new files try { // Generate user profile directory if it doesn't exist (this function doesn't affect this folder aside from creating it) if (!Directory.Exists(usrProfilesDir)) { Directory.CreateDirectory(usrProfilesDir); } // Generate system profile directory if it doesn't exist if (!Directory.Exists(sysProfilesDir)) { Directory.CreateDirectory(sysProfilesDir); } // Generate tmp directory if it doesn't exist if (!Directory.Exists(tmpDir)) { Directory.CreateDirectory(tmpDir); } // Download latest version of profiles string zipPath = Path.Combine(tmpDir, "latest.zip"); string sourceUrl = "https://github.com/NotCoffee418/TrinityCreatorProfiles/archive/master.zip"; Logger.Log("Downloading updated profiles from '" + sourceUrl); using (var client = new WebClient()) { client.DownloadFile(sourceUrl, zipPath); } // Extract download & delete zip Logger.Log("Extracting downloaded profiles and deleting zip. Path: " + tmpDir); ZipFile.ExtractToDirectory(zipPath, tmpDir); File.Delete(zipPath); // Check each file to see if it's updated (using revision) Logger.Log("Installing updated profiles..."); foreach (string tmpFilePath in Directory.GetFiles(Path.Combine(tmpDir, "TrinityCreatorProfiles-master"))) { string fileName = Path.GetFileName(tmpFilePath); string profileDestPath = Path.Combine(sysProfilesDir, fileName); Logger.Log("Checking for new version on " + fileName); if (!File.Exists(profileDestPath)) { Logger.Log(fileName + ": is a new profile. Installing..."); File.Copy(tmpFilePath, profileDestPath); } else // profile exists, check if it's a new version { Profile localVer = Profile.LoadFile(profileDestPath, false); // Not error display, versions for older version of app will default to rev 0 Profile remoteVer = Profile.LoadFile(tmpFilePath, true); // display error, if the downloaded version is corrupt, we have an issue if (remoteVer.Revision > localVer.Revision) // New version found, install { Logger.Log($"{fileName}: New version found. Updating from revision {localVer.Revision} to {remoteVer.Revision}."); File.Copy(tmpFilePath, profileDestPath, overwrite: true); } else // Up to date { Logger.Log($"{fileName}: Up to date."); } } } } catch (Exception ex) { Logger.Log("Failed to update profiles from GitHub: " + ex.Message, Logger.Status.Warning, true); } finally { // Delete temp dir if (Directory.Exists(tmpDir)) { Directory.Delete(tmpDir, recursive: true); } } }
public static void UpdateProfiles() { // Update Profiles from https://github.com/NotCoffee418/TrinityCreatorProfiles Logger.Log("Updater: Updating Profiles from GitHub."); // Get relevant directories string sysProfilesDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NotCoffee418", "TrinityCreator", "Profiles"); string usrProfilesDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "TrinityCreator", "Profiles"); string tmpDir = Path.Combine(Path.GetTempPath(), "tc-" + GHelper.RandomString(6)); // Download repository, update any new files try { // Generate user profile directory if it doesn't exist (this function doesn't affect this folder aside from creating it) if (!Directory.Exists(usrProfilesDir)) { Directory.CreateDirectory(usrProfilesDir); } // Generate system profile directory if it doesn't exist if (!Directory.Exists(sysProfilesDir)) { Directory.CreateDirectory(sysProfilesDir); } // Generate tmp directory if it doesn't exist if (!Directory.Exists(tmpDir)) { Directory.CreateDirectory(tmpDir); } // Download latest version of profiles string zipPath = Path.Combine(tmpDir, "latest.zip"); string sourceUrl = "https://github.com/NotCoffee418/TrinityCreatorProfiles/archive/master.zip"; Logger.Log("Updater: Downloading updated profiles from '" + sourceUrl); using (var client = new WebClient()) { client.DownloadFile(sourceUrl, zipPath); } // Extract download & delete zip Logger.Log("Updater: Extracting downloaded profiles and cleaning zip. Path: " + tmpDir); ZipFile.ExtractToDirectory(zipPath, tmpDir); File.Delete(zipPath); // Check each file to see if it's updated (using revision) Logger.Log("Updater: Installing updated profiles..."); bool isOutdatedTcForProfiles = false; foreach (string tmpFilePath in Directory.GetFiles(Path.Combine(tmpDir, "TrinityCreatorProfiles-master"))) { string fileName = Path.GetFileName(tmpFilePath); string profileDestPath = Path.Combine(sysProfilesDir, fileName); Logger.Log("Checking for new version on " + fileName); if (!File.Exists(profileDestPath)) { Logger.Log(fileName + ": is a new profile. Installing..."); File.Copy(tmpFilePath, profileDestPath); } else // profile exists, check if it's a new version { Profile localVer = Profile.LoadFile(profileDestPath, false); // Not error display, versions for older version of app will default to rev 0 Profile remoteVer = Profile.LoadFile(tmpFilePath, true); // display error, if the downloaded version is corrupt, we have an issue if (remoteVer.Revision > localVer.Revision) // New version found, install { Logger.Log($"Updater: {fileName} - New version found."); int runningAppBuild = Assembly.GetExecutingAssembly().GetName().Version.Revision; if (remoteVer.TestedBuild > runningAppBuild) // profile may not support this version of Tcreator { // used to show warning, doesn't update isOutdatedTcForProfiles = true; Logger.Log($"Updater: Profile {fileName} was tested on a newer version of Trinity Creator. Not updating or installing local file.", Logger.Status.Warning, false); } else { Logger.Log($"Updater: Updating {fileName} from revision {localVer.Revision} to {remoteVer.Revision}."); File.Copy(tmpFilePath, profileDestPath, overwrite: true); } } else // Up to date { Logger.Log($"{fileName}: Up to date."); } } } // Show warning profiles are newer than build if (isOutdatedTcForProfiles) { Logger.Log("Profile: Some profiles were not installed or updated as this version of Trinity Creator may not support them." + Environment.NewLine + "Please update Trinity Creator to resolve this issue. (Help > Check for updates)", Logger.Status.Warning, true); } } catch (Exception ex) { Logger.Log("Failed to update profiles from GitHub: " + ex.Message, Logger.Status.Warning, true); } finally { // Delete temp dir if (Directory.Exists(tmpDir)) { Directory.Delete(tmpDir, recursive: true); } } }