Esempio n. 1
0
        private void UpdateInstalledMaps()
        {
            if (InvokeRequired)
            {
                var d = new SafeVoid(UpdateInstalledMaps);
                Invoke(d);
            }
            else
            {
                Map.installed = new List <Map>();
                // Find all files ending with .info.txt in mordhaupath
                foreach (string f in Directory.GetFiles(m_MordhauPath, "*.info.txt", SearchOption.AllDirectories))
                {
                    using (var reader = new StreamReader(f))
                    {
                        var m = new Map();
                        try
                        {
                            string   content = reader.ReadToEnd().Replace("\r\n", "\n");
                            string[] lines   = content.Split('\n');
                            m.name        = lines[MapVars.name];
                            m.folderName  = lines[MapVars.folderName];
                            m.description = lines[MapVars.description];
                            m.authors     = lines[MapVars.authors];
                            m.version     = lines[MapVars.version];
                            m.releaseDate = DateTime.ParseExact(lines[MapVars.releaseDate], "dd/MM/yyyy",
                                                                CultureInfo.InvariantCulture);
                            m.fileSize = lines[MapVars.fileSize];
                            if (lines.Length > MapVars.suggestedPlayers)
                            {
                                m.suggestedPlayers = lines[MapVars.suggestedPlayers];
                            }
                            if (lines.Length > MapVars.thumbnailURL)
                            {
                                m.thumbnailURL = lines[MapVars.thumbnailURL];
                            }
                            //Log("Adding map " + m.name);
                            Map.installed.Add(m);
                        }
                        catch (Exception e)
                        {
                            Log($"Error in installed info file: {f}; {e.Message}");
                        }
                    }
                }

                foreach (Map m in Map.maps)
                {
                    foreach (Map y in Map.installed.Where(z =>
                                                          z.folderName.Equals(m.folderName) && !z.version.Equals(m.version) && !z.needsUpdate))
                    {
                        y.needsUpdate = true;
                        y.name        = $"[OUTDATED] {y.name}";
                    }
                }

                InstalledMapsBox.DataSource    = Map.installed;
                InstalledMapsBox.DisplayMember = "name";
                Update();
            }
        }
Esempio n. 2
0
        private void UpdateInstalledMaps()
        {
            if (InvokeRequired)
            {
                var d = new SafeVoid(UpdateInstalledMaps);
                Invoke(d);
            }
            else
            {
                Map.installed = new List <Map>();
                // Find all files ending with .info.txt in mordhaupath
                foreach (string f in Directory.GetFiles(m_MordhauPath, "*.info.txt", SearchOption.AllDirectories))
                {
                    using (var reader = new StreamReader(f))
                    {
                        var m = new Map();
                        try
                        {
                            string   content = reader.ReadToEnd().Replace("\r\n", "\n");
                            string[] lines   = content.Split('\n');
                            m.name        = lines[MapVars.name];
                            m.folderName  = lines[MapVars.folderName];
                            m.description = lines[MapVars.description];
                            m.authors     = lines[MapVars.authors];
                            m.version     = lines[MapVars.version];
                            m.releaseDate = DateTime.ParseExact(lines[MapVars.releaseDate], "dd/MM/yyyy",
                                                                CultureInfo.InvariantCulture);
                            m.fileSize = lines[MapVars.fileSize];
                            if (lines.Length > MapVars.suggestedPlayers)
                            {
                                m.suggestedPlayers = lines[MapVars.suggestedPlayers];
                            }
                            if (lines.Length > MapVars.thumbnailURL)
                            {
                                m.thumbnailURL = lines[MapVars.thumbnailURL];
                            }
                            if (lines.Length > MapVars.downloadURL && lines[MapVars.downloadURL].Length > 0)
                            {
                                m.downloadURL = GetDownloadLink(lines[MapVars.downloadURL]);
                            }
                            else
                            {
                                m.downloadURL =
                                    $@"https://github.com/MordhauMappingModding/MapFiles/blob/master/{m.folderName}.zip?raw=true";
                            }
                            //Log("Adding map " + m.name);
                            Map.installed.Add(m);
                        }
                        catch (Exception e)
                        {
                            Log($"Error in installed info file: {f}; {e.Message}");
                        }
                    }
                }

                CheckMapUpdates();

                InstalledMapsBox.DataSource    = Map.installed;
                InstalledMapsBox.DisplayMember = "name";
                Update();
            }
        }