/// <summary>
        /// Compares the current desktop file with another, to see if they have the same information or not.
        /// Does not compare executable or platform as executable obviously could be different between platforms.
        /// </summary>
        /// <returns></returns>
        public bool Compare(DesktopFile other)
        {
            if (name != other.Name)
            {
                return(false);
            }

            if (type != other.Type)
            {
                return(false);
            }

            if (icon != other.Icon)
            {
                return(false);
            }

            if (comment != other.Comment)
            {
                return(false);
            }

            if (terminal != other.Terminal)
            {
                return(false);
            }

            if (categories != other.Categories)
            {
                return(false);
            }

            if (mimeTypes != other.MimeTypes)
            {
                return(false);
            }

            if (manual != other.Manual)
            {
                return(false);
            }

            if (joystickMode != other.JoystickMode)
            {
                return(false);
            }

            if (gSensor != other.GSensor)
            {
                return(false);
            }

            if (hardwareScaling != other.HardwareScaling)
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        private void Pack()
        {
            if (!Directory.Exists(curPath))
            {
                MessageBox.Show("No valid folder selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (desktopFileOpt == DesktopFileOption.Ignore || desktopFileOpt == DesktopFileOption.LoadExisting)
            {
                DesktopFile desktopFileGCW0 = null;
                DesktopFile desktopFileA320 = null;

                if (textBoxExe.Text != "")
                {
                    desktopFileGCW0 = new DesktopFile();
                }

                if (textBoxExeA320.Text != "")
                {
                    desktopFileA320 = new DesktopFile();
                }

                if (desktopFileGCW0 == null && desktopFileA320 == null)
                {
                    MessageBox.Show("You must enter an executable for at least one platform.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (desktopFileGCW0 != null)
                {
                    desktopFileGCW0.Platform = "gcw0";

                    desktopFileGCW0.Name            = textBoxName.Text;
                    desktopFileGCW0.Exec            = textBoxExe.Text;
                    desktopFileGCW0.Icon            = textBoxIcon.Text;
                    desktopFileGCW0.Comment         = textBoxComment.Text;
                    desktopFileGCW0.Categories      = textBoxCategories.Text;
                    desktopFileGCW0.MimeTypes       = textBoxMimeTypes.Text;
                    desktopFileGCW0.Terminal        = checkBoxTerminal.Checked;
                    desktopFileGCW0.Manual          = textBoxManual.Text;
                    desktopFileGCW0.JoystickMode    = checkBoxJoystickMode.Checked;
                    desktopFileGCW0.GSensor         = checkBoxGSensor.Checked;
                    desktopFileGCW0.HardwareScaling = checkBoxHardwareScaling.Checked;
                }

                if (desktopFileA320 != null)
                {
                    desktopFileA320.Platform = "a320";

                    desktopFileA320.Name            = textBoxName.Text;
                    desktopFileA320.Exec            = textBoxExeA320.Text;
                    desktopFileA320.Icon            = textBoxIcon.Text;
                    desktopFileA320.Comment         = textBoxComment.Text;
                    desktopFileA320.Categories      = textBoxCategories.Text;
                    desktopFileA320.MimeTypes       = textBoxMimeTypes.Text;
                    desktopFileA320.Terminal        = checkBoxTerminal.Checked;
                    desktopFileA320.Manual          = textBoxManual.Text;
                    desktopFileA320.JoystickMode    = checkBoxJoystickMode.Checked;
                    desktopFileA320.GSensor         = checkBoxGSensor.Checked;
                    desktopFileA320.HardwareScaling = checkBoxHardwareScaling.Checked;
                }

                if (desktopFileGCW0 != null && !desktopFileGCW0.VerifyData())
                {
                    MessageBox.Show("Error: " + desktopFileGCW0.LastError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (desktopFileA320 != null && !desktopFileA320.VerifyData())
                {
                    MessageBox.Show("Error: " + desktopFileA320.LastError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (desktopFileGCW0 != null)
                {
                    string execPath  = Path.Combine(new string[] { curPath, desktopFileGCW0.Exec });
                    bool   exeExists = File.Exists(execPath);
                    if (!exeExists)
                    {
                        DialogResult exeResult = MessageBox.Show("Executable can not be found - Continue anyway?", "Executable not found", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (exeResult != System.Windows.Forms.DialogResult.Yes)
                        {
                            return;
                        }
                    }

                    desktopFileGCW0.WriteDesktopFile(curPath);

                    if (exeExists)
                    {
                        VerifyAndFixLineEndingsIfScript(execPath);
                    }
                }
                else
                {
                    string path = Path.Combine(curPath, DesktopFile.GetFilename("gcw0"));
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }

                if (desktopFileA320 != null)
                {
                    string execPath  = Path.Combine(new string[] { curPath, desktopFileA320.Exec });
                    bool   exeExists = File.Exists(execPath);
                    if (!exeExists)
                    {
                        DialogResult exeResult = MessageBox.Show("Executable can not be found - Continue anyway?", "Executable not found", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (exeResult != System.Windows.Forms.DialogResult.Yes)
                        {
                            return;
                        }
                    }

                    desktopFileA320.WriteDesktopFile(curPath);

                    if (exeExists)
                    {
                        VerifyAndFixLineEndingsIfScript(execPath);
                    }
                }
                else
                {
                    string path = Path.Combine(curPath, DesktopFile.GetFilename("a320"));
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
            }

            if (textBoxManual.Text != "")
            {
                try
                {
                    VerifyAndFixLineEndings(Path.Combine(curPath, textBoxManual.Text));
                }
                catch (Exception)
                { }
            }

            saveFileDialogOpk.InitialDirectory = Directory.GetParent(curPath).FullName;

            DialogResult result = saveFileDialogOpk.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            ExecutePacker(saveFileDialogOpk.FileName);
        }
 private string GetFilename()
 {
     return(DesktopFile.GetFilename(platform));
 }
Beispiel #4
0
        private void LoadDirectory(string path)
        {
            Reset();
            curPath             = path;
            textBoxCurPath.Text = path;

            List <string>        desktopFiles     = new List <string>();
            IEnumerable <string> tempDesktopFiles = Directory.EnumerateFiles(path, "*.desktop");

            foreach (string desktopFile in tempDesktopFiles)
            {
                desktopFiles.Add(desktopFile);
            }

            if (desktopFiles.Count > 0)
            {
                ExistingDesktopFilesWindow desktopAskWindow = new ExistingDesktopFilesWindow();
                DialogResult result = desktopAskWindow.ShowDialog();
                if (result == DialogResult.OK)
                {
                    desktopFileOpt = desktopAskWindow.DesktopFileOption;

                    if (desktopFileOpt == DesktopFileOption.LoadExisting)
                    {
                        string      execGcw          = "";
                        string      execA320         = "";
                        DesktopFile desktopFileToUse = null;

                        // Load desktop files
                        List <DesktopFile> loadedDesktopFiles = new List <DesktopFile>();
                        foreach (string desktopFilename in desktopFiles)
                        {
                            DesktopFile df = new DesktopFile();
                            Regex       platformPattern = new Regex("default\\.([ ._0-9A-Za-z-]+)\\.desktop");
                            string      platform        = platformPattern.Match(Path.GetFileName(desktopFilename)).Groups[1].Value;
                            if (!df.ReadDesktopFile(path, platform))
                            {
                                MessageBox.Show("Loading of existing desktop file failed: " + df.LastError, "Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                continue;
                            }

                            loadedDesktopFiles.Add(df);

                            if (platform == "gcw0")
                            {
                                execGcw = df.Exec;
                            }
                            else if (platform == "a320")
                            {
                                execA320 = df.Exec;
                            }

                            if (desktopFileToUse == null)
                            {
                                desktopFileToUse = df;
                            }
                        }

                        if (loadedDesktopFiles.Count > 1)
                        {
                            // Compare desktop files
                            // If they differ other than the executable, prompt to pick one to use
                            if (desktopFileToUse != null)
                            {
                                foreach (DesktopFile df in loadedDesktopFiles)
                                {
                                    if (!desktopFileToUse.Compare(df))
                                    {
                                        LoadDesktopSelectorDialog selectorDialog = new LoadDesktopSelectorDialog();
                                        selectorDialog.SetData(loadedDesktopFiles);
                                        DialogResult selectorResult = selectorDialog.ShowDialog();
                                        if (result == DialogResult.OK)
                                        {
                                            DesktopFile selected = selectorDialog.SelectedData;
                                            if (selected != null)
                                            {
                                                desktopFileToUse = selected;
                                            }
                                            else
                                            {
                                                desktopFileToUse = null;
                                            }
                                        }
                                        else
                                        {
                                            desktopFileToUse = null;
                                        }
                                        break;
                                    }
                                }
                            }
                        }

                        if (desktopFileToUse != null)
                        {
                            // Set fields with desktop file data
                            textBoxName.Text                = desktopFileToUse.Name;
                            textBoxComment.Text             = desktopFileToUse.Comment;
                            textBoxCategories.Text          = desktopFileToUse.Categories;
                            textBoxExe.Text                 = execGcw;
                            textBoxExeA320.Text             = execA320;
                            textBoxIcon.Text                = desktopFileToUse.Icon;
                            checkBoxLaunchWithFile.Checked  = desktopFileToUse.WithFile;
                            textBoxMimeTypes.Text           = desktopFileToUse.MimeTypes;
                            checkBoxTerminal.Checked        = desktopFileToUse.Terminal;
                            textBoxManual.Text              = desktopFileToUse.Manual;
                            checkBoxJoystickMode.Checked    = desktopFileToUse.JoystickMode;
                            checkBoxGSensor.Checked         = desktopFileToUse.GSensor;
                            checkBoxHardwareScaling.Checked = desktopFileToUse.HardwareScaling;
                        }

                        EnableFields(true);
                    }
                    else if (desktopFileOpt == DesktopFileOption.UseAsIs)
                    {
                        SetUsingExistingFilesInAllFields();
                    }
                    else if (desktopFileOpt == DesktopFileOption.Ignore)
                    {
                        EnableFields(true);
                    }
                }
                else
                {
                    return;
                }
            }

            if (desktopFileOpt == DesktopFileOption.Ignore)
            {
                // Guess values
                IEnumerable <string> files = Directory.EnumerateFiles(path, "*.dge");
                string probableExe         = "";
                foreach (string file in files)
                {
                    probableExe = Path.GetFileName(file);
                    break;
                }

                string probableIcon   = "";
                string firstIconMatch = "";
                files = Directory.EnumerateFiles(path, "*.png");
                foreach (string file in files)
                {
                    if (firstIconMatch.Length == 0)
                    {
                        firstIconMatch = Path.GetFileName(file);
                    }

                    if (Path.GetFileNameWithoutExtension(file) == Path.GetFileNameWithoutExtension(probableExe))
                    {
                        probableIcon = Path.GetFileName(file);
                        break;
                    }
                }

                if (probableIcon == "")
                {
                    probableIcon = firstIconMatch;
                }

                textBoxName.Text = Path.GetFileName(path);
                textBoxExe.Text  = probableExe;
                textBoxIcon.Text = probableIcon;

                EnableFields(true);
            }
        }