Exemple #1
0
        public MainWindow()
        {
            InitializeComponent();
            AppMan.Logger.Debug("MainWindow Initialized");
            if (CryptoConfig.AllowOnlyFipsAlgorithms)
            {
                // Do not replace with ContentDialog
                MessageBox.Show(
                    "Syn3 Updater has detected that 'Use FIPS Compliant algorithms for encryption, hashing, and signing.' is enforced via Group Policy, Syn3 Updater will be unable to validate any files using MD5 with this policy enforced and therefore is currently unable to function\n\nThe application will now close!",
                    LM.GetValue("String.Notice"), MessageBoxButton.OK, MessageBoxImage.Error);
                AppMan.App.Exit();
            }

            try
            {
                object v = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Windows Defender Exploit Guard\Controlled Folder Access",
                                             "EnableControlledFolderAccess", "0");
                if (v != null && v.ToString() != "0")
                {
                    if (Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Windows Defender Exploit Guard\Controlled Folder Access\AllowedApplications",
                                          Assembly.GetExecutingAssembly().Location, null) == null)
                    {
                        MessageBox.Show(
                            "Syn3 Updater has detected that 'Controlled Folder Access' is enabled on this computer\n\nSyn3 Updater may be unable to read or write to files at certain locations, to prevent potential issues please exclude Syn3 Updater from Controlled Folder Access or ensure you are using a folder that is not protected.",
                            LM.GetValue("String.Notice"), MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
            }
            catch
            {
                // ignored
            }
        }
Exemple #2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace((string)value))
                {
                    return(LM.GetValue(parameter?.ToString(), value.ToString()));
                }
            }
            catch
            {
                // ignored
            }

            return(LM.GetValue(parameter?.ToString()));
        }
Exemple #3
0
 /// <summary>
 /// </summary>
 /// <param name="content"></param>
 /// <param name="title"></param>
 /// <param name="secondarybutton"></param>
 /// <param name="defaultbutton"></param>
 /// <param name="cancel"></param>
 /// <param name="primarybutton"></param>
 /// <returns></returns>
 public static async Task ShowErrorDialog(string content, string cancel = null)
 {
     try
     {
         SequentialDialog contentDialog = new()
         {
             Title           = LM.GetValue("String.Error"),
             Content         = content,
             CloseButtonText = string.IsNullOrEmpty(cancel) ? LM.GetValue("String.OK") : cancel,
             Background      = Brushes.DarkRed,
             Foreground      = Brushes.White
         };
         await DialogManager.OpenDialogAsync(contentDialog, true);
     }
     catch (InvalidOperationException)
     {
     }
 }
Exemple #4
0
 public static async Task OpenWebPage(string url)
 {
     try
     {
         Process.Start(url);
     }
     catch (System.ComponentModel.Win32Exception)
     {
         Clipboard.SetText(url);
         await Application.Current.Dispatcher.BeginInvoke(() => UIHelper.ShowDialog(LM.GetValue("MessageBox.NoBrowser"),LM.GetValue("String.Notice"),LM.GetValue("Download.CancelButton")));
     }
 }
Exemple #5
0
        /// <summary>
        ///     Refreshes device list using WMI queries
        /// </summary>
        /// <param name="fakeusb">Set to true to add 'Download Only' option to the list</param>
        /// <returns>ObservableCollection of all USB Drives as type Drive</returns>
        public static ObservableCollection <Drive> RefreshDevices(bool fakeusb)
        {
            ObservableCollection <Drive> driveList  = new();
            ManagementObjectSearcher     driveQuery = new("select * from Win32_DiskDrive Where InterfaceType = \"USB\" OR MediaType = \"External hard disk media\"");

            foreach (ManagementBaseObject n in driveQuery.Get())
            {
                ManagementObject d            = (ManagementObject)n;
                string           friendlySize = MathHelper.BytesToString(Convert.ToInt64(d.Properties["Size"].Value));

                if (friendlySize == "0B")
                {
                    continue;
                }

                Drive  drive = new();
                string partitionQueryText = $@"associators of {{{d.Path.RelativePath}}} where AssocClass = Win32_DiskDriveToDiskPartition";
                ManagementObjectSearcher partitionQuery = new(partitionQueryText);
                foreach (ManagementBaseObject o in partitionQuery.Get())
                {
                    ManagementObject         p = (ManagementObject)o;
                    string                   logicalDriveQueryText = $@"associators of {{{p.Path.RelativePath}}} where AssocClass = Win32_LogicalDiskToPartition";
                    ManagementObjectSearcher logicalDriveQuery     = new(logicalDriveQueryText);
                    foreach (ManagementBaseObject managementBaseObject in logicalDriveQuery.Get())
                    {
                        ManagementObject         ld = (ManagementObject)managementBaseObject;
                        ManagementObjectSearcher encryptedDriveQuery = new("\\\\.\\ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption", $"select * from Win32_EncryptableVolume Where DriveLetter = \"{ld.Properties["DeviceId"].Value}\"");
                        foreach (ManagementBaseObject encryptedDriveObject in encryptedDriveQuery.Get())
                        {
                            uint encryptionStatus = (uint)encryptedDriveObject.GetPropertyValue("ProtectionStatus");
                            drive.Encrypted = encryptionStatus != 0;
                            if (drive.Encrypted)
                            {
                                drive.EncryptionStatus = LM.GetValue("String.Encrypted");
                            }
                        }

                        if (!drive.Encrypted)
                        {
                            drive.FileSystem += ld.GetPropertyValue("FileSystem");
                            drive.VolumeName  = string.IsNullOrWhiteSpace((string)ld.GetPropertyValue("VolumeName")) ? "" : ld.GetPropertyValue("VolumeName").ToString();
                        }

                        drive.Letter        = ld.GetPropertyValue("DeviceId").ToString();
                        drive.PartitionType = p.GetPropertyValue("Type").ToString().Contains("GPT:") ? "GPT" : "MBR";

                        drive.Name = d.GetPropertyValue("Caption").ToString();

                        drive.Path      = d.Path.RelativePath;
                        drive.FreeSpace = MathHelper.BytesToString(Convert.ToInt64(ld.GetPropertyValue("FreeSpace")));
                        drive.Model     = d.GetPropertyValue("Model").ToString();
                        drive.Size      = friendlySize;
                        drive.Fake      = false;
                        if (drive.FileSystem == "exFAT" && drive.PartitionType == "MBR" && drive.Name == "CYANLABS")
                        {
                            drive.SkipFormat = true;
                        }
                        else
                        {
                            drive.SkipFormat = false;
                        }
                    }
                }

                // Add to array of drives
                driveList.Add(drive);
            }

            if (fakeusb)
            {
                driveList.Add(new Drive {
                    Path = "", Name = LM.GetValue("Home.NoUSBDir"), Fake = true
                });
            }

            // Return a list of drives
            return(driveList);
        }
Exemple #6
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);
            }
        }
Exemple #7
0
        public MainWindowViewModel()
        {
            try
            {
                string regioninfo = AppMan.Client.GetStringAsync(new Uri("https://api.cyanlabs.net/app/syn3updater/githublatest")).Result;
                if (Version.Parse(regioninfo) > Version.Parse(Assembly.GetEntryAssembly()?.GetName().Version.ToString() !))
                {
                    AppMan.App.Outdated = regioninfo;
                }
            }
            catch (Exception)
            {
                // ignored
            }

            switch (AppMan.App.MainSettings.Theme)
            {
            case "Dark":
                ResourceDictionaryEx.GlobalTheme      = ElementTheme.Dark;
                ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
                ThemeIcon = PackIconVaadinIconsKind.SunOutline;
                break;

            case "Light":
                ResourceDictionaryEx.GlobalTheme      = ElementTheme.Light;
                ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
                ThemeIcon = PackIconVaadinIconsKind.SunOutline;
                break;

            default:
                ResourceDictionaryEx.GlobalTheme      = ElementTheme.Dark;
                ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
                ThemeIcon = PackIconVaadinIconsKind.SunOutline;
                break;
            }

            _args = Environment.GetCommandLineArgs();
            AppMan.App.LanguageChangedEvent += delegate
            {
                ObservableCollection <TabItem> ti = new()
                {
                    new TabItem(PackIconVaadinIconsKind.InfoCircle, "About", "about"),
                    new TabItem(PackIconVaadinIconsKind.Home, "Home", "home", true),
                    new TabItem(PackIconVaadinIconsKind.Tools, "Utility", "utility"),
                    new TabItem(PackIconVaadinIconsKind.Download, "Downloads", "downloads"),
                    //new TabItem(EFontAwesomeIcon.Solid_Bug, "Crash", "crashme"),
                    new TabItem(PackIconVaadinIconsKind.Car, "Profiles", "profiles"),
                    new TabItem(PackIconVaadinIconsKind.FileText, "Logs", "logs"),
                    new TabItem(PackIconVaadinIconsKind.Newspaper, "News", "news")
                };

                foreach (TabItem tabItem in ti.Where(x => x != null && !string.IsNullOrWhiteSpace(x.Key)))
                {
                    tabItem.Name = LM.GetValue($"Main.{tabItem.Key}", Language);
                }
                TabItems = ti;

                AppTitle =
                    $"Syn3 Updater {Assembly.GetEntryAssembly()?.GetName().Version} ({AppMan.App.LauncherPrefs.ReleaseTypeInstalled}) - {LM.GetValue("Profiles.CurrentProfile")}: {AppMan.App.MainSettings.Profile}";
            };

            AppMan.App.ShowDownloadsTab += delegate { CurrentTab = "downloads"; };
            AppMan.App.ShowSettingsTab  += delegate { CurrentTab = "settings"; };
            AppMan.App.ShowHomeTab      += delegate { CurrentTab = "home"; };
            AppMan.App.ShowUtilityTab   += delegate { CurrentTab = "utility"; };
            AppMan.App.ShowNewsTab      += delegate { CurrentTab = "news"; };
        }
Exemple #8
0
        /// <summary>
        ///     A multi-section check to ensure nothing prevents the download from beginning
        /// </summary>
        /// <param name="selectedDrive">USB Drive</param>
        /// <returns>true/false as Boolean depending on if Download is cancelled or not</returns>
        public static async Task <bool> CancelDownloadCheck(USBHelper.Drive selectedDrive)
        {
            // Set local variables to the values of application level variables
            string driveLetter  = AppMan.App.DriveLetter;
            string downloadPath = AppMan.App.DownloadPath;

            // Ensure drive letter is not used as download path
            if (!string.IsNullOrEmpty(driveLetter))
            {
                if (downloadPath.Contains(driveLetter))
                {
                    await Application.Current.Dispatcher.BeginInvoke(() => UIHelper.ShowErrorDialog(LM.GetValue("MessageBox.CancelDownloadIsDrive")));

                    return(true);
                }
            }

            // Optional Format
            if (string.IsNullOrWhiteSpace(selectedDrive?.Path) && driveLetter != null)
            {
                try
                {
                    if (Directory.EnumerateFileSystemEntries(driveLetter, "*", SearchOption.AllDirectories).Any())
                    {
                        if (await Application.Current.Dispatcher.Invoke(() => UIHelper.ShowDialog(string.Format(LM.GetValue("MessageBox.OptionalFormat"), driveLetter), LM.GetValue("String.Notice"), LM.GetValue("String.No"),
                                                                                                  LM.GetValue("String.Yes"))) == ContentDialogResult.Primary)
                        {
                            AppMan.App.SkipFormat = false;
                        }
                        else
                        {
                            AppMan.Logger.Info("Selected folder will not be cleared before being used");
                            AppMan.App.SkipFormat = true;
                        }
                    }
                    else
                    {
                        AppMan.App.SkipFormat = true;
                    }
                }
                catch (DirectoryNotFoundException e)
                {
                    await Application.Current.Dispatcher.BeginInvoke(() => UIHelper.ShowErrorDialog(e.GetFullMessage()));

                    return(true);
                }
                catch (IOException e)
                {
                    await Application.Current.Dispatcher.BeginInvoke(() => UIHelper.ShowErrorDialog(e.GetFullMessage()));

                    return(true);
                }
            }
            else
            {
                if (selectedDrive?.FileSystem == "exFAT" && selectedDrive?.PartitionType == "MBR" && selectedDrive?.VolumeName == "CYANLABS")
                {
                    if (await Application.Current.Dispatcher.Invoke(() => UIHelper.ShowDialog(string.Format(LM.GetValue("MessageBox.OptionalFormatUSB"), selectedDrive.Name, driveLetter), LM.GetValue("String.Notice"),
                                                                                              LM.GetValue("String.No"), LM.GetValue("String.Yes"))) == ContentDialogResult.Primary)
                    {
                        AppMan.App.SkipFormat = false;
                    }
                    else
                    {
                        AppMan.Logger.Info("USB Drive not formatted, using existing filesystem and files");
                        AppMan.App.SkipFormat = true;
                    }
                }
            }

            // Format USB Drive
            if (selectedDrive != null && !string.IsNullOrWhiteSpace(selectedDrive.Path) && !AppMan.App.SkipFormat)
            {
                if (await Application.Current.Dispatcher.Invoke(() => UIHelper.ShowWarningDialog(string.Format(LM.GetValue("MessageBox.CancelFormatUSB"), selectedDrive.Name, driveLetter), LM.GetValue("String.Warning") + "!",
                                                                                                 LM.GetValue("String.No"), LM.GetValue("String.Yes"))) != ContentDialogResult.Primary)
                {
                    return(true);
                }
            }

            if (selectedDrive != null && selectedDrive?.Name == LM.GetValue("Home.NoUSBDir"))
            {
                AppMan.Logger.Info("Using 'Select a Directory' instead of a USB Drive");
                AppMan.App.DownloadToFolder = true;
                if (string.IsNullOrEmpty(driveLetter))
                {
                    return(true);
                }

                if (Directory.EnumerateFiles(driveLetter).Any() && !AppMan.App.SkipFormat)
                {
                    if (await Application.Current.Dispatcher.Invoke(() => UIHelper.ShowWarningDialog(string.Format(LM.GetValue("MessageBox.CancelDeleteFiles"), driveLetter), LM.GetValue("String.Warning") + "!",
                                                                                                     LM.GetValue("String.No"), LM.GetValue("String.Yes"))) != ContentDialogResult.Primary)
                    {
                        return(true);
                    }
                }
            }
            else
            {
                AppMan.App.DownloadToFolder = false;
            }

            // If nothing above has returned true then download has not been cancelled and method will return false;
            return(false);
        }
Exemple #9
0
        public static async Task <bool> Download(string installMode, ObservableCollection <SModel.Ivsu> ivsuList,
                                                 SModel.SRegion selectedRegion, string selectedRelease, string selectedMapVersion, string driveLetter, USBHelper.Drive selectedDrive)
        {
            if (await SetIvsuList(installMode, ivsuList, selectedRegion, selectedRelease, selectedMapVersion, driveLetter) == false)
            {
                await Application.Current.Dispatcher.BeginInvoke(() => UIHelper.ShowErrorDialog(LM.GetValue("MessageBox.NoPackagesSelected")));

                return(false);
            }

            bool canceldownload = false;

            //Install Mode is reformat or downgrade My20 warning
            if ((installMode == "reformat" || installMode == "downgrade") && !AppMan.App.DownloadOnly && AppMan.App.Settings.My20v2 == null)
            {
                if (await Application.Current.Dispatcher.Invoke(() => UIHelper.ShowDialog(string.Format(LM.GetValue("MessageBox.My20Check")), LM.GetValue("String.Warning") + "!", LM.GetValue("String.No"),
                                                                                          LM.GetValue("String.Yes"), null, ContentDialogButton.None, Brushes.DarkRed)) == ContentDialogResult.Primary)
                {
                    await USBHelper.LogPrepareUSBAction(selectedDrive, driveLetter, "logutilitymy20");

                    return(true);
                }
            }

            //Warn is users region is different to new selection
            if (selectedRegion.Code != AppMan.App.Settings.CurrentRegion)
            {
                if (await Application.Current.Dispatcher.Invoke(() => UIHelper.ShowWarningDialog(string.Format(LM.GetValue("MessageBox.CancelRegionMismatch")), LM.GetValue("String.Warning") + "!", LM.GetValue("String.No"),
                                                                                                 LM.GetValue("String.Yes"))) != ContentDialogResult.Primary)
                {
                    canceldownload = true;
                }
            }

            //Cancel no apps package selected
            if (!AppMan.App.AppsSelected && (installMode == "reformat" || installMode == "downgrade"))
            {
                await Application.Current.Dispatcher.BeginInvoke(() => UIHelper.ShowErrorDialog(LM.GetValue("MessageBox.CancelNoApps")));

                canceldownload = true;
            }


            if (!canceldownload && (AppMan.App.DownloadOnly || !await SanityCheckHelper.CancelDownloadCheck(selectedDrive)))
            {
                if (AppMan.App.DownloadOnly)
                {
                    AppMan.Logger.Info($"Starting download only of ({selectedRelease} - {selectedRegion?.Code} - {selectedMapVersion})");
                }
                else
                {
                    AppMan.App.DriveNumber = selectedDrive.Path.Replace("Win32_DiskDrive.DeviceID=\"\\\\\\\\.\\\\PHYSICALDRIVE", "").Replace("\"", "");
                    AppMan.App.DriveLetter = driveLetter;
                    AppMan.Logger.Info($"Starting process ({selectedRelease} - {selectedRegion?.Code} - {selectedMapVersion})");
                }

                AppMan.App.IsDownloading = true;
                AppMan.App.FireDownloadsTabEvent();
                return(true);
            }

            return(false);
        }