Пример #1
0
        private static void LoadTexture(TextureLibrary library, TextureInfo info)
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter = "Images|*.png;*.bmp;*.jpg",
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                Bitmap bitmap;
                try
                {
                    bitmap = new Bitmap(ofd.FileName);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(
                        $"Unable to open image {ofd.FileName}\n{exception.Message}",
                        "Invalid image",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1);
                    return;
                }
                library.AddChange(info.name, bitmap);
            }
        }
Пример #2
0
        private void ExplorerForm_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                var paths = ((string[])e.Data.GetData(DataFormats.FileDrop));
                if (paths.Length == 1 && Directory.Exists(paths[0]) && IsInstallationFolder(paths[0]))
                {
                    imageListView.Clear();
                    folderTreeView.Nodes.Clear();
                    LoadTextureLists(paths[0]);
                    return;
                }
                if (instructionsLabel.Visible)
                {
                    BringToFront();
                    MessageBox.Show(
                        "Please select a valid Streets of Rage 4 installation folder",
                        "Data folder not found",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.DefaultDesktopOnly);
                    return;
                }

                var root = folderTreeView.SelectedNode.Name;
                foreach (var path in paths)
                {
                    if (File.Exists(path))
                    {
                        string name     = Path.GetFileNameWithoutExtension(path);
                        string filename = Path.Combine(root, name);
                        if (library.Contains(filename) == false)
                        {
                            MessageBox.Show(
                                this,
                                $"{filename}\ndoes not exist in the textures library",
                                "Invalid texture replacement",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1);
                            break;
                        }

                        Bitmap image;
                        try
                        {
                            image = new Bitmap(path);
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(
                                this,
                                $"Unable to open image {path}\n{exception.Message}",
                                "Invalid image",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1);
                            return;
                        }
                        library.AddChange(filename, image);
                        UpdateChangesLabel();

                        foreach (ListViewItem item in imageListView.Items)
                        {
                            if (item.Tag is TextureInfo info && info.name == filename)
                            {
                                imageListView.LargeImageList.Images.Add(TextureLoader.ScaledImage(image));
                                item.ImageIndex = imageListView.LargeImageList.Images.Count - 1;
                                item.Font       = new Font(item.Font, FontStyle.Bold);
                            }
                        }
                    }
                }
            }
        }