Exemplo n.º 1
0
        private void lbInst_DoubleClick(object sender, EventArgs e)
        {
            if (lbInst.SelectedItem != null)
            {
                CMod selMod = (CMod)lbInst.SelectedItem;

                if (!selMod.isBaseMod() && !selMod.isAddon())
                {
                    selMod.toggleActive();

                    int idx = lbInst.SelectedIndex;
                    lbInst.Items.Remove(selMod);
                    lbInst.Items.Insert(idx, selMod);
                    lbInst.SelectedIndex = idx;
                }
                else
                {
                    if (selMod.isAddon())
                    {
                        MessageBox.Show("You cannot disable addons like character packs or room presets.", "Ooopsie...");
                    }
                    else
                    {
                        MessageBox.Show("Disabling the base game files is not the best idea you had today...\nI'll keep them enabled for you.", "Eh what?");
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void lbInst_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbInst.SelectedItem != null)
            {
                CMod mod = (CMod)lbInst.SelectedItem;

                if (!mod.isBaseMod())
                {
                    btnDelMod.Enabled = true;
                }
                else
                {
                    btnDelMod.Enabled = false;
                }

                // Select the same module in the repo if available
                int oldSel = lbAvail.SelectedIndex;
                for (int idx = 0; idx < lbAvail.Items.Count; idx++)
                {
                    CMod itm = (CMod)lbAvail.Items[idx];
                    if (itm.getId() == mod.getId())
                    {
                        lbAvail.SelectedIndex = idx;
                        break;
                    }
                }
            }
            else
            {
                btnDelMod.Enabled = false;
            }
        }
Exemplo n.º 3
0
        private bool ReadModControlFile()
        {
            string sPath = m_sPath + @"LifePlay\Content\Modules\ModLauncher.config";

            if (!File.Exists(sPath))
            {
                return(false);
            }
            try
            {
                using (StreamReader sr = File.OpenText(sPath))
                {
                    int           idx      = 0;
                    List <String> itemList = new List <string>();

                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();

                        if (!line.StartsWith("UseConfigIgnoreAppData") && line.IndexOf(':') > 1)
                        {
                            // Test if the item already exists
                            if (!itemList.Contains(line))
                            {
                                itemList.Add(line);
                            }
                            else if (!line.StartsWith("vin_Base"))
                            {
                                Debug.Print("Duplicate mod item in control file: " + line);
                            }
                        }
                    }

                    // Test if we need to reverse the mod control file
                    if (!itemList[0].StartsWith("vin_Base"))
                    {
                        itemList.Reverse(); // The mod control file is in reversed order
                    }
                    foreach (string line in itemList)
                    {
                        string[] kvp = line.Split(':');

                        string sId     = kvp[0];
                        bool   enabled = (kvp[1].ToLower() == "true");
                        CMod   mod     = findInstalledModWithId(sId);
                        if (mod != null)
                        {
                            mod.setEnabled(enabled);
                            mod.setIndex(idx++);
                        }
                    }
                }
            }
            catch (Exception ex)
            { }

            return(true);
        }
Exemplo n.º 4
0
        private void btnUpdateAll_Click(object sender, EventArgs e)
        {
            // Compare avail with installed
            List <CMod> modsToUpdate  = new List <CMod>();
            string      sModsToUpdate = "";

            foreach (CMod modAvail in m_ModsAvailable.Values)
            {
                CMod found = findInstalledModWithId(modAvail.getId());
                if (found != null)
                {
                    if (found.getVersion() != modAvail.getVersion())
                    {
                        // Looks like changed
                        modsToUpdate.Add(modAvail);
                        sModsToUpdate += modAvail.ToString() + "\n";
                    }
                }
            }

            if (modsToUpdate.Count > 0)
            {
                DialogResult dr = MessageBox.Show("The following updates are available:\n\n" + sModsToUpdate + "\nInstall them now?", "Updates found", MessageBoxButtons.YesNo);
                if (dr == System.Windows.Forms.DialogResult.Yes)
                {
                    foreach (CMod modToUpdate in modsToUpdate)
                    {
                        bool currentState     = true;
                        CMod installedVersion = findInstalledModWithId(modToUpdate.getId());
                        currentState = installedVersion.isEnabled();

                        InstallMod(modToUpdate);

                        // After installation all mods are enabled.
                        // Set the previous state
                        if (!currentState)
                        {
                            // Disable again
                            installedVersion = findInstalledModWithId(modToUpdate.getId());
                            installedVersion.toggleActive();
                        }
                    }

                    RefreshLocalMods();
                    RefreshRepoMods();
                }
            }
            else
            {
                MessageBox.Show("All your modules are up to date.", "No updates found");
            }
        }
Exemplo n.º 5
0
        private void lbInst_DragDrop(object sender, DragEventArgs e)
        {
            Point point = lbInst.PointToClient(new Point(e.X, e.Y));
            int   index = lbInst.IndexFromPoint(point);

            if (index < 0)
            {
                index = lbInst.Items.Count - 1;
            }

            CMod data = (CMod)e.Data.GetData(typeof(CMod));

            lbInst.Items.Remove(data);
            lbInst.Items.Insert(index, data);
        }
Exemplo n.º 6
0
        private void lbAvail_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbAvail.SelectedItem != null)
            {
                CMod selMod = (CMod)lbAvail.SelectedItem;

                if (selMod.getDescription() == null)
                {
                    if (selMod.getDependencies() != null)
                    {
                        lblModInfo.Text = "Requires: " + selMod.getDependencies();
                    }
                    else
                    {
                        lblModInfo.Text = "Double click a module to install / update it.";
                    }
                }
                else
                {
                    lblModInfo.Text = selMod.getDescription();
                    if (selMod.getDependencies() != null)
                    {
                        lblModInfo.Text += " [Requires: " + selMod.getDependencies() + "]";
                    }
                }

                // Select the same module in the local repo if installed
                int oldSel = lbInst.SelectedIndex;
                for (int idx = 0; idx < lbInst.Items.Count; idx++)
                {
                    CMod itm = (CMod)lbInst.Items[idx];
                    if (itm.getId() == selMod.getId())
                    {
                        lbInst.SelectedIndex = idx;
                        break;
                    }
                }
            }
            else
            {
                lblModInfo.Text = "Double click a module to install / update it.";
            }
        }
Exemplo n.º 7
0
        private void lbAvail_DoubleClick(object sender, EventArgs e)
        {
            if (lbAvail.SelectedItem != null)
            {
                CMod mod = (CMod)lbAvail.SelectedItem;

                CMod newMod = InstallMod(mod, true);

                if (newMod != null)
                {
                    // Test if the mod was already installed (only updated)
                    CMod instMod = findInstalledModWithId(newMod.getId());
                    if (instMod == null)
                    {
                        RefreshLocalMods();
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void btnDelMod_Click(object sender, EventArgs e)
        {
            if (lbInst.SelectedItem != null)
            {
                DialogResult dr = MessageBox.Show("Are you sure you want to delete the mod?", "Delete mod", MessageBoxButtons.YesNo);
                if (dr == System.Windows.Forms.DialogResult.Yes)
                {
                    CMod mod = (CMod)lbInst.SelectedItem;
                    if (!mod.isBaseMod())
                    {
                        bool success = mod.delete();

                        if (success)
                        {
                            lbInst.Items.Remove(mod);
                            m_ModsInstalled.Remove(mod.getId());
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        private void RenderRepoModList()
        {
            lbAvail.Items.Clear();

            // We keep two lists for sorting them in the UI
            List <CMod> updatedMods = new List <CMod>();
            List <CMod> normalMods  = new List <CMod>();

            foreach (CMod mod in m_ModsAvailable.Values)
            {
                // Check if this module is installed locally
                CMod instMod = findInstalledModWithId(mod.getId());
                if (instMod != null)
                {
                    if (instMod.getVersion() != mod.getVersion())
                    {
                        // Looks updated
                        mod.setUpdated(true);
                        updatedMods.Add(mod);
                    }
                    else
                    {
                        normalMods.Add(mod);
                    }
                }
                else
                {
                    normalMods.Add(mod);
                }
            }

            normalMods.Sort((x, y) => x.ToString().CompareTo(y.ToString()));
            updatedMods.Sort((x, y) => x.ToString().CompareTo(y.ToString()));

            lbAvail.Items.AddRange(updatedMods.ToArray());
            lbAvail.Items.AddRange(normalMods.ToArray());
        }
Exemplo n.º 10
0
        private CMod InstallMod(CMod mod, bool askToReplace = false)
        {
            if (mod.getDependencies() != null && mod.getDependencies().Length > 0)
            {
                // Test if the dependency is met
                CMod dep = findInstalledModWithId(mod.getDependencies());
                if (dep == null)
                {
                    DialogResult dr = System.Windows.Forms.DialogResult.Cancel;
                    dep = findRepoModWithId(mod.getDependencies());

                    if (dep != null)
                    {
                        dr = MessageBox.Show("The mod '" + mod.getName() + "' requires the mod '" + mod.getDependencies() + "' to be installed.\n\nCurrently I cannot find that module in your game but I have it in my repository.\n\nShall I install it?", mod.getDisplayName() + ": missing dependency!", MessageBoxButtons.YesNoCancel);
                        if (dr == System.Windows.Forms.DialogResult.Yes)
                        {
                            InstallMod(dep, true);
                        }
                        else if (dr == System.Windows.Forms.DialogResult.Cancel)
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        dr = MessageBox.Show("The mod '" + mod.getName() + "' requires the mod '" + mod.getDependencies() + "' to be installed.\n\nCurrently I cannot find that module in your game and I don't find it in my repository.\n\nContinue anyways?", mod.getDisplayName() + ": missing dependency!", MessageBoxButtons.YesNo);
                        if (dr == System.Windows.Forms.DialogResult.No)
                        {
                            return(null);
                        }
                    }
                }
            }

            using (WebClient wc = new WebClient())
            {
                try
                {
                    wc.DownloadFile(mod.getFileName(), "lpmgr.tmp");

                    if (Directory.Exists("mmTemp"))
                    {
                        Directory.Delete("mmTemp", true);
                    }

                    Directory.CreateDirectory("mmTemp");

                    System.IO.Compression.ZipFile.ExtractToDirectory("lpmgr.tmp", "mmTemp");

                    string[] subFolders = Directory.GetDirectories("mmTemp");
                    if (subFolders.Length == 1)    // Single mod
                    {
                        string name = Path.GetFileName(subFolders[0]);

                        // Test if already installed
                        bool   install = true;
                        string dest    = m_sPath + MOD_SUBFOLDER + name;
                        if (!mod.isPatch() && Directory.Exists(dest))       // patches always override
                        {
                            DialogResult dr = System.Windows.Forms.DialogResult.Yes;
                            if (askToReplace)
                            {
                                dr = MessageBox.Show("Replace existing mod?", mod.getDisplayName() + ": already installed!", MessageBoxButtons.YesNo);
                            }

                            if (dr == System.Windows.Forms.DialogResult.Yes)
                            {
                                Directory.Delete(dest, true);
                            }
                            else
                            {
                                install = false;
                            }
                        }

                        if (install)
                        {
                            if (mod.getDevMessage() != null)
                            {
                                MessageBox.Show(mod.getDevMessage(), "Message from mod " + mod.getName());
                            }

                            if (mod.isPatch())
                            {
                                DirectoryCopy(subFolders[0], dest, true);
                            }
                            else
                            {
                                Directory.Move(subFolders[0], dest);
                            }

                            // Test if the mod file exists
                            DirectoryInfo folder      = new DirectoryInfo(dest);
                            FileInfo      modFileInfo = null;
                            if (folder.GetFiles("*.lpmod").Length > 0)
                            {
                                modFileInfo = folder.GetFiles("*.lpmod")[0];
                            }
                            else if (folder.GetFiles("*.lpaddon").Length > 0)
                            {
                                modFileInfo = folder.GetFiles("*.lpaddon")[0];
                            }

                            if (modFileInfo != null)
                            {
                                CMod newMod = new CMod(mod.getName(), dest);
                                newMod.setFileName(modFileInfo.FullName);
                                newMod.readModInfo();
                                newMod.setIndex(lbInst.Items.Count);

                                if (Directory.Exists("mmTemp"))
                                {
                                    Directory.Delete("mmTemp", true);
                                }
                                File.Delete("lpmgr.tmp");

                                return(newMod);
                            }
                        }
                    }
                    else if (subFolders.Length > 1)
                    {
                        if (mod.getDevMessage() != null)
                        {
                            MessageBox.Show(mod.getDevMessage(), "Message from mod " + mod.getName());
                        }

                        DialogResult dr = System.Windows.Forms.DialogResult.Yes;
                        dr = MessageBox.Show("The package contains multiple folders.\n\nIt may replace / modify several existing mods (which is OK for patches or bundles).\n\nProceed with installation?\n\n(If unsure check the mod description again...)", mod.getDisplayName() + ": Install?", MessageBoxButtons.YesNo);

                        if (dr == System.Windows.Forms.DialogResult.Yes)
                        {
                            CMod retMod = null;
                            foreach (string sf in subFolders)
                            {
                                string name = Path.GetFileName(sf);
                                string dest = m_sPath + MOD_SUBFOLDER + name;

                                DirectoryCopy(sf, dest, true);
                            }
                        }
                    }

                    if (Directory.Exists("mmTemp"))
                    {
                        Directory.Delete("mmTemp", true);
                    }

                    File.Delete("lpmgr.tmp");

                    RefreshLocalMods();
                    RefreshRepoMods();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Problem during installation of mod " + mod.ToString() + ":\n" + ex.Message, "Ooops...");
                }

                return(null);
            }
        }
Exemplo n.º 11
0
        private void UpdateRepo()
        {
            bool canContinue = true;

            m_ModsAvailable.Clear();

            try
            {
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;

                using (WebClient c = new WebClient())
                {
                    string sUrl = BASE_REPO_URL + "repo.xml";
                    c.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache);
                    c.Headers.Add("Cache-Control", "no-cache");
                    c.DownloadFile(sUrl, "lprepo.xml");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Cannot download mod repository.\nCheck your connection and/or if a newer version of the mod manager is avalilable.\n\nError message is:\n" + ex.Message, "Ooops!");
                canContinue = false;
            }

            XmlDocument repo = new XmlDocument();

            if (canContinue)
            {
                try
                {
                    repo.Load("lprepo.xml");
                    XmlNode root = repo.DocumentElement.SelectSingleNode("/Repo");
                    foreach (XmlNode modXml in root.ChildNodes)
                    {
                        if (modXml.LocalName == "#comment")
                        {
                            string val       = modXml.Value;
                            string searchVer = "#Current LifePlay Version:";
                            if (val.Contains(searchVer))
                            {
                                val = val.Trim();
                                m_sLifePlayVersionAvailable = val.Substring(searchVer.Length + 1);
                            }

                            searchVer = "#Current Launcher Version:";
                            if (val.Contains(searchVer))
                            {
                                val = val.Trim();
                                m_sLauncherVersionAvailable = val.Substring(searchVer.Length + 1);
                            }
                            continue;
                        }

                        string name    = modXml.Attributes["Name"].InnerText;
                        string ver     = modXml.Attributes["Version"].InnerText;
                        string id      = modXml.Attributes["Id"].InnerText;
                        string path    = modXml.Attributes["Path"].InnerText;
                        bool   isPatch = modXml.Attributes["isPatch"] != null ? modXml.Attributes["isPatch"].InnerText == "1" : false;

                        if (!(path.StartsWith("http://") || path.StartsWith("https://")))
                        {
                            path = BASE_REPO_URL + path;
                        }

                        CMod curMod = new CMod(id, name, ver, path);

                        // Test for optional message
                        string devMsg = null;
                        if (modXml.Attributes.GetNamedItem("Msg") != null)
                        {
                            devMsg = modXml.Attributes["Msg"].InnerText;
                        }
                        curMod.setDevMessage(devMsg);

                        // Optional description
                        string descr = null;
                        if (modXml.Attributes.GetNamedItem("Description") != null)
                        {
                            descr = modXml.Attributes["Description"].InnerText;
                        }
                        curMod.setDescription(descr);

                        // Optional dependencies
                        string deps = null;
                        if (modXml.Attributes.GetNamedItem("Depends") != null)
                        {
                            deps = modXml.Attributes["Depends"].InnerText;
                        }
                        curMod.setDependencies(deps);

                        // Patch flag
                        curMod.setIsPatch(isPatch);

                        try
                        {
                            m_ModsAvailable.Add(id, curMod);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Whoops... Something is wrong with my repository!\nError code: " + ex.Message);
                        }
                    }

                    lblAvailModules.Text = m_ModsAvailable.Count.ToString() + " modules available (checked: " + DateTime.Now.ToString() + ")";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "The repo could not be downloaded.\nError code:\n" + ex.Message + "\nPlease check if a newer version of the mod manager is avalilable.", "Ooops!");
                    canContinue = false;

                    lblAvailModules.Text = "Unable to fetch the repository. :-(";
                }
            }

            if (File.Exists("lprepo.xml"))
            {
                File.Delete("lprepo.xml");
            }

            try
            {
                string [] aInst  = m_sLifePlayVersionInstalled.Split('.');
                string[]  aAvail = m_sLifePlayVersionAvailable.Split('.');

                int majorInst  = int.Parse(aInst[0]);
                int majorAvail = int.Parse(aAvail[0]);
                int minorInst  = int.Parse(aInst[1]);
                int minorAvail = int.Parse(aAvail[1]);

                if (majorInst <= majorAvail)
                {
                    if (minorInst < minorAvail)
                    {
                        DialogResult dr = MessageBox.Show("Looks like you are running an old version of LifePlay.\nShall I open the download site for you?", "LifePlay is out dated", MessageBoxButtons.YesNo);
                        if (dr == System.Windows.Forms.DialogResult.Yes)
                        {
                            Process.Start("https://f95zone.to/threads/lifeplay-v2-17-vinfamy.11321/");
                        }
                    }
                }
            }
            catch (Exception) { }

            if (m_sLauncherVersionAvailable.Length > 0 && m_sLauncherVersionAvailable != Application.ProductVersion.ToString())
            {
                DialogResult dr = MessageBox.Show("There is a new version of the launcher available.\nShall I open the download site for you?", "Launcher is out dated", MessageBoxButtons.YesNo);
                if (dr == System.Windows.Forms.DialogResult.Yes)
                {
                    Process.Start("https://github.com/NickNo-dev/LP-ModManager/releases/latest");
                }
            }
        }
Exemplo n.º 12
0
        private void GetInstalledMods()
        {
            m_ModsInstalled.Clear();

            try
            {
                DirectoryInfo   directory   = new DirectoryInfo(m_sPath + MOD_SUBFOLDER);
                DirectoryInfo[] directories = directory.GetDirectories();

                foreach (DirectoryInfo folder in directories)
                {
                    bool wasDisabled = false;

                    // Test if the folder contains a required info file
                    FileInfo modFileInfo = null;
                    if (folder.GetFiles("*.lpmod").Length > 0)
                    {
                        modFileInfo = folder.GetFiles("*.lpmod")[0];
                    }
                    else if (folder.GetFiles("*.lpaddon").Length > 0)
                    {
                        modFileInfo = folder.GetFiles("*.lpaddon")[0];
                    }
                    else if (folder.GetFiles("*.disabled").Length > 0)
                    {
                        modFileInfo = folder.GetFiles("*.disabled")[0];

                        // reset old disabled state to new one
                        string newName = modFileInfo.FullName.Replace(".disabled", "");
                        modFileInfo.MoveTo(newName);
                        wasDisabled = true;
                    }

                    if (modFileInfo != null)
                    {
                        try
                        {
                            string modFile = folder.Name;
                            string modPath = modFileInfo.DirectoryName;

                            CMod instMod = new CMod(modFile, modPath);
                            if (wasDisabled)
                            {
                                instMod.setEnabled(!wasDisabled);
                            }

                            instMod.setFileName(modFileInfo.FullName);
                            instMod.readModInfo();

                            m_ModsInstalled.Add(instMod.getId(), instMod);
                        }
                        catch (Exception) { }
                    }
                }

                lblInstalledModules.Text = m_ModsInstalled.Count.ToString() + " modules installed (checked: " + DateTime.Now.ToString() + ")";
            }
            catch (Exception ex)
            {
                lblInstalledModules.Text = "I had problems reading your local installation... :-(";
            }
        }