Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- using System.Diagnostics;
- namespace PicManager
- {
- public partial class Form1 : Form
- {
- List<string> images = new List<string>();
- int currentPicNum = 0;
- string chosenDirectory = string.Empty;
- string chosenDirectoryFixed = string.Empty;
- string outputDirectory = string.Empty;
- string outputDirectoryFixed = string.Empty;
- public Form1()
- {
- InitializeComponent();
- this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
- pictureBox1.Visible = false;
- this.KeyPreview = true;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- LinkLabel.Link link = new LinkLabel.Link();
- link.LinkData = "http://www.steamcommunity.com/id/skizerzz";
- skizerzLink.Links.Add(link);
- }
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.R)
- Relocate();
- else if (e.KeyCode == Keys.D)
- NextPic();
- else if (e.KeyCode == Keys.A)
- PreviousPic();
- }
- private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
- {
- }
- private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
- {
- }
- private void button3_Click(object sender, EventArgs e)
- {
- ChooseInputFolder();
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- }
- private void folderBrowserDialog1_HelpRequest_1(object sender, EventArgs e)
- {
- }
- private void button4_Click(object sender, EventArgs e)
- {
- ChooseOutputFolder();
- }
- public void ChooseInputFolder()
- {
- if(folderBrowserDialog1.ShowDialog() == DialogResult.OK)
- {
- if (folderBrowserDialog1.SelectedPath == outputDirectory)
- {
- MessageBox.Show("Input directory cannot be the same as Output directory");
- return;
- }
- textBox1.Text = folderBrowserDialog1.SelectedPath;
- chosenDirectory = folderBrowserDialog1.SelectedPath;
- chosenDirectoryFixed = chosenDirectory.Replace("\\", "/");
- DirectoryInfo dirInfo = new DirectoryInfo(chosenDirectory);
- System.IO.FileInfo[] fileNames = dirInfo.GetFiles();
- images.Clear();
- foreach(FileInfo fi in fileNames)
- {
- if (fi.Extension == ".jpg" || fi.Extension == ".png" || fi.Extension == ".gif")
- {
- images.Add(fi.Name);
- }
- }
- SetFirstPic();
- Debug.WriteLine(images.Count());
- }
- }
- public void ChooseOutputFolder()
- {
- if(folderBrowserDialog2.ShowDialog() == DialogResult.OK)
- {
- if(folderBrowserDialog2.SelectedPath == chosenDirectory)
- {
- MessageBox.Show("Output directory cannot be the same as Input directory");
- return;
- }
- textBox2.Text = folderBrowserDialog2.SelectedPath;
- outputDirectory = folderBrowserDialog2.SelectedPath;
- outputDirectoryFixed = outputDirectory.Replace("\\", "/");
- }
- }
- public void SetFirstPic()
- {
- currentPicNum = 0;
- if (images.Count > 0)
- {
- pictureBox1.ImageLocation = "" + chosenDirectory + "\\" + images[0];
- currentPicLabel.Text = "" + (currentPicNum + 1) + "/" + images.Count;
- pictureBox1.Visible = true;
- }
- else
- {
- pictureBox1.Visible = false;
- currentPicLabel.Text = "0/0";
- }
- pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
- pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
- }
- public void NextPic()
- {
- if (images.Count == 0)
- {
- return;
- }
- currentPicNum += 1;
- if(currentPicNum < images.Count)
- {
- pictureBox1.ImageLocation = "" + chosenDirectory + "\\" + images[currentPicNum];
- currentPicLabel.Text = "" + (currentPicNum + 1) + "/" + images.Count;
- }
- else
- {
- currentPicNum -= 1;
- }
- Debug.Write(images.Count);
- Debug.Write(" <-- images.Count ---- currentPicNum --> ");
- Debug.WriteLine(currentPicNum);
- }
- public void PreviousPic()
- {
- if (images.Count == 0)
- return;
- currentPicNum -= 1;
- if (currentPicNum > -1)
- {
- pictureBox1.ImageLocation = "" + chosenDirectory + "\\" + images[currentPicNum];
- currentPicLabel.Text = "" + (currentPicNum + 1) + "/" + images.Count;
- }
- else
- {
- currentPicNum += 1;
- }
- Debug.Write(images.Count);
- Debug.Write(" <-- images.Count ---- currentPicNum --> ");
- Debug.WriteLine(currentPicNum);
- }
- public void Relocate()
- {
- if (images.Count < 1)
- return;
- if (outputDirectoryFixed != string.Empty)
- {
- File.Move("" + chosenDirectoryFixed + "/" + images[currentPicNum], "" + outputDirectoryFixed + "/" + images[currentPicNum]);
- images.Remove(images[currentPicNum]);
- Debug.Write(images.Count);
- Debug.Write(" <-- images.Count ---- currentPicNum --> ");
- Debug.WriteLine(currentPicNum);
- if(currentPicNum + 1 <= images.Count)
- {
- //NextPic();
- //Debug.WriteLine("Running NextPic()");
- pictureBox1.ImageLocation = "" + chosenDirectory + "\\" + images[currentPicNum];
- currentPicLabel.Text = "" + (currentPicNum + 1) + "/" + images.Count;
- }
- else if (images.Count > 0)
- {
- PreviousPic();
- Debug.WriteLine("Running PreviousPic()");
- }
- else
- {
- pictureBox1.Visible = false;
- currentPicLabel.Text = "0/0";
- }
- }
- else
- {
- MessageBox.Show("Please choose an output folder");
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- NextPic();
- }
- private void relocateButton_Click(object sender, EventArgs e)
- {
- Relocate();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- PreviousPic();
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void skizerzLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- Process.Start(e.Link.LinkData as string);
- }
- private void helpButton_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Instructions:" + Environment.NewLine + "1. Select the folder you want to sort through as Input" +
- Environment.NewLine + "2. Select the folder you want to relocate files to as Output" +
- Environment.NewLine + "3. Use Relocate when an image you want moved to the Output folder is selected" +
- Environment.NewLine + Environment.NewLine + "Controls:" +
- Environment.NewLine + "- Use A and D to browse pictures" +
- Environment.NewLine + "- Use R to relocate");
- }
- private void currentPicLabel_Click(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement