Beispiel #1
0
        private void SetupTree()
        {
            // Set up the market tree.
            marketTree.BeginUpdate();
            marketTree.Nodes.Clear();
            // Set up the images.
            marketTree.ImageList = new ImageList();
            // Get child groups.
            List <InvMarketGroup> groups = InvMarketGroup.GetRootGroups();

            groups = groups.OrderBy(g => g.marketGroupName).ToList();
            // Add the groups.
            PopulateTreeGroups(marketTree.Nodes, marketTree.ImageList, groups);
            marketTree.EndUpdate();
        }
Beispiel #2
0
        public static string PreloadImages(BackgroundWorker worker)
        {
            if (UserData.typeIconZip == null || UserData.typeIconZip?.Length == 0)
            {
                // No zip file specified.
                return(null);
            }
            // Get inv types and icons.
            worker.ReportProgress(0, "Finding needed images.");
            List <int>            types  = new List <int>();
            List <int>            icons  = new List <int>();
            List <InvMarketGroup> groups = InvMarketGroup.GetRootGroups();

            while (groups.Count > 0)
            {
                InvMarketGroup group = groups[0];
                groups.Remove(group);
                // Add icon.
                icons.Add(group.iconID);
                // Add child groups to search list.
                groups.AddRange(InvMarketGroup.GetGroupChildren(group.marketGroupID));
                // Get types for group.
                List <InvType> groupTypes = InvType.GetMarketGroupTypes(group.marketGroupID);
                // Add types to group.
                foreach (InvType type in groupTypes)
                {
                    if (!type.published)
                    {
                        continue;
                    }
                    types.Add(type.typeID);
                }
            }
            List <string> files = new List <string>();

            foreach (int typeID in types)
            {
                string zipImageFile = "Types/" + typeID.ToString() + "_32.png";
                files.Add(zipImageFile);
            }
            int typesComplete = 0;

            worker.ReportProgress(0, "Opening types Zip...");
            if (UserData.typeIconZip != null && File.Exists(UserData.typeIconZip))
            {
                FileStream fileStream   = File.OpenRead(UserData.typeIconZip);
                ZipArchive zip          = new ZipArchive(fileStream);
                int        totalFiles   = types.Count;
                int        failedFiles  = 0;
                int        skippedFiles = 0;
                foreach (int typeID in types)
                {
                    ZipArchiveEntry zipFile = zip.GetEntry("Types/" + typeID.ToString() + "_64.png");
                    if (zipFile == null)
                    {
                        continue;
                    }
                    Stream       zStream   = zipFile.Open();
                    MemoryStream memStream = new MemoryStream();
                    zStream.CopyTo(memStream);
                    memStream.Position = 0;
                    try
                    {
                        Image img = Image.FromStream(memStream);
                        images[zipFile.FullName] = img;
                    }
                    catch (ArgumentException)
                    {
                        failedFiles++;
                        skippedFiles++;
                    }
                    typesComplete++;
                    if (typesComplete % 10 == 0)
                    {
                        double pct = (double)typesComplete / (double)totalFiles;
                        string msg = "Loading type image files... (" + (typesComplete - skippedFiles) + " of " + totalFiles + " complete)";
                        if (failedFiles > 0)
                        {
                            msg += " (" + failedFiles + " failed.)";
                        }
                        worker.ReportProgress(Math.Min((int)(pct * 50.0), 100), msg);
                    }
                }
            }
            int iconsComplete = 0;

            worker.ReportProgress(50, "Opening icons Zip...");
            if (UserData.iconsZip != null && File.Exists(UserData.iconsZip))
            {
                // Open the zip archive.
                FileStream fileStream = File.OpenRead(UserData.iconsZip);
                ZipArchive zip        = new ZipArchive(fileStream);
                int        totalFiles = icons.Count;
                foreach (int iconID in icons)
                {
                    IconID icon = IconID.GetIconID(iconID);
                    if (icon == null)
                    {
                        continue;
                    }
                    // Construct image path.
                    string iconFile  = icon.iconFile;
                    int    lastSlash = iconFile.LastIndexOf('/');
                    iconFile = "Icons/items/" + iconFile.Substring(lastSlash + 1);
                    // Get the file.
                    MemoryStream    memStream = new MemoryStream();
                    ZipArchiveEntry zipFile   = zip.GetEntry(iconFile);
                    if (zipFile == null)
                    {
                        continue;
                    }
                    Stream zStream = zipFile.Open();
                    zStream.CopyTo(memStream);
                    memStream.Position = 0;
                    try
                    {
                        Image img = Image.FromStream(memStream);
                        images[iconFile] = img;
                    }
                    catch (ArgumentException)
                    {
                    }
                    iconsComplete++;
                    if (iconsComplete % 10 == 0)
                    {
                        double pct = (double)iconsComplete / (double)totalFiles;
                        string msg = "Loading Icon image files... (" + iconsComplete + " of " + totalFiles + " complete)";
                        worker.ReportProgress(Math.Min((int)(pct * 50.0) + 50, 100), msg);
                    }
                }
            }
            worker.ReportProgress(100, "Loaded " + typesComplete + " type images and " + iconsComplete + " icon images loaded.");
            return(null);
        }