Advertisement
Skizerzz

PicSort v0.1

Jan 28th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11. using System.Diagnostics;
  12.  
  13. namespace PicManager
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.  
  18.         List<string> images = new List<string>();
  19.         int currentPicNum = 0;
  20.         string chosenDirectory = string.Empty;
  21.         string chosenDirectoryFixed = string.Empty;
  22.  
  23.         string outputDirectory = string.Empty;
  24.         string outputDirectoryFixed = string.Empty;
  25.  
  26.         public Form1()
  27.         {
  28.             InitializeComponent();
  29.             this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
  30.             pictureBox1.Visible = false;
  31.             this.KeyPreview = true;
  32.         }
  33.  
  34.         private void Form1_Load(object sender, EventArgs e)
  35.         {
  36.             LinkLabel.Link link = new LinkLabel.Link();
  37.             link.LinkData = "http://www.steamcommunity.com/id/skizerzz";
  38.             skizerzLink.Links.Add(link);
  39.         }
  40.  
  41.         private void Form1_KeyDown(object sender, KeyEventArgs e)
  42.         {
  43.             if (e.KeyCode == Keys.R)
  44.                 Relocate();
  45.             else if (e.KeyCode == Keys.D)
  46.                 NextPic();
  47.             else if (e.KeyCode == Keys.A)
  48.                 PreviousPic();
  49.         }
  50.  
  51.  
  52.         private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
  53.         {
  54.  
  55.         }
  56.  
  57.         private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
  58.         {
  59.  
  60.         }
  61.  
  62.         private void button3_Click(object sender, EventArgs e)
  63.         {
  64.             ChooseInputFolder();
  65.         }
  66.  
  67.         private void pictureBox1_Click(object sender, EventArgs e)
  68.         {
  69.  
  70.         }
  71.  
  72.         private void folderBrowserDialog1_HelpRequest_1(object sender, EventArgs e)
  73.         {
  74.  
  75.         }
  76.  
  77.         private void button4_Click(object sender, EventArgs e)
  78.         {
  79.             ChooseOutputFolder();
  80.         }
  81.  
  82.         public void ChooseInputFolder()
  83.         {
  84.             if(folderBrowserDialog1.ShowDialog() == DialogResult.OK)
  85.             {
  86.                 if (folderBrowserDialog1.SelectedPath == outputDirectory)
  87.                 {
  88.                     MessageBox.Show("Input directory cannot be the same as Output directory");
  89.                     return;
  90.                 }
  91.  
  92.                 textBox1.Text = folderBrowserDialog1.SelectedPath;
  93.                 chosenDirectory = folderBrowserDialog1.SelectedPath;
  94.                 chosenDirectoryFixed = chosenDirectory.Replace("\\", "/");
  95.                 DirectoryInfo dirInfo = new DirectoryInfo(chosenDirectory);
  96.                 System.IO.FileInfo[] fileNames = dirInfo.GetFiles();
  97.  
  98.                 images.Clear();
  99.                 foreach(FileInfo fi in fileNames)
  100.                 {
  101.                     if (fi.Extension == ".jpg" || fi.Extension == ".png" || fi.Extension == ".gif")
  102.                     {
  103.                         images.Add(fi.Name);
  104.                     }
  105.                 }
  106.                 SetFirstPic();
  107.                 Debug.WriteLine(images.Count());
  108.             }
  109.         }
  110.  
  111.         public void ChooseOutputFolder()
  112.         {
  113.            
  114.             if(folderBrowserDialog2.ShowDialog() == DialogResult.OK)
  115.             {
  116.                 if(folderBrowserDialog2.SelectedPath == chosenDirectory)
  117.                 {
  118.                     MessageBox.Show("Output directory cannot be the same as Input directory");
  119.                     return;
  120.                 }
  121.  
  122.                 textBox2.Text = folderBrowserDialog2.SelectedPath;
  123.                 outputDirectory = folderBrowserDialog2.SelectedPath;
  124.                 outputDirectoryFixed = outputDirectory.Replace("\\", "/");
  125.             }
  126.         }
  127.  
  128.         public void SetFirstPic()
  129.         {
  130.             currentPicNum = 0;
  131.             if (images.Count > 0)
  132.             {
  133.                 pictureBox1.ImageLocation = "" + chosenDirectory + "\\" + images[0];
  134.                 currentPicLabel.Text = "" + (currentPicNum + 1) + "/" + images.Count;
  135.                 pictureBox1.Visible = true;
  136.             }
  137.             else
  138.             {
  139.                 pictureBox1.Visible = false;
  140.                 currentPicLabel.Text = "0/0";
  141.             }
  142.             pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  143.             pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  144.         }
  145.  
  146.         public void NextPic()
  147.         {
  148.             if (images.Count == 0)
  149.             {
  150.                 return;
  151.             }
  152.            
  153.             currentPicNum += 1;
  154.             if(currentPicNum < images.Count)
  155.             {
  156.                 pictureBox1.ImageLocation = "" + chosenDirectory + "\\" + images[currentPicNum];
  157.                 currentPicLabel.Text = "" + (currentPicNum + 1) + "/" + images.Count;
  158.             }
  159.             else
  160.             {
  161.                 currentPicNum -= 1;
  162.             }
  163.  
  164.             Debug.Write(images.Count);
  165.             Debug.Write(" <-- images.Count ---- currentPicNum --> ");
  166.             Debug.WriteLine(currentPicNum);
  167.         }
  168.  
  169.         public void PreviousPic()
  170.         {
  171.             if (images.Count == 0)
  172.                 return;
  173.  
  174.             currentPicNum -= 1;
  175.             if (currentPicNum > -1)
  176.             {
  177.                 pictureBox1.ImageLocation = "" + chosenDirectory + "\\" + images[currentPicNum];
  178.                 currentPicLabel.Text = "" + (currentPicNum + 1) + "/" + images.Count;
  179.             }
  180.             else
  181.             {
  182.                 currentPicNum += 1;
  183.             }
  184.  
  185.             Debug.Write(images.Count);
  186.             Debug.Write(" <-- images.Count ---- currentPicNum --> ");
  187.             Debug.WriteLine(currentPicNum);
  188.         }
  189.  
  190.         public void Relocate()
  191.         {
  192.             if (images.Count < 1)
  193.                 return;
  194.            
  195.             if (outputDirectoryFixed != string.Empty)
  196.             {
  197.                 File.Move("" + chosenDirectoryFixed + "/" + images[currentPicNum], "" + outputDirectoryFixed + "/" + images[currentPicNum]);
  198.                 images.Remove(images[currentPicNum]);
  199.                 Debug.Write(images.Count);
  200.                 Debug.Write(" <-- images.Count ---- currentPicNum --> ");
  201.                 Debug.WriteLine(currentPicNum);
  202.                 if(currentPicNum + 1 <= images.Count)
  203.                 {
  204.                     //NextPic();
  205.                     //Debug.WriteLine("Running NextPic()");
  206.  
  207.                     pictureBox1.ImageLocation = "" + chosenDirectory + "\\" + images[currentPicNum];
  208.                     currentPicLabel.Text = "" + (currentPicNum + 1) + "/" + images.Count;
  209.                 }
  210.                 else if (images.Count > 0)
  211.                 {
  212.                     PreviousPic();
  213.                     Debug.WriteLine("Running PreviousPic()");
  214.                 }
  215.                 else
  216.                 {
  217.                     pictureBox1.Visible = false;
  218.                     currentPicLabel.Text = "0/0";
  219.                 }
  220.             }
  221.             else
  222.             {
  223.                 MessageBox.Show("Please choose an output folder");
  224.             }
  225.         }
  226.  
  227.         private void button2_Click(object sender, EventArgs e)
  228.         {
  229.             NextPic();
  230.         }
  231.  
  232.         private void relocateButton_Click(object sender, EventArgs e)
  233.         {
  234.             Relocate();
  235.         }
  236.  
  237.         private void button1_Click(object sender, EventArgs e)
  238.         {
  239.             PreviousPic();
  240.         }
  241.  
  242.         private void textBox1_TextChanged(object sender, EventArgs e)
  243.         {
  244.  
  245.         }
  246.  
  247.         private void skizerzLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  248.         {
  249.             Process.Start(e.Link.LinkData as string);
  250.         }
  251.  
  252.         private void helpButton_Click(object sender, EventArgs e)
  253.         {
  254.             MessageBox.Show("Instructions:" + Environment.NewLine + "1. Select the folder you want to sort through as Input" +
  255.                             Environment.NewLine + "2. Select the folder you want to relocate files to as Output" +
  256.                             Environment.NewLine + "3. Use Relocate when an image you want moved to the Output folder is selected" +
  257.                             Environment.NewLine + Environment.NewLine + "Controls:" +
  258.                             Environment.NewLine + "- Use A and D to browse pictures" +
  259.                             Environment.NewLine + "- Use R to relocate");
  260.         }
  261.  
  262.         private void currentPicLabel_Click(object sender, EventArgs e)
  263.         {
  264.  
  265.         }
  266.     }
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement