Example #1
0
        public static IMImage FromJObject(JObject obj, string basePath)
        {
            var x = basePath.Split('\\').ToList();

            x.Remove(x.Last());
            basePath = Helper.StrArrayToStr(x, "\\");
            var res = new IMImage()
            {
                Path       = basePath + "\\" + obj["path"].ToString().Replace("\\", "/").Replace("./", "").Replace("/", "\\"),
                Alias      = obj["alias"].ToString(),
                Tags       = (from o in obj["tags"].Values() select o.ToString()).ToList(),
                Characters = (from o in obj["characters"].Values() select o.ToString()).ToList(),
                Width      = Convert.ToInt32(obj["width"].ToString()),
                Height     = Convert.ToInt32(obj["height"].ToString()),
            };

            return(res);
        }
Example #2
0
        private void LVImages_SelectedIndexChanged(object sender, EventArgs e)
        {
            var s = (sender as ListView).SelectedItems;

            try
            {
                string key = "";
                foreach (var v in s)
                {
                    //i = (sender as ListView).Items.IndexOf(v as ListViewItem);
                    key = (v as ListViewItem).Text;
                }
                Console.WriteLine("##### \"" + key + "\"");
                SelectedImage = Images[key];
                Text          = BuildTitle();
                if (tabControl2.SelectedIndex == 0)
                {
                    Previewer.Load(Helper.PathToUrl(SelectedImage.Path));
                }
                editImagePictureBox.Image  = Image.FromFile(SelectedImage.Path);
                editImagePathTextBox.Text  = SelectedImage.Path;
                editImageAliasTextBox.Text = SelectedImage.Alias;

                UpdateEditLists();

                if (SelectedImage != null)
                {
                    foreach (var i in editImageTagsCheckedListBox.Items)
                    {
                        editImageTagsCheckedListBox.SetItemChecked(editImageTagsCheckedListBox.Items.IndexOf(i), SelectedImage.Tags.Contains(i.ToString()));
                    }
                    foreach (var i in editImageCharactersCheckedListBox.Items)
                    {
                        editImageCharactersCheckedListBox.SetItemChecked(editImageCharactersCheckedListBox.Items.IndexOf(i), SelectedImage.Characters.Contains(i.ToString()));
                    }
                }
            } catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\n\n" + ex.StackTrace);
            }
        }
Example #3
0
        private void ImportImagesSeperately()
        {
            var counter = 1;
            var max     = ImportingFileNames.Count;

            if (InvokeRequired)
            {
                Invoke(new MethodInvoker(delegate()
                {
                    statusProgressBar.Minimum = 1;
                    statusProgressBar.Value   = 1;
                    statusProgressBar.Maximum = max;
                }));
            }
            foreach (var f in ImportingFileNames)
            {
                var projectPath = ProjectDataPath + "\\" + f.Split('\\').Last();
                if (!File.Exists(projectPath))
                {
                    File.Copy(f, projectPath);
                }
                else
                {
                    /*var msres = MessageBox.Show("The File " + f.Split('\\').Last() + " already exists in " + ProjectDataPath + ". \nDo you wish to replace it", "File already exists", MessageBoxButtons.YesNo);
                     * switch(msres)
                     * {
                     *  case DialogResult.Yes:
                     *      File.Replace(f, ProjectDataPath + "\\" + f.Split('\\').Last(), ProjectDataPath + "\\##backup" + f.Split('\\').Last());
                     *      break;
                     *  case DialogResult.No:
                     *      break;
                     * }*/
                }
                var img     = Image.FromFile(projectPath);
                var imimage = new IMImage()
                {
                    Path   = projectPath,
                    Width  = img.Width,
                    Height = img.Height,
                };

                try
                {
                    Images.Add(imimage.Path.Split('\\').Last(), imimage);
                    (Project["Images"] as JArray).Add(imimage.ToJObject(ProjectDataPath));
                } catch (Exception ex)
                {
                    Console.WriteLine(ex + "\n\n" + ex.StackTrace);
                }
                if (InvokeRequired)
                {
                    Invoke(new MethodInvoker(delegate()
                    {
                        statusProgressBar.Value = counter;
                        statusLabel.Text        = "Importing (" + counter + " / " + max + ") [" + f + "]";
                    }));
                }
                counter++;
            }
            File.WriteAllText(ProjectPath, Project.ToString());
            new Thread(ReopenThis).Start();
        }
Example #4
0
        private void LoadProject()
        {
            var JImages                = Project["Images"] as JArray;
            var JTags                  = (Project["Tags"]).Children();
            var JCharacters            = (Project["Characters"]).Children();
            var max                    = JImages.Count();
            var LVImagesCollection     = new List <ListViewItem>();
            var LVTagsCollection       = new List <ListViewItem>();
            var LVCharactersCollection = new List <ListViewItem>();
            var LVSmallImageList       = new ImageList()
            {
                ImageSize = new Size(32, 32),
            };
            var LVLargeImageList = new ImageList()
            {
                ImageSize = new Size(80, 80)
            };

            if (InvokeRequired)
            {
                Invoke(new MethodInvoker(delegate
                {
                    statusLabel.Text          = "Loading Images: (0/" + max + ")";
                    statusProgressBar.Maximum = max;
                    statusProgressBar.Minimum = 1;
                }));
            }
            var somecounter = 1;

            foreach (var v in JImages)
            {
                var newImg = IMImage.FromJObject(v as JObject, ProjectDataPath);
                Images.Add(newImg.Path.Split('\\').Last(), newImg);
                LVImagesCollection.Add(Images.Last().Value.ToListViewItem());
                var   p         = Images.Last().Value.Path.Split('\\').Last();
                var   thumbpath = ProjectDataPath + "\\thumb\\" + Helper.StrArrayToStr((from x in p.Split('.').ToList() where x != p.Split('.').Last() select x).ToList(), ".") + ".png";
                Image img;
                if (!File.Exists(thumbpath))
                {
                    img = Image.FromFile(Images.Last().Value.Path);
                    double factor = (double)img.Width / (double)img.Height;
                    img = img.GetThumbnailImage((int)Math.Truncate(Convert.ToDecimal(100 * factor)), 100, () => false, IntPtr.Zero);
                    img.Save(thumbpath);
                }
                else
                {
                    img = Image.FromFile(thumbpath);
                }
                LVSmallImageList.Images.Add(p, img);
                LVLargeImageList.Images.Add(p, img);
                if (InvokeRequired)
                {
                    Invoke(new MethodInvoker(delegate
                    {
                        statusLabel.Text        = "Loading Images: (" + somecounter + "/" + max + ")";
                        statusProgressBar.Value = somecounter;
                    }));
                }

                somecounter++;
            }
            if (JTags.Count() > 0)
            {
                max = JTags.Count();
                if (InvokeRequired)
                {
                    Invoke(new MethodInvoker(delegate()
                    {
                        statusProgressBar.Maximum = max;
                    }));
                }
                var counter = 1;
                foreach (var v in JTags)
                {
                    var x       = JObject.Parse("{" + v.ToString() + "}");
                    var current = counter;
                    if (InvokeRequired)
                    {
                        Invoke(new MethodInvoker(delegate
                        {
                            statusLabel.Text        = "Loading Tags: (" + current + "/" + max + ")";
                            statusProgressBar.Value = current;
                        }));
                    }
                    counter++;
                    Tags.Add((v as JProperty).Name, IMTag.FromJObject(x, (v as JProperty).Name));
                    LVTagsCollection.Add(Tags.Last().Value.ToListViewItem());
                }
            }
            if (JCharacters.Count() > 0)
            {
                var counter = 1;
                max = JCharacters.Count();
                if (InvokeRequired)
                {
                    Invoke(new MethodInvoker(delegate()
                    {
                        statusProgressBar.Maximum = max;
                    }));
                }
                foreach (var v in JCharacters)
                {
                    var x       = JObject.Parse("{" + v.ToString() + "}");
                    var current = counter;
                    if (InvokeRequired)
                    {
                        Invoke(new MethodInvoker(delegate
                        {
                            statusLabel.Text        = "Loading Characters: (" + current + "/" + max + ")";
                            statusProgressBar.Value = current;
                        }));
                    }
                    counter++;
                    Characters.Add((v as JProperty).Name, IMCharacter.FromJObject(x, (v as JProperty).Name));
                    LVCharactersCollection.Add(Characters.Last().Value.ToListViewItem());
                }
            }
            if (InvokeRequired)
            {
                Invoke(new MethodInvoker(delegate
                {
                    statusLabel.Text = "Building Lists ...";

                    LVImages.SmallImageList = LVSmallImageList;
                    LVImages.LargeImageList = LVLargeImageList;
                    var counter             = 1;
                    var buildmax            = LVImagesCollection.Count();
                    foreach (var v in LVImagesCollection)
                    {
                        LVImages.Items.Add(v);
                        statusLabel.Text = "Building Images List (" + counter + " / " + buildmax + ")";
                        counter++;
                    }
                    counter  = 1;
                    buildmax = LVTagsCollection.Count();
                    foreach (var v in LVTagsCollection)
                    {
                        LVTags.Items.Add(v);
                        statusLabel.Text = "Building Tags List (" + counter + " / " + buildmax + ")";
                        counter++;
                    }
                    counter  = 1;
                    buildmax = LVCharactersCollection.Count();
                    foreach (var v in LVCharactersCollection)
                    {
                        LVCharacters.Items.Add(v);
                        statusLabel.Text = "Building Characters List (" + counter + " / " + buildmax + ")";
                        counter++;
                    }
                    UpdateEditLists();
                    statusLabel.Text = "Done Loading";
                }));
            }
        }