Пример #1
0
        public static MapFolder GetMapsByFolder(List <Map> maps)
        {
            MapFolder root = new MapFolder();

            foreach (Map map in maps)
            {
                string fullName = map.name.Replace("\\", "/");

                string[]  dirs   = fullName.Split('/');
                MapFolder subdir = root;

                for (int i = 0; i < dirs.Length - 1; i++)
                {
                    string dir = dirs[i];

                    if (!subdir.subdirs.ContainsKey(dir))
                    {
                        subdir.subdirs.Add(dir, new MapFolder());
                    }

                    subdir = subdir.subdirs[dir];
                }

                subdir.maps.Add(map);
            }

            return(root);
        }
Пример #2
0
        private void LoadMaps()
        {
            string modPath = launcher.GetCurrentMod().installPath;

            string mapsPath = modPath + "\\maps\\";

            List <Map> maps = Map.LoadMaps(mapsPath).OrderByDescending(i => i.GetLastUpdate()).ToList();

            root = Map.GetMapsByFolder(maps);

            ShowMaps(string.Empty);
        }
Пример #3
0
        private void ShowMaps(string path)
        {
            path = path.Replace("\\", "/");

            string[]  dirs   = path.Split('/');
            MapFolder subdir = root;

            for (int i = 0; i < dirs.Length; i++)
            {
                string dir = dirs[i];

                if (dir == string.Empty)
                {
                    break;
                }

                if (!subdir.subdirs.ContainsKey(dir))   // Error. dir not found
                {
                    Debugger.Break();
                }
                subdir = subdir.subdirs[dir];
            }

            galleryControl.Gallery.Groups[0].Items.Clear();

            // Create gallery map folders
            foreach (KeyValuePair <string, MapFolder> map in subdir.subdirs)
            {
                string mapName = map.Key;

                Image bitmap = Bitmap.FromFile(AppDomain.CurrentDomain.BaseDirectory + "\\Assets\\Misc\\folder.png");

                string      mapDescription = string.Empty;
                GalleryItem item           = new GalleryItem(bitmap, mapName, mapDescription);
                item.Tag = map;
                galleryControl.Gallery.Groups[0].Items.Add(item);
            }

            // Create gallery map items
            foreach (Map map in subdir.maps)
            {
                string mapName = map.name;

                string        screenshotFilter = Path.GetFileName(mapName) + "*.jpg";
                List <string> screenshots      = new List <string>();

                if (Directory.Exists(modPath + "\\screenshots\\"))
                {
                    screenshots = new DirectoryInfo(modPath + "\\screenshots\\").GetFiles(screenshotFilter)
                                  .OrderByDescending(f => f.LastWriteTime)
                                  .Select(f => f.Name)
                                  .ToList();
                }

                Image bitmap = Bitmap.FromFile(AppDomain.CurrentDomain.BaseDirectory + "\\Assets\\Misc\\noScreenshots.png");
                foreach (string screenshot in screenshots)
                {
                    int i;
                    if (int.TryParse(screenshot.Replace(Path.GetFileName(mapName), string.Empty)
                                     .Replace(".jpg", string.Empty),
                                     out i))
                    {
                        bitmap = Bitmap.FromFile(modPath + "\\screenshots\\" + screenshot);

                        break;
                    }
                }

                string      mapDescription = map.versions.Last().Value.lastUpdateDate.ToString("dd/MM/yy HH:mm:ss");
                GalleryItem item           = new GalleryItem(bitmap, mapName, mapDescription);
                item.Tag = map;
                galleryControl.Gallery.Groups[0].Items.Add(item);
            }

            // Show path
            string instancePath = new GameInfo(launcher).getValue("instancepath");

            pathEdit.EditValue = instancePath + "\\" + string.Join("\\", dirs);
        }