Example #1
0
        internal static void Get45PlusFromRegistry()
        {
            try
            {
                const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";

                using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
                {
                    if (ndpKey != null && ndpKey.GetValue("Release") != null)
                    {
                        FormMain.LogWriter($"Installed .NET Framework {CheckFor45PlusVersion((int)ndpKey.GetValue("Release"))} version");
                        //Console.WriteLine($".NET Framework Version: {CheckFor45PlusVersion((int)ndpKey.GetValue("Release"))}");
                    }
                    else
                    {
                        FormMain.LogWriter(".NET Framework Version 4.5 or later is not detected.");
                        //Console.WriteLine(".NET Framework Version 4.5 or later is not detected.");
                    }
                }

                // Checking the version using >= enables forward compatibility.
                string CheckFor45PlusVersion(int releaseKey)
                {
                    if (releaseKey >= 528040)
                    {
                        return("4.8 or later");
                    }
                    if (releaseKey >= 461808)
                    {
                        return("4.7.2");
                    }
                    if (releaseKey >= 461308)
                    {
                        return("4.7.1");
                    }
                    if (releaseKey >= 460798)
                    {
                        return("4.7");
                    }
                    if (releaseKey >= 394802)
                    {
                        return("4.6.2");
                    }
                    if (releaseKey >= 394254)
                    {
                        return("4.6.1");
                    }
                    if (releaseKey >= 393295)
                    {
                        return("4.6");
                    }
                    if (releaseKey >= 379893)
                    {
                        return("4.5.2");
                    }
                    if (releaseKey >= 378675)
                    {
                        return("4.5.1");
                    }
                    if (releaseKey >= 378389)
                    {
                        return("4.5");
                    }
                    // This code should never execute. A non-null release key should mean
                    // that 4.5 or later is installed.
                    return("No 4.5 or later version detected");
                }
            }
            catch
            {
                FormMain.LogWriter(".NET Framework Version detection FAILED");
            }
        }
Example #2
0
        //Buttons
        private void buttonAccept_Click(object sender, EventArgs e)
        {
            switch (FormMode)
            {
            case "rename":
            {
                string NewProfileName = textBoxNewName.Text.Trim(new char[] { ' ' }), NewFolderName = "", NewFolderPath = "";
                byte   progress = 0;

                ReturnNewName = NewProfileName;

                //Get existing folders
                string[] existingDirs = Directory.GetDirectories(InitialPath.Remove(InitialPath.LastIndexOf('\\') + 1));

                List <string> existingDirList = new List <string>();

                foreach (string dir in existingDirs)
                {
                    //Get name
                    existingDirList.Add(Utilities.TextUtilities.FromHexToString(Path.GetFileName(dir)));
                }

                if (NewProfileName != InitialName || existingDirList.Contains(NewProfileName))
                {
                    try
                    {
                        //New folder name
                        NewFolderName = Utilities.TextUtilities.FromStringToHex(NewProfileName);
                        NewFolderPath = InitialPath.Remove(InitialPath.LastIndexOf('\\') + 1) + NewFolderName;

                        progress = 1;

                        //Create folder and copy
                        Directory.CreateDirectory(NewFolderPath);
                        progress = 2;
                        Utilities.IO_Utilities.DirectoryCopy(InitialPath, NewFolderPath, true);
                        progress = 3;

                        //Decode profile.sii
                        FormMain tF          = new FormMain();
                        string[] profileFile = tF.NewDecodeFile(NewFolderPath + "\\profile.sii");
                        progress = 4;

                        SaveFileProfileData ProfileData = new SaveFileProfileData();
                        ProfileData.Prepare(profileFile);
                        progress = 5;

                        //New name
                        ProfileData.ProfileName = NewProfileName;
                        progress = 6;

                        //Write file
                        using (StreamWriter SW = new StreamWriter(NewFolderPath + "\\profile.sii", false))
                        {
                            ProfileData.WriteToStream(SW);
                        }
                        progress = 7;

                        //Make backup
                        if (checkBoxCreateBackup.Checked)
                        {
                            ZipFile.CreateFromDirectory(InitialPath, InitialPath + ".zip");
                        }
                        progress = 8;

                        //Delete old folder
                        Directory.Delete(InitialPath, true);
                        progress = 9;

                        ReturnNewName           = NewProfileName;
                        ReturnRenamedSuccessful = true;
                    }
                    catch
                    {
                        switch (progress)
                        {
                        case 0:
                            MessageBox.Show("Create new folder name failed");
                            break;

                        case 1:
                            MessageBox.Show("Directory was not created");
                            break;

                        case 2:
                            MessageBox.Show("Directory copy failed");
                            goto delete;

                        case 3:
                            MessageBox.Show("Profile not decoded");
                            goto delete;

                        case 4:
                            MessageBox.Show("Profile hase wrong version/format");
                            goto delete;

                        case 5:
                            MessageBox.Show("Profile name is not applied");
                            goto delete;

                        case 6:
                            MessageBox.Show("Profile write failed");
                            goto delete;

                        case 7:
                            MessageBox.Show("Profile backup creation failed. Keeping both versions. Delete old profile manually.");
                            break;

                        case 8:
                            MessageBox.Show("Deleting old profile failed. Keeping both versions. Delete old profile manually.");
                            ZipFile.ExtractToDirectory(InitialPath + ".zip", InitialPath);
                            File.Delete(InitialPath + ".zip");
                            break;
delete:
                            Directory.Delete(NewFolderPath);
                            break;

                        default:
                            MessageBox.Show("Unexpected error. Deleting new Profile.");
                            Directory.Delete(NewFolderPath);
                            break;
                        }
                    }
                }

                break;
            }

            case "clone":
            {
                //Get existing folders
                string[] existingDirs = Directory.GetDirectories(InitialPath.Remove(InitialPath.LastIndexOf('\\') + 1));

                List <string> existingDirList = new List <string>();

                foreach (string dir in existingDirs)
                {
                    //Get name
                    existingDirList.Add(Utilities.TextUtilities.FromHexToString(Path.GetFileName(dir)));
                }

                foreach (string newfile in textBoxNewName.Lines)
                {
                    string NewProfileName = "", NewFolderPath = "";
                    byte   progress = 0;

                    try
                    {
                        //Check empty lines
                        if (newfile.Length == 0 || newfile.Trim(new char[] { ' ' }).Length == 0)
                        {
                            continue;
                        }

                        NewProfileName = newfile.Trim(new char[] { ' ' });
                        //Check existing folders
                        if (NewProfileName == InitialName || existingDirList.Contains(NewProfileName))
                        {
                            continue;
                        }

                        //New folder
                        string NewProfileNameHex = Utilities.TextUtilities.FromStringToHex(NewProfileName);
                        NewFolderPath = InitialPath.Remove(InitialPath.LastIndexOf('\\') + 1) + NewProfileNameHex;

                        progress = 1;

                        //Validate If exist skip
                        if (Directory.Exists(NewFolderPath))
                        {
                            continue;
                        }

                        Directory.CreateDirectory(NewFolderPath);

                        progress = 2;

                        //Copy profile files .cfg .sii .png
                        //Get the files in the initial directory and copy them to the new location.
                        var files = Directory.EnumerateFiles(InitialPath, "*.*", SearchOption.TopDirectoryOnly).Where(s => s.EndsWith(".cfg") || s.EndsWith(".sii") || s.EndsWith(".png")).ToArray();

                        //Iterate files
                        foreach (string file in files)
                        {
                            string temppath = Path.Combine(NewFolderPath, Path.GetFileName(file)); //new file path with name

                            FileInfo tFI = new FileInfo(file);                                     //fileinfo
                            tFI.CopyTo(temppath, false);                                           //Copy
                        }

                        progress = 3;

                        //Create save folder
                        string NewSaveFolder = NewFolderPath + "\\save";
                        Directory.CreateDirectory(NewSaveFolder);

                        progress = 4;

                        //Copy saves
                        if (checkBoxFullCloning.Checked)
                        {
                            Utilities.IO_Utilities.DirectoryCopy(InitialPath + "\\save", NewSaveFolder, true);
                        }
                        else
                        {
                            Utilities.IO_Utilities.DirectoryCopy(InitialPath + "\\save\\autosave", NewSaveFolder + "\\autosave", false);
                        }

                        progress = 5;

                        //Decode profile.sii
                        string[] profileFile = ParentForm.NewDecodeFile(NewFolderPath + "\\profile.sii");
                        progress = 6;

                        SaveFileProfileData ProfileData = new SaveFileProfileData();
                        ProfileData.Prepare(profileFile);
                        progress = 7;

                        //New name
                        ProfileData.ProfileName  = NewProfileName;
                        ProfileData.CreationTime = Utilities.DateTimeUtilities.DateTimeToUnixTimeStamp();
                        progress = 8;

                        //Write file
                        using (StreamWriter SW = new StreamWriter(NewFolderPath + "\\profile.sii", false))
                        {
                            ProfileData.WriteToStream(SW);
                        }
                        progress = 9;

                        //Cloned folders
                        existingDirList.Add(NewProfileName);
                        ReturnClonedNames.Add(NewProfileName);
                    }
                    catch {
                        switch (progress)
                        {
                        case 0:
                            MessageBox.Show("Create new folder name failed");
                            break;

                        case 1:
                            MessageBox.Show("Directory was not created");
                            break;

                        case 2:
                            MessageBox.Show("Directory copy failed");
                            goto delete;

                        case 3:
                            MessageBox.Show("Directory for saves was not created");
                            goto delete;

                        case 4:
                            MessageBox.Show("Directory with saves copy failed");
                            goto delete;

                        case 5:
                            MessageBox.Show("Profile not decoded");
                            goto delete;

                        case 6:
                            MessageBox.Show("Profile hase wrong version/format");
                            goto delete;

                        case 7:
                            MessageBox.Show("Profile properties was not applied");
                            goto delete;

                        case 8:
                            MessageBox.Show("Profile write failed");
                            goto delete;
delete:
                            Directory.Delete(NewFolderPath);
                            break;

                        default:
                            MessageBox.Show("Unexpected error. Deleting new Profile.");
                            Directory.Delete(NewFolderPath);
                            break;
                        }
                    }
                }

                if (ReturnClonedNames.Count > 0)
                {
                    ReturnCloningSuccessful = true;
                }

                break;
            }
            }

            DialogResult = DialogResult.OK;
            Close();
        }