Example #1
0
        // Handles the saving and checking of the values entered in the form.
        private void button2_Click(object sender, EventArgs e)
        {
            string type;

            if ((string.IsNullOrEmpty(before.Text) && method.SelectedItem.ToString() != "At the end of file") || string.IsNullOrEmpty(after.Text) || string.IsNullOrEmpty(fileEdited.Text) || string.IsNullOrEmpty(method.SelectedItem.ToString()))
            {
                MessageBox.Show("Please check that you entered something in all the fields; they are all required.", "Check your content", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // Try to get the method type.
            switch (method.SelectedItem.ToString())
            {
            case "Add before":
                type = "add_before";
                break;

            case "Add after":
                type = "add_after";
                break;

            case "At the end of file":
                type = "end";
                break;

            default:
                type = "replace";
                break;
            }

            int optional = Convert.ToInt32(optionalCheck.Checked);

            // Start the sql string.
            string sql;

            // If we are not editing an instruction, we are going to insert a new one.
            if (editing == 0)
            {
                sql = "INSERT INTO instructions(id, before, after, type, file, optional) VALUES(null, @beforeText, @afterText, @type, @fileEdited, @optional)";
            }

            // If we *are* editing an instruction, update the existing entry instead.
            else
            {
                sql = "UPDATE instructions SET before = @beforeText, after = @afterText, type = @type, file = @fileEdited, optional = @optional WHERE id = @editing";
            }

            // Create the query.
            SQLiteCommand command = new SQLiteCommand(sql, co);

            command.Parameters.AddWithValue("@beforeText", before.Text);
            command.Parameters.AddWithValue("@afterText", after.Text);
            command.Parameters.AddWithValue("@type", type);
            command.Parameters.AddWithValue("@fileEdited", filePrefix.SelectedItem + "/" + fileEdited.Text);
            command.Parameters.AddWithValue("@optional", optional);
            command.Parameters.AddWithValue("@editing", editing);

            // And execute it.
            command.ExecuteNonQuery();

            me.refreshInstructionTree();

            Close();
        }
Example #2
0
        public bool openProjDir(string dir)
        {
            try
            {
                // Check if the directory exists. Also should contain a package_info.xml.
                if (!Directory.Exists(dir))
                {
                    return(false);
                }

                // Start an instance of the mod editor.
                modEditor me = new modEditor();

                if (!File.Exists(dir + "/data.sqlite"))
                {
                    MessageBox.Show("A required database file was not found in your project. It will now be generated.", "Loading Project", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    me.generateSQL(dir);
                }

                me.workingDirectory = dir;
                me.conn             = new SQLiteConnection("Data Source=\"" + dir + "/data.sqlite\";Version=3;");
                me.conn.Open();
                me.hasConn = true;

                me.refreshInstructionTree();
                me.refreshExtractionTree();
                me.reloadSettings();

                // Checks.
                if (!me.settings.ContainsKey("modName") || !me.settings.ContainsKey("mbVersion") || !me.settings.ContainsKey("ignoreInstructions") || !me.settings.ContainsKey("autoGenerateModID") || !me.settings.ContainsKey("includeModManLine"))
                {
                    MessageBox.Show("Your project does not include all the required settings. Please try to repair your project and try again.", "Loading Project", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    me.conn.Close();
                    me.Close();
                    return(false);
                }

                // Compare the versions
                Version lmver  = new Version(Properties.Settings.Default.minMbVersion);
                Version mver   = new Version(me.settings["mbVersion"]);
                int     status = mver.CompareTo(lmver);

                // If the status is equal to or bigger than 0 we are running the latest version.
                if (status < 0)
                {
                    MessageBox.Show("Your project is generated with an older version of Mod Builder, which used a different format. Please repair your project and try again.", "Loading Project", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    me.conn.Close();
                    me.Close();
                    return(false);
                }

                me.modID.Text            = me.settings["modID"];
                me.modName.Text          = me.settings["modName"];
                me.modType.SelectedItem  = me.settings["modType"];
                me.modVersion.Text       = me.settings["modVersion"];
                me.authorName.Text       = me.settings["modUser"];
                me.modCompatibility.Text = me.settings["modCompat"];
                me.Text = me.settings["modName"] + " - Mod Builder";

                if (me.settings["ignoreInstructions"] == "true")
                {
                    me.ignoreInstructions.Checked = true;
                }

                if (me.settings["autoGenerateModID"] == "true")
                {
                    me.genPkgID.Checked = true;
                }

                if (me.settings["includeModManLine"] == "true")
                {
                    me.includeModManLine.Checked = true;
                }

                // Also load the readme.txt.
                if (File.Exists(dir + "/Package/readme.txt"))
                {
                    me.modReadme.Text = File.ReadAllText(dir + "/Package/readme.txt");
                }

                if (File.Exists(dir + "/Package/install.php"))
                {
                    me.customCodeInstall.Text = File.ReadAllText(dir + "/Package/install.php");
                }

                if (File.Exists(dir + "/Package/uninstall.php"))
                {
                    me.customCodeUninstall.Text = File.ReadAllText(dir + "/Package/uninstall.php");
                }

                if (File.Exists(dir + "/Package/installDatabase.php"))
                {
                    me.installDatabaseCode.Text = File.ReadAllText(dir + "/Package/installDatabase.php");
                }

                if (File.Exists(dir + "/Package/uninstallDatabase.php"))
                {
                    me.uninstallDatabaseCode.Text = File.ReadAllText(dir + "/Package/uninstallDatabase.php");
                }

                me.Show();

                // Log this to the recent projects file.

                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                return(false);
            }
        }