Beispiel #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.ClearSelection();

            if (!string.IsNullOrEmpty(Program.CommandLineOptions.NextLaunchPath))
            {
                ModManager.LaunchCommand = Program.CommandLineOptions.NextLaunchPath;
                Program.CommandLineOptions.NextLaunchPath = null;
                ModManager.SyncConfigToDisk();
            }

            // Fetch the latest version from github
            Task.Run(() =>
            {
                latestOnlineVersion = GitHubAPI.GetLatestVersionFromGitHub(GitHubRepo);
            }).ContinueWith(res =>
            {
                if (latestOnlineVersion != null && latestOnlineVersion.IsAMLVersionLower())
                {
                    BasicButtonPopup resultButton = this.GetBasicButton("A new version of AstroModLoader (v" + latestOnlineVersion + ") is available!", "OK", "Open in browser", null);
                    resultButton.PageToVisit      = GitHubAPI.GetLatestVersionURL(GitHubRepo);
                    resultButton.ShowDialog();
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());

            // Initial resize of the menu to fit the table if necessary
            AMLUtils.InvokeUI(ForceTableToFit);

            AMLUtils.InvokeUI(ForceResize);
            AMLUtils.InvokeUI(ForceResize);

            UpdateVersionLabel();
            RefreshModInfoLabel();
        }
 public static void RefreshTheme(Form frm)
 {
     AMLUtils.InvokeUI(() =>
     {
         RefreshThemeInternal(frm);
     });
 }
Beispiel #3
0
 private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
 {
     if (TableManager != null)
     {
         AMLUtils.InvokeUI(() => TableManager.PaintCell(sender, e));
     }
 }
Beispiel #4
0
        public void FullRefresh()
        {
            if (ModManager != null)
            {
                Directory.CreateDirectory(ModManager.DownloadPath);
                Directory.CreateDirectory(ModManager.InstallPath);

                ModManager.SyncModsFromDisk();
                ModManager.SyncConfigFromDisk();
                ModManager.UpdateReadOnlyStatus();
                ModManager.SortMods();
                if (!autoUpdater.IsBusy)
                {
                    autoUpdater.RunWorkerAsync();
                }
            }

            AMLUtils.InvokeUI(() =>
            {
                if (TableManager != null)
                {
                    TableManager.Refresh();
                }
                AMLPalette.RefreshTheme(this);
                RefreshModInfoLabel();
            });
        }
        private void UpdatePathing(object sender, EventArgs e)
        {
            string correctedGamePath  = AMLUtils.FixGamePath(gamePathBox.Text);
            string correctedLocalPath = AMLUtils.FixBasePath(localPathBox.Text);

            if (string.IsNullOrEmpty(correctedGamePath) || !AMLUtils.IsValidPath(correctedGamePath))
            {
                gamePathBox.Text = BaseForm.ModManager.GamePath;
                this.ShowBasicButton("The specified game path is invalid!", "OK", null, null);
                return;
            }

            if (string.IsNullOrEmpty(correctedLocalPath) || !AMLUtils.IsValidPath(correctedLocalPath))
            {
                localPathBox.Text = BaseForm.ModManager.BasePath;
                this.ShowBasicButton("The specified local path is invalid!", "OK", null, null);
                return;
            }

            BaseForm.ModManager.ValidPlatformTypesToPaths[PlatformType.Custom] = correctedGamePath;
            BaseForm.ModManager.CustomBasePath = correctedLocalPath;
            BaseForm.ModManager.RefreshAllPlatformsList();
            BaseForm.SwitchPlatform(PlatformType.Custom);

            this.UpdateLabels();
        }
        private void accentComboBox_UpdateColor(object sender, EventArgs e)
        {
            Color backupColor = Color.FromArgb(AMLPalette.AccentColor.ToArgb());

            try
            {
                if (AMLPalette.PresetMap.ContainsKey(accentComboBox.Text))
                {
                    AMLPalette.AccentColor = AMLPalette.PresetMap[accentComboBox.Text];
                }
                else
                {
                    AMLPalette.AccentColor = AMLUtils.ColorFromHTML(accentComboBox.Text);
                }

                AMLPalette.RefreshTheme(BaseForm);
                BaseForm.ModManager.SyncConfigToDisk();
                AMLPalette.RefreshTheme(this);
            }
            catch
            {
                this.ShowBasicButton("Invalid color!", "OK", null, null);
                AMLPalette.AccentColor = backupColor;
            }
            UpdateColorBoxText();
        }
 private void SetDebugText(string txt)
 {
     AMLUtils.InvokeUI(() =>
     {
         debugLabel.Text = txt;
     });
 }
        private void refuseMismatchedConnectionsCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            ModHandler.OurIntegrator.RefuseMismatchedConnections = refuseMismatchedConnectionsCheckbox.Checked;
            BaseForm.ModManager.SyncDependentConfigToDisk();
            AMLUtils.InvokeUI(BaseForm.TableManager.Refresh);

            this.UpdateLabels();
        }
 public void SyncConfigToDisk()
 {
     AMLUtils.InvokeUI(() =>
     {
         SyncDependentConfigToDisk();
         SyncIndependentConfigToDisk();
     });
 }
 private void waitingTimer_Tick(object sender, EventArgs e)
 {
     AMLUtils.InvokeUI(() =>
     {
         numDots++; if (numDots > 3)
         {
             numDots = 1;
         }
         this.label1.Text = "Working" + new string('.', numDots);
     });
 }
        private void UpdateColorBoxText()
        {
            foreach (KeyValuePair <string, Color> entry in AMLPalette.PresetMap)
            {
                if (entry.Value.Equals(AMLPalette.AccentColor))
                {
                    accentComboBox.Text = entry.Key;
                    return;
                }
            }

            accentComboBox.Text = AMLUtils.ColorToHTML(AMLPalette.AccentColor);
        }
Beispiel #12
0
        private async Task ForceUpdateCells()
        {
            await Task.Run(() =>
            {
                if (ModManager.IsReadOnly)
                {
                    return;
                }

                if (!updateCellsSemaphore.WaitOne(5000))
                {
                    return;
                }
                foreach (DataGridViewRow row in this.dataGridView1.Rows)
                {
                    if (row.Tag is Mod taggedMod)
                    {
                        if (taggedMod.CannotCurrentlyUpdate)
                        {
                            continue;
                        }
                        taggedMod.Enabled = (bool)row.Cells[0].Value;
                        if (TableHandler.ShouldContainOptionalColumn())
                        {
                            taggedMod.IsOptional = (bool)row.Cells[5].Value;
                        }
                        if (row.Cells[2].Value is string strVal)
                        {
                            Version changingVer = null;
                            if (strVal.Contains("Latest"))
                            {
                                taggedMod.ForceLatest = true;
                                changingVer           = taggedMod.AvailableVersions[0];
                            }
                            else
                            {
                                taggedMod.ForceLatest = false;
                                changingVer           = new Version(strVal);
                            }

                            SwitchVersionSync(taggedMod, changingVer);
                        }
                    }
                }
                ModManager.FullUpdate();
                updateCellsSemaphore.Release();
            }).ContinueWith(res =>
            {
                AMLUtils.InvokeUI(TableManager.Refresh);
            });
        }
Beispiel #13
0
        public Form1()
        {
            InitializeComponent();
            modInfo.Text = "";
            AMLUtils.InitializeInvoke(this);

            this.Text = "AstroModLoader v" + Application.ProductVersion;

            // Enable double buffering to look nicer
            if (!SystemInformation.TerminalServerSession)
            {
                Type         ourGridType = dataGridView1.GetType();
                PropertyInfo pi          = ourGridType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
                pi.SetValue(dataGridView1, true, null);
                this.DoubleBuffered = true;
            }
            dataGridView1.Select();

            if (Program.CommandLineOptions.ServerMode)
            {
                syncButton.Hide();
            }

            ModManager   = new ModHandler(this);
            TableManager = new TableHandler(dataGridView1, ModManager);

            dataGridView1.CellValueChanged    += DataGridView1_CellValueChanged;
            dataGridView1.CellContentClick    += DataGridView1_CellContentClick;
            dataGridView1.DataBindingComplete += DataGridView1_DataBindingComplete;
            dataGridView1.CellEndEdit         += DataGridView1_CellEndEdit;
            dataGridView1.SelectionChanged    += new EventHandler(DataGridView1_SelectionChanged);
            footerPanel.Paint += Footer_Paint;
            AMLPalette.RefreshTheme(this);

            AllowDrop  = true;
            DragEnter += new DragEventHandler(Form1_DragEnter);
            DragDrop  += new DragEventHandler(Form1_DragDrop);
            dataGridView1.DragEnter += new DragEventHandler(Form1_DragEnter);
            dataGridView1.DragDrop  += new DragEventHandler(Form1_DragDrop);

            PeriodicCheckTimer.Enabled     = true;
            CheckAllDirty.Enabled          = true;
            ForceAutoUpdateRefresh.Enabled = true;

            autoUpdater                     = new BackgroundWorker();
            autoUpdater.DoWork             += new DoWorkEventHandler(AutoUpdater_DoWork);
            autoUpdater.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Simple_Refresh_RunWorkerCompleted);
            autoUpdater.RunWorkerAsync();
        }
        public void SyncIndependentConfigFromDisk()
        {
            IndependentConfig independentConfig = null;

            try
            {
                independentConfig = JsonConvert.DeserializeObject <IndependentConfig>(File.ReadAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "AstroModLoader", "config.json")));
            }
            catch
            {
                independentConfig = null;
            }

            if (independentConfig != null)
            {
                if (!string.IsNullOrEmpty(independentConfig.AccentColor))
                {
                    try
                    {
                        AMLPalette.AccentColor = AMLUtils.ColorFromHTML(independentConfig.AccentColor);
                    }
                    catch { }
                }
                AMLPalette.CurrentTheme = independentConfig.Theme;
                AMLPalette.RefreshTheme(BaseForm);

                Platform = independentConfig.Platform;
                if (FirstRecordedIndependentConfigPlatform == PlatformType.Unknown)
                {
                    FirstRecordedIndependentConfigPlatform = independentConfig.Platform;
                }
                if (!string.IsNullOrEmpty(independentConfig.CustomBasePath))
                {
                    CustomBasePath = independentConfig.CustomBasePath;
                }
                if (!string.IsNullOrEmpty(independentConfig.PlayFabCustomID))
                {
                    PlayFabAPI.CustomID = independentConfig.PlayFabCustomID;
                }
                if (!string.IsNullOrEmpty(independentConfig.PlayFabToken))
                {
                    PlayFabAPI.Token = independentConfig.PlayFabToken;
                }
            }
        }
        private void RunOKButton()
        {
            PerformPathSubstitutions();

            if (AllowBrowse && !AMLUtils.IsValidPath(gamePathBox.Text))
            {
                ShowWarning("This is not a valid path!");
                return;
            }

            if (gamePathBox.Text != null && gamePathBox.Text.Length > 0)
            {
                var doneText = gamePathBox.Text;
                if (AllowBrowse && doneText[doneText.Length - 1] == Path.DirectorySeparatorChar)
                {
                    doneText = doneText.Substring(0, doneText.Length - 1);
                }
                switch (VerifyMode)
                {
                case VerifyPathMode.Base:
                    doneText = AMLUtils.FixBasePath(doneText);
                    if (string.IsNullOrEmpty(doneText))
                    {
                        ShowWarning("This is not the correct path!");
                        OutputText = null;
                        return;
                    }
                    break;

                case VerifyPathMode.Game:
                    doneText = AMLUtils.FixGamePath(doneText);
                    if (doneText == null)
                    {
                        ShowWarning("This is not the correct path!");
                        OutputText = null;
                        return;
                    }
                    break;
                }

                OutputText        = doneText;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Beispiel #16
0
        public bool DownloadVersionSync(Mod thisMod, Version newVersion)
        {
            try
            {
                if (!ModManager.GlobalIndexFile.ContainsKey(thisMod.CurrentModData.ModID))
                {
                    throw new IndexFileException("Can't find index file entry for mod: " + thisMod.CurrentModData.ModID);
                }
                Dictionary <Version, IndexVersionData> allVerData = ModManager.GlobalIndexFile[thisMod.CurrentModData.ModID].AllVersions;
                if (!allVerData.ContainsKey(newVersion))
                {
                    throw new IndexFileException("Failed to find the requested version in the mod's index file: " + thisMod.CurrentModData.ModID + " v" + newVersion);
                }

                using (var wb = new WebClient())
                {
                    wb.Headers[HttpRequestHeader.UserAgent] = AMLUtils.UserAgent;

                    string kosherFileName = AMLUtils.SanitizeFilename(allVerData[newVersion].Filename);

                    string tempDownloadFolder = Path.Combine(Path.GetTempPath(), "AstroModLoader", "Downloads");
                    Directory.CreateDirectory(tempDownloadFolder);
                    wb.DownloadFile(allVerData[newVersion].URL, Path.Combine(tempDownloadFolder, kosherFileName));
                    InstallModFromPath(Path.Combine(tempDownloadFolder, kosherFileName), out _, out int numMalformatted, out _);
                    if (numMalformatted > 0)
                    {
                        throw new FormatException(numMalformatted + " mods were malformatted");
                    }
                    ModManager.SortVersions();
                    ModManager.SortMods();
                    Directory.Delete(tempDownloadFolder, true);
                }
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is IOException || ex is IndexFileException)
                {
                    Debug.WriteLine(ex.ToString());
                    return(false);
                }
                throw;
            }
            return(true);
        }
        public void SyncIndependentConfigToDisk()
        {
            var newIndConfig = new IndependentConfig();

            if (Program.CommandLineOptions.ServerMode)
            {
                newIndConfig.Platform = FirstRecordedIndependentConfigPlatform;
            }
            else
            {
                newIndConfig.Platform = Platform;
            }
            newIndConfig.Theme           = AMLPalette.CurrentTheme;
            newIndConfig.AccentColor     = AMLUtils.ColorToHTML(AMLPalette.AccentColor);
            newIndConfig.CustomBasePath  = CustomBasePath;
            newIndConfig.PlayFabCustomID = PlayFabAPI.CustomID;
            newIndConfig.PlayFabToken    = PlayFabAPI.Token;

            Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "AstroModLoader"));
            File.WriteAllBytes(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "AstroModLoader", "config.json"), Encoding.UTF8.GetBytes(AMLUtils.SerializeObject(newIndConfig)));
        }
Beispiel #18
0
        private void DataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            Mod selectedMod = TableManager.GetCurrentlySelectedMod();

            if (dataGridView1.SelectedRows.Count == 1 && !ModManager.IsReadOnly)
            {
                DataGridViewRow selectedRow = dataGridView1.SelectedRows[0];
                int             newModIndex = selectedRow.Index;

                // If shift is held, that means we are changing the order
                if (canAdjustOrder && ModifierKeys == Keys.Shift && selectedMod != null && previouslySelectedMod != null && previouslySelectedMod != selectedMod)
                {
                    AMLUtils.InvokeUI(() =>
                    {
                        ModManager.SwapMod(previouslySelectedMod, newModIndex, false);
                        previouslySelectedMod = null;
                        canAdjustOrder        = false;
                        TableManager.Refresh();
                        canAdjustOrder = true;

                        dataGridView1.ClearSelection();
                        dataGridView1.Rows[newModIndex].Selected = true;
                        dataGridView1.CurrentCell = dataGridView1.Rows[newModIndex].Cells[0];
                        selectedMod = ModManager.Mods[newModIndex];

                        foreach (Mod mod in ModManager.Mods)
                        {
                            mod.Dirty = true;                                  // Update all the priorities on disk to be safe
                        }
                        ModManager.FullUpdate();
                    });
                }
            }

            previouslySelectedMod = selectedMod;

            RefreshModInfoLabel();
        }
        public void UpdateAvailableVersionsFromIndexFiles()
        {
            IsUpdatingAvailableVersionsFromIndexFilesWaitHandler.Reset();
            Dictionary <Mod, Version> switchVersionInstructions = new Dictionary <Mod, Version>();

            foreach (Mod mod in Mods)
            {
                Version latestVersion = null;
                if (mod.AvailableVersions.Count > 0)
                {
                    latestVersion = mod.AvailableVersions[0];
                }
                if (GlobalIndexFile.ContainsKey(mod.CurrentModData.ModID))
                {
                    IndexMod indexMod = GlobalIndexFile[mod.CurrentModData.ModID];
                    mod.AvailableVersions.AddRange(indexMod.AllVersions.Keys.Except(mod.AvailableVersions));
                    mod.AvailableVersions.Sort();
                    mod.AvailableVersions.Reverse();
                    latestVersion = mod.AvailableVersions[0];
                    //if (indexMod.LatestVersion != null) latestVersion = indexMod.LatestVersion;
                }

                if (mod.ForceLatest && latestVersion != null)
                {
                    switchVersionInstructions.Add(mod, latestVersion);
                }
            }

            AMLUtils.InvokeUI(BaseForm.TableManager.Refresh);

            foreach (KeyValuePair <Mod, Version> entry in switchVersionInstructions)
            {
                BaseForm.SwitchVersionSync(entry.Key, entry.Value);
            }
            IsUpdatingAvailableVersionsFromIndexFilesWaitHandler.Set();
        }
 public void Refresh()
 {
     AMLUtils.InvokeUI(RefreshInternal);
 }
        private void ForceExportProfile()
        {
            if (listBox1.SelectedValue == null || SelectedProfile == null)
            {
                this.ShowBasicButton("Please select a profile to export it as a .zip file.", "OK", null, null);
                return;
            }

            var dialog = new SaveFileDialog();

            dialog.Filter           = "ZIP files (*.zip)|*.zip|All files (*.*)|*.*";
            dialog.Title            = "Export a profile";
            dialog.RestoreDirectory = true;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string targetFolderPath = Path.Combine(Path.GetTempPath(), "AstroModLoader", "export");
                Directory.CreateDirectory(targetFolderPath);

                ModProfile creatingProfile = new ModProfile();
                creatingProfile.ProfileData = new Dictionary <string, Mod>();
                creatingProfile.Name        = listBox1.SelectedValue as string;
                creatingProfile.Info        = "Exported by " + AMLUtils.UserAgent + " at " + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffK");

                List <KeyValuePair <string, Mod> > plannedOrdering = new List <KeyValuePair <string, Mod> >();
                foreach (KeyValuePair <string, Mod> entry in SelectedProfile.ProfileData)
                {
                    if (entry.Value.Enabled)
                    {
                        plannedOrdering.Add(entry);
                    }
                }
                plannedOrdering = new List <KeyValuePair <string, Mod> >(plannedOrdering.OrderBy(o => o.Value.Priority).ToList());

                for (int i = 0; i < plannedOrdering.Count; i++)
                {
                    plannedOrdering[i].Value.Priority = i + 1;
                    creatingProfile.ProfileData[plannedOrdering[i].Key] = plannedOrdering[i].Value;

                    // Copy mod pak to the zip as well
                    string onePathOnDisk = OurParentForm.ModManager.GetPathOnDisk(plannedOrdering[i].Value, plannedOrdering[i].Key);
                    if (!string.IsNullOrEmpty(onePathOnDisk))
                    {
                        File.Copy(onePathOnDisk, Path.Combine(targetFolderPath, Path.GetFileName(onePathOnDisk)));
                    }
                }

                File.WriteAllBytes(Path.Combine(targetFolderPath, "profile1.json"), Encoding.UTF8.GetBytes(AMLUtils.SerializeObject(creatingProfile)));

                ZipFile.CreateFromDirectory(targetFolderPath, dialog.FileName);
                Directory.Delete(targetFolderPath, true);

                RefreshBox();
                statusLabel.Text = "Successfully exported profile.";
            }
        }
Beispiel #22
0
 public string ConstructName(int forcePriority = -1)
 {
     return(AMLUtils.GeneratePriorityFromPositionInList(forcePriority >= 0 ? forcePriority : Priority) + "-" + ModIDFilterRegex.Replace(CurrentModData.ModID, "") + "-" + InstalledVersion + "_P.pak");
 }
Beispiel #23
0
        private async void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string[] installingModPaths = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (installingModPaths.Length > 0)
            {
                Dictionary <string, List <Version> > newMods = new Dictionary <string, List <Version> >();
                int clientOnlyCount       = 0;
                int malformattedCount     = 0;
                int newProfileCount       = 0;
                int invalidExtensionCount = 0;
                int wasFolderCount        = 0;
                foreach (string newInstallingMod in installingModPaths)
                {
                    if (!File.Exists(newInstallingMod))
                    {
                        wasFolderCount++;
                        continue;
                    }
                    if (!AllowedModExtensions.Contains(Path.GetExtension(newInstallingMod)))
                    {
                        invalidExtensionCount++;
                        continue;
                    }

                    List <Mod> resMods = InstallModFromPath(newInstallingMod, out int thisClientOnlyCount, out int thisNumMalformatted, out int thisNumNewProfiles);
                    if (resMods == null)
                    {
                        continue;
                    }
                    foreach (Mod resMod in resMods)
                    {
                        if (resMod == null)
                        {
                            continue;
                        }
                        if (!newMods.ContainsKey(resMod.CurrentModData.ModID))
                        {
                            newMods[resMod.CurrentModData.ModID] = new List <Version>();
                        }
                        newMods[resMod.CurrentModData.ModID].AddRange(resMod.AvailableVersions);
                    }
                    clientOnlyCount   += thisClientOnlyCount;
                    malformattedCount += thisNumMalformatted;
                    newProfileCount   += thisNumNewProfiles;
                }

                //ModManager.SyncModsFromDisk(true);
                ModManager.SortMods();
                ModManager.SortVersions();
                ModManager.RefreshAllPriorites();
                if (!autoUpdater.IsBusy)
                {
                    autoUpdater.RunWorkerAsync();
                }

                foreach (Mod mod in ModManager.Mods)
                {
                    if (mod == null)
                    {
                        continue;
                    }
                    mod.Dirty = true;

                    if (newMods.ContainsKey(mod.CurrentModData.ModID))
                    {
                        // We switch the installed version to the newest version that has just been added
                        newMods[mod.CurrentModData.ModID].Sort();
                        newMods[mod.CurrentModData.ModID].Reverse();
                        mod.InstalledVersion = newMods[mod.CurrentModData.ModID][0];

                        // If this is a new mod, we enable it or disable it automatically, but if it's not new then we respect the user's pre-existing setting
                        if (mod.AvailableVersions.Count == 1)
                        {
                            mod.Enabled = ModManager.InstalledAstroBuild.AcceptablySimilar(mod.CurrentModData.AstroBuild) && (!Program.CommandLineOptions.ServerMode || mod.CurrentModData.Sync != SyncMode.ClientOnly);
                        }
                    }
                }

                await ModManager.FullUpdate();

                AMLUtils.InvokeUI(() =>
                {
                    TableManager.Refresh();
                    if (wasFolderCount > 0)
                    {
                        this.ShowBasicButton("You cannot drag in a folder!", "OK", null, null);
                    }

                    if (invalidExtensionCount > 0)
                    {
                        this.ShowBasicButton(invalidExtensionCount + " file" + (invalidExtensionCount == 1 ? " had an invalid extension" : "s had invalid extensions") + " and " + (invalidExtensionCount == 1 ? "was" : "were") + " ignored.\nAcceptable mod extensions are: " + string.Join(", ", AllowedModExtensions), "OK", null, null);
                    }

                    if (clientOnlyCount > 0)
                    {
                        this.ShowBasicButton(clientOnlyCount + " mod" + (clientOnlyCount == 1 ? " is" : "s are") + " designated as \"Client only\" and " + (clientOnlyCount == 1 ? "was" : "were") + " ignored.", "OK", null, null);
                    }

                    if (malformattedCount > 0)
                    {
                        this.ShowBasicButton(malformattedCount + " mod" + (malformattedCount == 1 ? " was" : "s were") + " malformatted, and could not be installed.\nThe file name may be invalid, the metadata may be invalid, or both.\nPlease ensure that this mod meets the community-made standards.", "OK", null, null);
                    }

                    if (newProfileCount > 0)
                    {
                        this.ShowBasicButton(newProfileCount + " new profile" + (newProfileCount == 1 ? " was" : "s were") + " included with the file" + (installingModPaths.Length == 1 ? "" : "s") + " you installed.\n" + (newProfileCount == 1 ? "It has" : "They have") + " been added to your list of profiles.", "OK", null, null);
                    }
                });
            }
        }
Beispiel #24
0
        private void RefreshModInfoLabel()
        {
            AMLUtils.InvokeUI(() =>
            {
                Mod selectedMod = TableManager?.GetCurrentlySelectedMod();
                if (selectedMod == null)
                {
                    AdjustModInfoText("");
                    return;
                }

                string kosherDescription = selectedMod.CurrentModData.Description;
                if (!string.IsNullOrEmpty(kosherDescription) && kosherDescription.Length > 200)
                {
                    kosherDescription = kosherDescription.Substring(0, 200) + "...";
                }

                string kosherSync = "N/A";
                switch (selectedMod.CurrentModData.Sync)
                {
                case SyncMode.None:
                    kosherSync = "None";
                    break;

                case SyncMode.ClientOnly:
                    kosherSync = "Client only";
                    break;

                case SyncMode.ServerOnly:
                    kosherSync = "Server only";
                    break;

                case SyncMode.ServerAndClient:
                    kosherSync = "Server and client";
                    break;
                }

                long knownSize = -1;
                try
                {
                    knownSize = ModManager.GetSizeOnDisk(selectedMod);
                }
                catch (Exception ex)
                {
                    if (!(ex is IOException) && !(ex is FileNotFoundException))
                    {
                        throw;
                    }
                }

                string additionalData = "";
                if (knownSize >= 0)
                {
                    additionalData += "\nSize: " + AMLUtils.FormatFileSize(knownSize);
                }

                bool hasHomepage = !string.IsNullOrEmpty(selectedMod.CurrentModData.Homepage) && AMLUtils.IsValidUri(selectedMod.CurrentModData.Homepage);

                string realText = "Name: " + selectedMod.CurrentModData.Name;
                if (!string.IsNullOrEmpty(kosherDescription))
                {
                    realText += "\nDescription: " + kosherDescription;
                }
                realText += "\nSync: " + kosherSync;
                realText += additionalData;
                realText += hasHomepage ? "\nWebsite: " : "";

                AdjustModInfoText(realText, hasHomepage ? selectedMod.CurrentModData.Homepage : "");
            });
        }
Beispiel #25
0
        private void modInfo_LinkClicked(object sender, EventArgs e)
        {
            Mod selectedMod = TableManager.GetCurrentlySelectedMod();

            if (selectedMod != null && !string.IsNullOrEmpty(selectedMod.CurrentModData.Homepage) && AMLUtils.IsValidUri(selectedMod.CurrentModData.Homepage))
            {
                Process.Start(selectedMod.CurrentModData.Homepage);
            }
        }
        public void DeterminePaths()
        {
            string normalSteamBasePath          = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Astro");
            string normalMicrosoftStoreBasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Packages", "SystemEraSoftworks.29415440E1269_ftk5pbg2rayv2", "LocalState", "Astro");

            BasePath = null;
            if (!string.IsNullOrEmpty(Program.CommandLineOptions.LocalDataPath))
            {
                BasePath = AMLUtils.FixBasePath(Path.GetFullPath(Path.Combine(Program.CommandLineOptions.LocalDataPath, "Astro")));
            }
            else
            {
                if (Program.CommandLineOptions.ServerMode)
                {
                    BasePath = Path.Combine(GamePath != null ? GamePath : Directory.GetCurrentDirectory(), "Astro");
                }
                else if (Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) != null)
                {
                    switch (Platform)
                    {
                    case PlatformType.Steam:
                        BasePath = normalSteamBasePath;
                        break;

                    case PlatformType.Win10:
                        BasePath = normalMicrosoftStoreBasePath;
                        break;
                    }
                }
            }

            if (BasePath == null || !Directory.Exists(BasePath))
            {
                if (Platform == PlatformType.Custom || Platform == PlatformType.Unknown)
                {
                    if (!string.IsNullOrEmpty(CustomBasePath))
                    {
                        BasePath = CustomBasePath;
                    }
                    else
                    {
                        // If the regular Steam or Microsoft Store base paths do exist, they're probably what the user actually wants, but we still want to give them the option to change it here so we just put it in as prefilled text

                        TextPrompt initialPathPrompt = new TextPrompt
                        {
                            StartPosition = FormStartPosition.CenterScreen,
                            DisplayText   = "Select your local application data directory",
                            PrefilledText = Directory.Exists(normalSteamBasePath) ? normalSteamBasePath : (Directory.Exists(normalMicrosoftStoreBasePath) ? normalMicrosoftStoreBasePath : null),
                            VerifyMode    = VerifyPathMode.Base
                        };

                        if (initialPathPrompt.ShowDialog(BaseForm) == DialogResult.OK)
                        {
                            CustomBasePath = initialPathPrompt.OutputText;
                            BasePath       = CustomBasePath;
                        }
                        else
                        {
                            Environment.Exit(0);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Unable to find the local application data directory. If you have never created an Astroneer save file within the game on this computer before, please do so and then re-open AstroModLoader. Otherwise, please specify a local application data directory with the --data parameter.", "Uh oh!");
                    Environment.Exit(0);
                }
            }

            DetermineBasePathDerivatives();
        }
        public ModHandler(Form1 baseForm)
        {
            BaseForm      = baseForm;
            OurIntegrator = new ModIntegrator();
            OurIntegrator.RefuseMismatchedConnections = true;

            string automaticSteamPath = null;
            string automaticWin10Path = null;

            if (!Program.CommandLineOptions.ServerMode)
            {
                try
                {
                    automaticSteamPath = AMLUtils.FixGamePath(CheckRegistryForSteamPath(361420)); // Astroneer: 361420
                }
                catch { }

                try
                {
                    automaticWin10Path = AMLUtils.FixGamePath(CheckRegistryForMicrosoftStorePath());
                }
                catch { }
            }

            //automaticSteamPath = null;
            //automaticWin10Path = null;

            ValidPlatformTypesToPaths = new Dictionary <PlatformType, string>();
            if (automaticSteamPath != null)
            {
                ValidPlatformTypesToPaths[PlatformType.Steam] = automaticSteamPath;
            }
            if (automaticWin10Path != null)
            {
                ValidPlatformTypesToPaths[PlatformType.Win10] = automaticWin10Path;
            }

            SyncIndependentConfigFromDisk();
            if (!string.IsNullOrEmpty(CustomBasePath))
            {
                string customGamePath = GetGamePathFromBasePath(CustomBasePath);
                if (!string.IsNullOrEmpty(customGamePath))
                {
                    ValidPlatformTypesToPaths[PlatformType.Custom] = customGamePath;
                }
            }

            RefreshAllPlatformsList();
            if (!ValidPlatformTypesToPaths.ContainsKey(Platform) && AllPlatforms.Count > 0)
            {
                Platform = AllPlatforms[0];
            }
            if (Program.CommandLineOptions.ServerMode)
            {
                Platform = PlatformType.Server;
            }

            DeterminePaths();
            SyncModsFromDisk();
            SyncDependentConfigFromDisk();
            VerifyGamePath();

            if (Program.CommandLineOptions.ServerMode && Directory.Exists(Path.Combine(BasePath, "Saved")))
            {
                GamePath = Path.GetFullPath(Path.Combine(BasePath, ".."));
            }

            if (GamePath == null || !Directory.Exists(GamePath))
            {
                GamePath = null;
                if (ValidPlatformTypesToPaths.ContainsKey(Platform))
                {
                    GamePath = ValidPlatformTypesToPaths[Platform];
                }
                else
                {
                    TextPrompt initialPathPrompt = new TextPrompt
                    {
                        StartPosition = FormStartPosition.CenterScreen,
                        DisplayText   = "Select your game installation directory",
                        VerifyMode    = VerifyPathMode.Game
                    };

                    if (initialPathPrompt.ShowDialog(BaseForm) == DialogResult.OK)
                    {
                        GamePath = initialPathPrompt.OutputText;
                        Platform = PlatformType.Custom;
                        ValidPlatformTypesToPaths[PlatformType.Custom] = GamePath;
                        RefreshAllPlatformsList();
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }

            ApplyGamePathDerivatives();
            VerifyIntegrity();

            foreach (Mod mod in Mods)
            {
                mod.Dirty = true;
            }
            FullUpdateSynchronous();
            SortMods();
            RefreshAllPriorites();
            SyncConfigToDisk();
        }
        public void SyncDependentConfigToDisk()
        {
            var newConfig = new ModConfig();

            newConfig.GamePath      = GamePath;
            newConfig.LaunchCommand = LaunchCommand;
            newConfig.RefuseMismatchedConnections = OurIntegrator.RefuseMismatchedConnections;
            newConfig.Profiles   = ProfileList;
            newConfig.ModsOnDisk = GenerateProfile();

            File.WriteAllBytes(Path.Combine(DownloadPath, "modconfig.json"), Encoding.UTF8.GetBytes(AMLUtils.SerializeObject(newConfig)));
        }