示例#1
0
        /// <summary>
        /// The base window for QLMM.
        /// <para>It contains all of the neccessary functions for the program to operate.</para>
        /// <para>IO operations, game executable startup, and more are all handled here.</para>
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            Variables.QLMMWindow = this;
            this.Show(); // triggered automatically in older builds. Why it didn't work this time is beyond me.
            SelectionDetails.AppendText("QLMM by bonkmaykr\nSelect a mod from the list to view its information, or add a mod to the list using the \"Import Mod\" button below.");
            listData = ModsList.Items;

            SteamStartButton.Click     += new RoutedEventHandler(StartSteam);
            GameStartButton.Click      += new RoutedEventHandler(StartGame);
            ProgramOptionsButton.Click += new RoutedEventHandler(OpenSettings);


            // JSON Config Loader
            if (File.Exists(Variables.ConfigurationPath + "\\data.json") == true)
            {
                string loadedjson = File.ReadAllText(Variables.ConfigurationPath + "\\data.json");
                Variables.ConfigurationData = JObject.Parse(loadedjson);

                if (Variables.ConfigurationData["qlmm"]["sortByEnabled"] != null)
                {
                    Variables.sortByEnabled = (bool)Variables.ConfigurationData["qlmm"]["sortByEnabled"];
                }
                else
                {
                    Variables.ConfigurationData["qlmm"]["sortByEnabled"] = false;
                    Variables.sortByEnabled = (bool)Variables.ConfigurationData["qlmm"]["sortByEnabled"];
                }

                SearchModsFolder((string)Variables.ConfigurationData["qlmm"]["ModsPath"]);
            }
            else
            {
                // Create a configuration file for first-time program launch.
                if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Steam\\steamapps\\common\\Quake Live\\quakelive_steam.exe") == true)
                {
                    JObject temp = JObject.FromObject(new
                    {
                        qlmm = new
                        {
                            GamePath      = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Steam\\steamapps\\common\\Quake Live\\quakelive_steam.exe",
                            ModsPath      = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Steam\\steamapps\\common\\Quake Live\\baseq3\\",
                            sortByEnabled = false,
                            pureBypass    = false
                        }
                    });
                    Variables.ConfigurationData = temp;
                    Directory.CreateDirectory(Variables.ConfigurationPath);
                    File.WriteAllText(Variables.ConfigurationPath + "\\data.json", temp.ToString());
                    SearchModsFolder((string)Variables.ConfigurationData["qlmm"]["ModsPath"]);
                }
                else
                {
                    Variables.WasShitFound = false;

                    // I forgot to do this in the earlier builds, and it
                    // caused a NullReferenceException in the JSON library.
                    //
                    // Placeholder settings must be set before the Settings
                    // Window is opened, otherwise, the data will return
                    // null when the settings window attempts to load it.
                    JObject temp = JObject.FromObject(new
                    {
                        qlmm = new
                        {
                            GamePath      = "",
                            ModsPath      = "",
                            sortByEnabled = false,
                            pureBypass    = false
                        }
                    });
                    Variables.ConfigurationData = temp;

                    OpenSettings();
                }
            }

            // for next update -- please??

            /*if (File.Exists(Variables.ConfigurationPath + "\\data_oldquake.json") == true)
             * {
             *  string loadedjson = File.ReadAllText(Variables.ConfigurationPath + "\\data_oldquake.json");
             *  Variables.OldQuakeConfigurationData = JObject.Parse(loadedjson);
             * //
             *  if (Variables.OldQuakeConfigurationData["qlmm"]["sortByEnabled"] != null)
             *  {
             *      Variables.sortByEnabled = (bool)Variables.OldQuakeConfigurationData["qlmm"]["sortByEnabled"];
             *  }
             *  else
             *  {
             *      Variables.OldQuakeConfigurationData["qlmm"]["sortByEnabled"] = false;
             *      Variables.sortByEnabled = (bool)Variables.OldQuakeConfigurationData["qlmm"]["sortByEnabled"];
             *  }
             *
             *  SearchModsFolder((string)Variables.OldQuakeConfigurationData["qlmm"]["ModsPath"]);
             * }
             * else
             * {
             *  // Create a configuration file for first-time program launch.
             *  if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Steam\\steamapps\\common\\Quake 3 Arena\\quake3.exe") == true)
             *  {
             *      JObject temp = JObject.FromObject(new
             *      {
             *          qlmm = new
             *          {
             *              GamePath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Steam\\steamapps\\common\\Quake 3 Arena\\quake3.exe",
             *              ModsPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Steam\\steamapps\\common\\Quake 3 Arena\\baseq3\\",
             *              sortByEnabled = false,
             *              pureBypass = false
             *          }
             *      });
             *      Variables.OldQuakeConfigurationData = temp;
             *      Directory.CreateDirectory(Variables.ConfigurationPath);
             *      File.WriteAllText(Variables.ConfigurationPath + "\\data_oldquake.json", temp.ToString());
             *      SearchModsFolder((string)Variables.ConfigurationData["qlmm"]["ModsPath"]);
             *  }
             * }
             *
             * if (File.Exists(Variables.ConfigurationPath + "\\data_warfork.json") == true)
             * {
             *  string loadedjson = File.ReadAllText(Variables.ConfigurationPath + "\\data_warfork.json");
             *  Variables.WarforkConfigurationData = JObject.Parse(loadedjson);
             *
             *  if (Variables.WarforkConfigurationData["qlmm"]["sortByEnabled"] != null)
             *  {
             *      Variables.sortByEnabled = (bool)Variables.WarforkConfigurationData["qlmm"]["sortByEnabled"];
             *  }
             *  else
             *  {
             *      Variables.WarforkConfigurationData["qlmm"]["sortByEnabled"] = false;
             *      Variables.sortByEnabled = (bool)Variables.WarforkConfigurationData["qlmm"]["sortByEnabled"];
             *  }
             *
             *  //SearchModsFolder((string)Variables.ConfigurationData["qlmm"]["ModsPath"]);
             * }
             * else
             * {
             *  // Create a configuration file for first-time program launch.
             *  if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Steam\\steamapps\\common\\fvi\\fvi-launcher\\applications\\warfork\\Warfork.app\\Contents\\Resources\\warfork_x64.exe") == true)
             *  {
             *      JObject temp = JObject.FromObject(new
             *      {
             *          qlmm = new
             *          {
             *              GamePath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Steam\\steamapps\\common\\fvi\\fvi-launcher\\applications\\warfork\\Warfork.app\\Contents\\Resources\\warfork_x64.exe",
             *              ModsPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Steam\\steamapps\\common\\fvi\\fvi-launcher\\applications\\warfork\\Warfork.app\\Contents\\Resources\\basewf\\",
             *              sortByEnabled = false,
             *              pureBypass = true
             *          }
             *      });
             *      Variables.WarforkConfigurationData = temp;
             *      Directory.CreateDirectory(Variables.ConfigurationPath);
             *      File.WriteAllText(Variables.ConfigurationPath + "\\data_warfork.json", temp.ToString());
             *      SearchModsFolder((string)Variables.ConfigurationData["qlmm"]["ModsPath"]);
             *  }
             * }*/

            //MainWindow1.Closed += new RoutedEventHandler(Shutdown);
        }
示例#2
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     SelectionDetails.Document = new FlowDocument();
     SelectionDetails.AppendText("The button works!");
 }
示例#3
0
        // List of blacklisted preinstalled pk3s:
        // - pak00.pk3
        // - bin.pk3
        // - curry.pk3
        // - common-spog.pk3
        // - common-q3map2.pk3
        public void SearchModsFolder(string path)
        {
            Variables.ModListingData = new List <ModDefinition>();  // Reset current modlist data.
            ModsList.Items.Clear();                                 //
            int numberFailed2Parse = 0;                             // if this number is EVER above 0 then someone did a oopsie!

            try {
                string[]      enabledfoldercontents  = Directory.GetFiles(path, "*.pk3", SearchOption.TopDirectoryOnly);
                string[]      disabledfoldercontents = Directory.GetFiles(path, "*.pk3.disabled", SearchOption.TopDirectoryOnly);
                List <string> foldercontents         = new List <string>();

                foreach (string sortThis in enabledfoldercontents)
                {
                    foldercontents.Add(sortThis);
                }
                foreach (string sortThis in disabledfoldercontents)
                {
                    foldercontents.Add(sortThis);
                }
                if (Variables.sortByEnabled == false)
                {
                    foldercontents.Sort();
                }

                foreach (string currentpak in foldercontents)
                {
                    ModDefinition currentMod = new ModDefinition(currentpak);

                    int    shit1 = currentpak.LastIndexOf("\\");    // file name
                    string name  = currentpak.Substring(shit1);     //
                    if (currentpak.EndsWith(".disabled"))           //
                    {
                        currentMod.IsDisabled = true;               //
                    }                                               //

                    if (name.StartsWith("\\"))
                    {
                        name = name.Substring(1);
                    }
                    if (name.EndsWith(".disabled"))
                    {
                        name = name.Remove(name.LastIndexOf(".disabled"));
                    }

                    FileStream fileStream = new FileStream(currentpak, FileMode.Open, FileAccess.ReadWrite);
                    ZipFile    zipFile    = new ZipFile(fileStream);

                    //int metaLocation = zipFile.FindEntry("_meta", false);
                    // condition used to be metaLocation == -1
                    if (zipFile.ZipFileComment == "" || zipFile.ZipFileComment == null)
                    {
                        currentMod.name        = name;
                        currentMod.author      = "<unknown>";
                        currentMod.version     = "<unknown>";
                        currentMod.description = "";
                    }
                    else
                    {
                        try
                        {
                            JObject jo = JObject.Parse(zipFile.ZipFileComment);
                            currentMod.name        = (string)jo["qlmm"]["name"];
                            currentMod.author      = (string)jo["qlmm"]["author"];
                            currentMod.version     = (string)jo["qlmm"]["version"];
                            currentMod.description = (string)jo["qlmm"]["description"];
                        }
                        catch (Newtonsoft.Json.JsonReaderException bruhMoment) {
                            numberFailed2Parse++;
                            currentMod.name        = name;
                            currentMod.author      = "<unknown>";
                            currentMod.version     = "<unknown>";
                            currentMod.description = "";
                        }
                    }

                    if (currentMod.author == "" || currentMod.author == null)
                    {
                        currentMod.author = "<unknown>";
                    }
                    if (currentMod.version == "" || currentMod.version == null)
                    {
                        currentMod.version = "<unknown>";
                    }

                    // Filter out pre-installed pak files
                    if (currentMod.name != "pak00.pk3" &&
                        currentMod.name != "curry.pk3" &&
                        currentMod.name != "bin.pk3" &&
                        currentMod.name != "common-spog.pk3" &&
                        currentMod.name != "common-q3map2.pk3")
                    {
                        Variables.ModListingData.Add(currentMod);
                    }

                    zipFile.Close();
                    fileStream.Close(); // this is important in order to prevent crashing
                }

                SelectionDetails.Document = new FlowDocument();
                SelectionDetails.AppendText("QLMM by bonkmaykr\nSelect a mod from the list to view its information, or add a mod to the list using the \"Import Mod\" button below.");

                int numberOfDisabled = 0;
                foreach (ModDefinition checkThis in Variables.ModListingData)
                {
                    if (checkThis.IsDisabled == true)
                    {
                        numberOfDisabled++;
                    }
                }

                SelectionDetails.AppendText("\n\n" + Variables.ModListingData.Count + " packages discovered\n" + numberOfDisabled + " of them are disabled");

                if (numberFailed2Parse > 0)
                {
                    SelectionDetails.AppendText("\nFailed to parse the metadata of " + numberFailed2Parse + " or more packages, are they corrupted?");
                }
            } catch (DirectoryNotFoundException YouFuckingDumbass) {
                SelectionDetails.Document = new FlowDocument();
                SelectionDetails.AppendText("We failed to find any mod files due to a fatal error, sorry! Please make sure you typed the correct paths in your settings. Here's the error:\n\n" + YouFuckingDumbass.Message);
            } catch (FileNotFoundException YouFuckingDumbass) {
                SelectionDetails.Document = new FlowDocument();
                SelectionDetails.AppendText("We failed to find any mod files due to a fatal error, sorry! Please make sure you typed the correct paths in your settings. Here's the error:\n\n" + YouFuckingDumbass.Message);
            } catch (ArgumentException YouFuckingDumbass)
            {
                SelectionDetails.Document = new FlowDocument();
                SelectionDetails.AppendText("We failed to find any mod files due to a fatal error, sorry! Please make sure you typed the correct paths in your settings. Here's the error:\n\n" + YouFuckingDumbass.Message);
            }

            foreach (ModDefinition currentMod in Variables.ModListingData)
            {
                string isEnabledIndicator = "";

                // maybe allow the user to disable this?
                if (currentMod.IsDisabled == true)
                {
                    isEnabledIndicator = " (Disabled)";
                }                                                                       // else {isEnabledIndicator = " (Enabled)";}

                ListBoxItem currentListItem = new ListBoxItem();
                currentListItem.Content = currentMod.name + isEnabledIndicator;
                ModsList.Items.Add(currentListItem);
            }
        }