Added functionality for JPG images

master
Aaron 3 years ago
parent a99eda4162
commit 8367d7960b

86
Form1.Designer.cs generated

@ -41,7 +41,7 @@ namespace photo_sorter
this.btn_next = new System.Windows.Forms.Button();
this.btn_prev = new System.Windows.Forms.Button();
this.btn_sort = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.img_preview = new System.Windows.Forms.PictureBox();
this.gbox_info = new System.Windows.Forms.GroupBox();
this.btn_open_dest_dir = new System.Windows.Forms.Button();
this.tbox_source_dir = new System.Windows.Forms.TextBox();
@ -60,9 +60,12 @@ namespace photo_sorter
this.split_container_main = new System.Windows.Forms.SplitContainer();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.btn_open_src_dir = new System.Windows.Forms.Button();
this.selectDestinationDirectoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.btn_reload_src = new System.Windows.Forms.Button();
this.lbl_counter = new System.Windows.Forms.Label();
this.menuStrip1.SuspendLayout();
this.gbox_preview.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.img_preview)).BeginInit();
this.gbox_info.SuspendLayout();
this.gbox_copybool.SuspendLayout();
this.statusStrip1.SuspendLayout();
@ -87,6 +90,7 @@ namespace photo_sorter
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.openDirectoryToolStripMenuItem,
this.selectDestinationDirectoryToolStripMenuItem,
this.quitApplicationToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
@ -95,14 +99,14 @@ namespace photo_sorter
// openDirectoryToolStripMenuItem
//
this.openDirectoryToolStripMenuItem.Name = "openDirectoryToolStripMenuItem";
this.openDirectoryToolStripMenuItem.Size = new System.Drawing.Size(193, 22);
this.openDirectoryToolStripMenuItem.Size = new System.Drawing.Size(219, 22);
this.openDirectoryToolStripMenuItem.Text = "&Open Source Directory";
this.openDirectoryToolStripMenuItem.Click += new System.EventHandler(this.openDirectoryToolStripMenuItem_Click);
//
// quitApplicationToolStripMenuItem
//
this.quitApplicationToolStripMenuItem.Name = "quitApplicationToolStripMenuItem";
this.quitApplicationToolStripMenuItem.Size = new System.Drawing.Size(193, 22);
this.quitApplicationToolStripMenuItem.Size = new System.Drawing.Size(219, 22);
this.quitApplicationToolStripMenuItem.Text = "&Quit Application";
this.quitApplicationToolStripMenuItem.Click += new System.EventHandler(this.quitApplicationToolStripMenuItem_Click);
//
@ -126,11 +130,13 @@ namespace photo_sorter
this.gbox_preview.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.gbox_preview.Controls.Add(this.lbl_counter);
this.gbox_preview.Controls.Add(this.lbl_current_fname);
this.gbox_preview.Controls.Add(this.btn_next);
this.gbox_preview.Controls.Add(this.btn_prev);
this.gbox_preview.Controls.Add(this.btn_sort);
this.gbox_preview.Controls.Add(this.pictureBox1);
this.gbox_preview.Controls.Add(this.img_preview);
this.gbox_preview.Enabled = false;
this.gbox_preview.Location = new System.Drawing.Point(3, 3);
this.gbox_preview.Name = "gbox_preview";
this.gbox_preview.Size = new System.Drawing.Size(708, 533);
@ -143,9 +149,9 @@ namespace photo_sorter
this.lbl_current_fname.AutoSize = true;
this.lbl_current_fname.Location = new System.Drawing.Point(9, 18);
this.lbl_current_fname.Name = "lbl_current_fname";
this.lbl_current_fname.Size = new System.Drawing.Size(94, 13);
this.lbl_current_fname.Size = new System.Drawing.Size(214, 13);
this.lbl_current_fname.TabIndex = 7;
this.lbl_current_fname.Text = "hank_ketchum.file";
this.lbl_current_fname.Text = "hank_ketchum.file - Select Source to begin!";
//
// btn_next
//
@ -156,16 +162,18 @@ namespace photo_sorter
this.btn_next.TabIndex = 8;
this.btn_next.Text = "&Next >>";
this.btn_next.UseVisualStyleBackColor = true;
this.btn_next.Click += new System.EventHandler(this.btn_next_Click);
//
// btn_prev
//
this.btn_prev.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.btn_prev.Location = new System.Drawing.Point(235, 12);
this.btn_prev.Location = new System.Drawing.Point(235, 13);
this.btn_prev.Name = "btn_prev";
this.btn_prev.Size = new System.Drawing.Size(75, 23);
this.btn_prev.TabIndex = 6;
this.btn_prev.Text = "<< &Previous";
this.btn_prev.UseVisualStyleBackColor = true;
this.btn_prev.Click += new System.EventHandler(this.btn_prev_Click);
//
// btn_sort
//
@ -176,26 +184,28 @@ namespace photo_sorter
this.btn_sort.TabIndex = 7;
this.btn_sort.Text = "&Sort";
this.btn_sort.UseVisualStyleBackColor = true;
this.btn_sort.Click += new System.EventHandler(this.btn_sort_Click);
//
// pictureBox1
// img_preview
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.img_preview.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.InitialImage = null;
this.pictureBox1.Location = new System.Drawing.Point(6, 42);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(696, 485);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.img_preview.Image = ((System.Drawing.Image)(resources.GetObject("img_preview.Image")));
this.img_preview.InitialImage = null;
this.img_preview.Location = new System.Drawing.Point(6, 42);
this.img_preview.Name = "img_preview";
this.img_preview.Size = new System.Drawing.Size(696, 485);
this.img_preview.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.img_preview.TabIndex = 0;
this.img_preview.TabStop = false;
//
// gbox_info
//
this.gbox_info.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.gbox_info.Controls.Add(this.btn_reload_src);
this.gbox_info.Controls.Add(this.btn_open_src_dir);
this.gbox_info.Controls.Add(this.btn_open_dest_dir);
this.gbox_info.Controls.Add(this.tbox_source_dir);
@ -252,6 +262,7 @@ namespace photo_sorter
| System.Windows.Forms.AnchorStyles.Right)));
this.tbox_dest_dir.Location = new System.Drawing.Point(6, 35);
this.tbox_dest_dir.Name = "tbox_dest_dir";
this.tbox_dest_dir.ReadOnly = true;
this.tbox_dest_dir.Size = new System.Drawing.Size(314, 20);
this.tbox_dest_dir.TabIndex = 0;
//
@ -373,7 +384,7 @@ namespace photo_sorter
//
// btn_open_src_dir
//
this.btn_open_src_dir.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btn_open_src_dir.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_open_src_dir.Location = new System.Drawing.Point(322, 505);
this.btn_open_src_dir.Name = "btn_open_src_dir";
this.btn_open_src_dir.Size = new System.Drawing.Size(26, 23);
@ -382,6 +393,36 @@ namespace photo_sorter
this.btn_open_src_dir.UseVisualStyleBackColor = true;
this.btn_open_src_dir.Click += new System.EventHandler(this.btn_open_src_dir_Click);
//
// selectDestinationDirectoryToolStripMenuItem
//
this.selectDestinationDirectoryToolStripMenuItem.Name = "selectDestinationDirectoryToolStripMenuItem";
this.selectDestinationDirectoryToolStripMenuItem.Size = new System.Drawing.Size(219, 22);
this.selectDestinationDirectoryToolStripMenuItem.Text = "Select &Destination Directory";
this.selectDestinationDirectoryToolStripMenuItem.Click += new System.EventHandler(this.selectDestinationDirectoryToolStripMenuItem_Click);
//
// btn_reload_src
//
this.btn_reload_src.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_reload_src.Enabled = false;
this.btn_reload_src.Location = new System.Drawing.Point(273, 481);
this.btn_reload_src.Name = "btn_reload_src";
this.btn_reload_src.Size = new System.Drawing.Size(75, 23);
this.btn_reload_src.TabIndex = 902;
this.btn_reload_src.Text = "&Reload";
this.btn_reload_src.UseVisualStyleBackColor = true;
this.btn_reload_src.Click += new System.EventHandler(this.btn_reload_src_Click);
//
// lbl_counter
//
this.lbl_counter.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lbl_counter.Location = new System.Drawing.Point(607, 18);
this.lbl_counter.Name = "lbl_counter";
this.lbl_counter.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.lbl_counter.Size = new System.Drawing.Size(95, 23);
this.lbl_counter.TabIndex = 9;
this.lbl_counter.Text = "1 of 1";
this.lbl_counter.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// form_main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -398,7 +439,7 @@ namespace photo_sorter
this.menuStrip1.PerformLayout();
this.gbox_preview.ResumeLayout(false);
this.gbox_preview.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.img_preview)).EndInit();
this.gbox_info.ResumeLayout(false);
this.gbox_info.PerformLayout();
this.gbox_copybool.ResumeLayout(false);
@ -423,7 +464,7 @@ namespace photo_sorter
private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem;
private System.Windows.Forms.GroupBox gbox_preview;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox img_preview;
private System.Windows.Forms.Button btn_next;
private System.Windows.Forms.Button btn_prev;
private System.Windows.Forms.Button btn_sort;
@ -446,6 +487,9 @@ namespace photo_sorter
private System.Windows.Forms.Button btn_open_dest_dir;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.Button btn_open_src_dir;
private System.Windows.Forms.ToolStripMenuItem selectDestinationDirectoryToolStripMenuItem;
private System.Windows.Forms.Button btn_reload_src;
private System.Windows.Forms.Label lbl_counter;
}
}

@ -7,9 +7,20 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace photo_sorter
{
/*public static class Extensions
{
public static T[] RemoveAt<T>(this T[] source, int index)
{
var work = new List<T>(source);
work.RemoveAt(index);
return work.ToArray();
}
}*/
public partial class form_main : Form
{
public form_main()
@ -17,20 +28,151 @@ namespace photo_sorter
InitializeComponent();
}
private void btn_open_dir_Click(object sender, EventArgs e)
static class global
{
public static string dest = "";
public static string src;
public static string[] filenames;
public static int filecount;
public static int position = 0;
}
public void status_msg(string msg, int lvl = 1)
{
string mtype = "UNDEFINED";
switch (lvl)
{
case 1:
mtype = "INFO";
//stat_last_action.ForeColor = new System.Drawing.Color();
stat_last_action.ForeColor = Color.Black;
break;
case 2:
mtype = "WARN";
stat_last_action.ForeColor = Color.Olive;
break;
case 3:
mtype = "ERROR";
System.Media.SystemSounds.Asterisk.Play();
stat_last_action.ForeColor = Color.Red;
break;
case 4:
mtype = "CRITICAL";
System.Media.SystemSounds.Exclamation.Play();
stat_last_action.ForeColor = Color.Red;
break;
}
stat_last_action.Text = mtype + ": " + msg;
}
private void update_counter()
{
lbl_counter.Text = (global.position + 1).ToString() + " of " + global.filecount.ToString();
}
private void reload_source()
{
global.filenames = populate_file_names();
global.filecount = global.filenames.Length;
global.position = 0;
status_msg("Source directory updated, found " + global.filecount.ToString() + " images");
if (global.filecount > 0)
{
gbox_preview.Enabled = true;
lbl_counter.Text = (global.position + 1).ToString() + " of " + global.filecount.ToString();
update_image();
}
else
{
gbox_preview.Enabled = false;
status_msg("Source directory updated, but no images found!",3);
}
}
private void select_source_dir()
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
tbox_dest_dir.Text = folderBrowserDialog1.SelectedPath;
global.src = folderBrowserDialog1.SelectedPath;
tbox_source_dir.Text = global.src;
btn_reload_src.Enabled = true;
reload_source();
}
}
private void select_dest_dir()
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
global.dest = folderBrowserDialog1.SelectedPath;
tbox_dest_dir.Text = global.dest;
status_msg("Destination directory updated");
}
}
private void update_image()
{
string fname;
if (global.filecount == 0)
{
fname = "EMPTY - Select new source";
img_preview.Visible = false;
gbox_preview.Enabled = false;
}
else
{
fname = global.filenames[global.position];
Image img;
using (var bmp = new Bitmap(fname))
{
img = new Bitmap(bmp);
}
img_preview.Image = img;
img_preview.Visible = true;
GC.Collect();
GC.WaitForPendingFinalizers();
}
lbl_current_fname.Text = Path.GetFileName(fname);
update_counter();
}
public string[] populate_file_names()
{
string[] files = Directory.GetFiles(global.src, "*.jpg");
return files;
}
public void remove_index(int index)
{
for (int i = index; i < global.filenames.Length - 1; i++)
{
global.filenames[i] = global.filenames[i + 1];
}
Array.Resize(ref global.filenames, global.filenames.Length - 1);
global.filecount--;
if (global.position > global.filecount - 1)
{
global.position = global.filecount - 1;
}
}
//
// UI Interactions
//
///////////////////////////////////////////////////////
private void btn_open_dir_Click(object sender, EventArgs e)
{
select_dest_dir();
}
private void openDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
tbox_source_dir.Text = folderBrowserDialog1.SelectedPath;
}
select_source_dir();
}
private void selectDestinationDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
{
select_dest_dir();
}
private void quitApplicationToolStripMenuItem_Click(object sender, EventArgs e)
@ -48,12 +190,141 @@ namespace photo_sorter
private void btn_open_src_dir_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
select_source_dir();
}
private void btn_prev_Click(object sender, EventArgs e)
{
if (global.position > 0)
{
tbox_source_dir.Text = folderBrowserDialog1.SelectedPath;
global.position -= 1;
}
else
{
global.position = global.filecount - 1;
}
update_image();
}
private void btn_next_Click(object sender, EventArgs e)
{
if (global.position < global.filecount - 1)
{
global.position += 1;
}
else
{
global.position = 0;
}
update_image();
}
private void btn_sort_Click(object sender, EventArgs e)
{
string prim_dir = global.dest + '\\' + tbox_sort_primary.Text;
string sec_dir = prim_dir + '\\' + tbox_sort_secondary.Text;
string dpath;
if (global.dest == "")
{
status_msg("Destination directory must be set first!", 3);
//System.Media.SystemSounds.Exclamation.Play();
//MessageBox.Show("Destination directory must be set\nbefore images can be sorted!", "Error: Primary Sort", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (tbox_sort_primary.Text == "")
{
status_msg("Primary sort field required to sort!",3);
//System.Media.SystemSounds.Exclamation.Play();
//MessageBox.Show("Primary sort directory name is required!", "Error: Primary Sort", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (tbox_sort_secondary.Text == "")
{
dpath = prim_dir;
}
else
{
dpath = sec_dir;
if (!Directory.Exists(sec_dir))
{
Directory.CreateDirectory(sec_dir);
status_msg("Created directory '" + sec_dir + "'", 2);
}
}
if (!Directory.Exists(prim_dir))
{
Directory.CreateDirectory(prim_dir);
status_msg("Created directory '" + prim_dir + "'", 2);
}
string src_fname = global.filenames[global.position];
string dst_fname = dpath + "\\" + Path.GetFileName(global.filenames[global.position]);
if (rad_sort_move.Checked)
{
try
{
if (File.Exists(@dst_fname))
{
if (MessageBox.Show("This file already exists in the destination directory. Would you like to overwrite it?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
File.Delete(dst_fname);
status_msg("Deleted " + dst_fname, 2);
}
else
{
status_msg("Move aborted for " + src_fname, 2);
}
}
File.Move(@src_fname, @dst_fname);
//status_msg("Moved " + lbl_current_fname.Text + " to " + dpath);
status_msg("Moved " + global.filenames[global.position] + " to " + dpath);
remove_index(global.position);
update_image();
}
catch (IOException ex)
{
status_msg("Unable to move " + global.filenames[global.position] + " to " + dpath + "!", 4);
MessageBox.Show(ex.ToString(), "Critical: IO Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
try
{
if (File.Exists(@dst_fname))
{
if (MessageBox.Show("This file already exists in the destination directory. Would you like to overwrite it?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
File.Delete(dst_fname);
status_msg("Deleted " + dst_fname, 2);
}
else
{
status_msg("Copy aborted for " + src_fname, 2);
return;
}
}
File.Copy(@src_fname, @dst_fname);
//status_msg("Copied " + lbl_current_fname.Text + " to " + dpath);
status_msg("Copied " + global.filenames[global.position] + " to " + dpath);
remove_index(global.position);
update_image();
}
catch (IOException ex)
{
status_msg("Unable to copy " + global.filenames[global.position] + " to " + dpath + "!", 4);
MessageBox.Show(ex.ToString(), "Critical: IO Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void btn_reload_src_Click(object sender, EventArgs e)
{
reload_source();
}
/*private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Are you sure you want to quit the Photo Sorter application?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)

@ -121,7 +121,7 @@
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<data name="img_preview.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAANcAAACQCAYAAACbIP5hAAABgWlDQ1BJQ0MgcHJvZmlsZQAAKM+VkU8o
BFEcxz9maRE52IPkMIflRAnJUUukqG2t8u9gZtYutTO2mZWLo3JVDv5cLA4uzlwdXJVS/pQcnZyIizR+

Binary file not shown.

Binary file not shown.

@ -2,9 +2,9 @@ C:\Users\ajohnson\source\repos\photo_sorter\bin\Debug\photo_sorter.exe.config
C:\Users\ajohnson\source\repos\photo_sorter\bin\Debug\photo_sorter.exe
C:\Users\ajohnson\source\repos\photo_sorter\bin\Debug\photo_sorter.pdb
C:\Users\ajohnson\source\repos\photo_sorter\obj\Debug\photo_sorter.csprojAssemblyReference.cache
C:\Users\ajohnson\source\repos\photo_sorter\obj\Debug\photo_sorter.form_main.resources
C:\Users\ajohnson\source\repos\photo_sorter\obj\Debug\photo_sorter.Properties.Resources.resources
C:\Users\ajohnson\source\repos\photo_sorter\obj\Debug\photo_sorter.csproj.GenerateResource.cache
C:\Users\ajohnson\source\repos\photo_sorter\obj\Debug\photo_sorter.csproj.CoreCompileInputs.cache
C:\Users\ajohnson\source\repos\photo_sorter\obj\Debug\photo_sorter.exe
C:\Users\ajohnson\source\repos\photo_sorter\obj\Debug\photo_sorter.pdb
C:\Users\ajohnson\source\repos\photo_sorter\obj\Debug\photo_sorter.form_main.resources

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save