Exemple #1
0
        /// <summary>
        ///     Generates a log.txt file on the root of the USB Drive and a log-date.txt file in LogPath
        /// </summary>
        /// <param name="log">Additional log to append, usually the log textbox</param>
        /// <param name="upload">Set to true to upload log file <see cref="UploadLog" />, else false to only save it to USB drive</param>
        public async static Task GenerateLog(string log, bool upload)
        {
            StringBuilder data = new($@"CYANLABS - SYN3 UPDATER - V{Assembly.GetExecutingAssembly().GetName().Version}{Environment.NewLine}");

            data.Append(@"Branch: ").Append(AppMan.App.LauncherPrefs.ReleaseTypeInstalled).Append(Environment.NewLine)
            .Append(@"Operating System: ").Append(SystemHelper.GetOsFriendlyName()).Append(Environment.NewLine)
            .Append(Environment.NewLine)
            .Append($@"PREVIOUS CONFIGURATION{Environment.NewLine}")
            .Append($@"Version: {AppMan.App.SVersion}{Environment.NewLine}")
            .Append($@"Region: {AppMan.App.Settings.CurrentRegion}{Environment.NewLine}")
            .Append($@"Navigation: {AppMan.App.Settings.CurrentNav}{Environment.NewLine}")
            .Append($@"Install Mode: {AppMan.App.Settings.InstallMode} ({AppMan.App.InstallMode}){Environment.NewLine}")
            .Append($@"Install Mode Overridden: {AppMan.App.ModeForced}{Environment.NewLine}");

            if (AppMan.App.Settings.My20v2 == null)
            {
                data.Append($@"My20 Protection Enabled: {LM.GetValue("String.AutoDetect")}{Environment.NewLine}");
            }
            else if (AppMan.App.Settings.My20v2 == true)
            {
                data.Append($@"My20 Protection Enabled: {LM.GetValue("String.Enabled")}{Environment.NewLine}");
            }
            else if (AppMan.App.Settings.My20v2 == false)
            {
                data.Append($@"My20 Protection Enabled: {LM.GetValue("String.Disabled")}{Environment.NewLine}");
            }

            data.Append(Environment.NewLine).Append("DESTINATION DETAILS").Append(Environment.NewLine);
            if (AppMan.App.DownloadToFolder)
            {
                data.Append("Mode: Directory").Append(Environment.NewLine)
                .Append(@"Path: ").Append(AppMan.App.DriveLetter).Append(Environment.NewLine);
            }
            else
            {
                data.Append("Mode: Drive").Append(Environment.NewLine)
                .Append("Model: ").Append(AppMan.App.DriveName).Append(Environment.NewLine)
                .Append("FileSystem: ").Append(AppMan.App.DriveFileSystem).Append(Environment.NewLine)
                .Append("Partition Type: ").Append(AppMan.App.DrivePartitionType).Append(Environment.NewLine);
            }

            string driveletter = AppMan.App.DriveLetter;

            if (File.Exists($@"{driveletter}\reformat.lst"))
            {
                data.Append(Environment.NewLine)
                .Append("REFORMAT.LST").Append(Environment.NewLine)
                .Append(File.ReadAllText($@"{driveletter}\reformat.lst")).Append(Environment.NewLine);
            }

            if (File.Exists($@"{driveletter}\autoinstall.lst"))
            {
                data.Append(Environment.NewLine)
                .Append("AUTOINSTALL.LST").Append(Environment.NewLine)
                .Append(File.ReadAllText($@"{driveletter}\autoinstall.lst")).Append(Environment.NewLine);
            }

            if (Directory.Exists($@"{driveletter}\SyncMyRide"))
            {
                data.Append(Environment.NewLine);
                DirectoryInfo di       = new($@"{driveletter}\SyncMyRide");
                FileInfo[]    allFiles = di.GetFiles("*", SearchOption.AllDirectories);
                data.Append($"FILES ({allFiles.Length}){Environment.NewLine}");
                foreach (FileInfo file in allFiles)
                {
                    data.Append($"{file.Name} ({MathHelper.BytesToString(file.Length)}){Environment.NewLine}");
                }
                data.Append(Environment.NewLine);
            }

            data.Append("LOG").Append(Environment.NewLine)
            .Append(log);
            string complete    = data.ToString();
            string currentDate = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");

            try
            {
                File.WriteAllText($@"{driveletter}\log.txt", complete);
                File.WriteAllText($@"{AppMan.App.MainSettings.LogPath}log-{currentDate}.txt", complete);
            }
            catch (DirectoryNotFoundException e)
            {
                await Application.Current.Dispatcher.BeginInvoke(() => UIHelper.ShowErrorDialog(e.GetFullMessage()));
            }
            catch (UnauthorizedAccessException e)
            {
                await Application.Current.Dispatcher.BeginInvoke(() => UIHelper.ShowErrorDialog(e.GetFullMessage()));
            }

            if (upload)
            {
                await UploadLog(complete);
            }
        }