Programmet fungerar nu både via select av enskilda bilder (gt1) och alla jpg/jpeg

This commit is contained in:
2020-07-25 10:24:53 +02:00
parent 6b27788721
commit f06e73c5f1
2 changed files with 202 additions and 111 deletions

View File

@ -7,19 +7,19 @@ namespace PictureHandling
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.Button btnFileDialog;
private System.Windows.Forms.Label lblPath;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label HPath;
private System.Windows.Forms.Label lblFileName;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label HFilnamn;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.ListBox lstPicFiles;
private System.Windows.Forms.Label lblCreated;
private System.Windows.Forms.Label HSkapad;
private System.Windows.Forms.Button btnReOrganize;
/// <summary>
/// Required designer variable.
/// </summary>
//private System.ComponentModel.Container components = null;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label HNyRotKatalog;
private System.Windows.Forms.TextBox txtRootDir;
private bool Deleting = false;
@ -49,25 +49,28 @@ namespace PictureHandling
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.btnFileDialog = new System.Windows.Forms.Button();
this.lblPath = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.HPath = new System.Windows.Forms.Label();
this.lblFileName = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.HFilnamn = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.lstPicFiles = new System.Windows.Forms.ListBox();
this.lblCreated = new System.Windows.Forms.Label();
this.HSkapad = new System.Windows.Forms.Label();
this.btnReOrganize = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.HNyRotKatalog = new System.Windows.Forms.Label();
this.txtRootDir = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.HGrundpath = new System.Windows.Forms.Label();
this.lblGroundPath = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.HSlutpath = new System.Windows.Forms.Label();
this.lblFinalPath = new System.Windows.Forms.Label();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.lblCreated = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// btnFileDialog
//
this.btnFileDialog.Location = new System.Drawing.Point(16, 56);
this.btnFileDialog.Location = new System.Drawing.Point(35, 92);
this.btnFileDialog.Name = "btnFileDialog";
this.btnFileDialog.Size = new System.Drawing.Size(75, 23);
this.btnFileDialog.TabIndex = 0;
@ -76,46 +79,49 @@ namespace PictureHandling
//
// lblPath
//
this.lblPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblPath.Location = new System.Drawing.Point(167, 16);
this.lblPath.BackColor = System.Drawing.Color.Transparent;
this.lblPath.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblPath.Location = new System.Drawing.Point(75, 16);
this.lblPath.Name = "lblPath";
this.lblPath.Size = new System.Drawing.Size(521, 17);
this.lblPath.Size = new System.Drawing.Size(279, 16);
this.lblPath.TabIndex = 1;
//
// label2
// HPath
//
this.label2.Location = new System.Drawing.Point(104, 16);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 17);
this.label2.TabIndex = 2;
this.label2.Text = "Path";
this.HPath.Dock = System.Windows.Forms.DockStyle.Fill;
this.HPath.Location = new System.Drawing.Point(3, 16);
this.HPath.Name = "HPath";
this.HPath.Size = new System.Drawing.Size(66, 16);
this.HPath.TabIndex = 2;
this.HPath.Text = "Path";
//
// lblFileName
//
this.lblFileName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblFileName.Location = new System.Drawing.Point(167, 33);
this.lblFileName.BackColor = System.Drawing.Color.Transparent;
this.tableLayoutPanel1.SetColumnSpan(this.lblFileName, 3);
this.lblFileName.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblFileName.Location = new System.Drawing.Point(75, 0);
this.lblFileName.Name = "lblFileName";
this.lblFileName.Size = new System.Drawing.Size(210, 15);
this.lblFileName.Size = new System.Drawing.Size(590, 16);
this.lblFileName.TabIndex = 3;
//
// label1
// HFilnamn
//
this.label1.Location = new System.Drawing.Point(104, 33);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 15);
this.label1.TabIndex = 4;
this.label1.Text = "Filnamn";
this.HFilnamn.Dock = System.Windows.Forms.DockStyle.Fill;
this.HFilnamn.Location = new System.Drawing.Point(3, 0);
this.HFilnamn.Name = "HFilnamn";
this.HFilnamn.Size = new System.Drawing.Size(66, 16);
this.HFilnamn.TabIndex = 4;
this.HFilnamn.Text = "Filnamn";
//
// pictureBox1
//
this.pictureBox1.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.Location = new System.Drawing.Point(176, 88);
this.pictureBox1.Location = new System.Drawing.Point(179, 90);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(512, 480);
this.pictureBox1.Size = new System.Drawing.Size(524, 509);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 5;
this.pictureBox1.TabStop = false;
@ -123,105 +129,135 @@ namespace PictureHandling
// lstPicFiles
//
this.lstPicFiles.FormattingEnabled = true;
this.lstPicFiles.Location = new System.Drawing.Point(16, 88);
this.lstPicFiles.Location = new System.Drawing.Point(35, 124);
this.lstPicFiles.Name = "lstPicFiles";
this.lstPicFiles.Size = new System.Drawing.Size(128, 394);
this.lstPicFiles.TabIndex = 6;
this.lstPicFiles.SelectedIndexChanged += new System.EventHandler(this.lstPicFiles_SelectedIndexChanged);
//
// lblCreated
// HSkapad
//
this.lblCreated.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lblCreated.Location = new System.Drawing.Point(355, 30);
this.lblCreated.Name = "lblCreated";
this.lblCreated.Size = new System.Drawing.Size(333, 18);
this.lblCreated.TabIndex = 7;
this.lblCreated.Text = "Skapad: ";
this.HSkapad.Dock = System.Windows.Forms.DockStyle.Fill;
this.HSkapad.Location = new System.Drawing.Point(360, 16);
this.HSkapad.Name = "HSkapad";
this.HSkapad.Size = new System.Drawing.Size(50, 16);
this.HSkapad.TabIndex = 7;
this.HSkapad.Text = "Skapad: ";
//
// btnReOrganize
//
this.btnReOrganize.Enabled = false;
this.btnReOrganize.Location = new System.Drawing.Point(16, 496);
this.btnReOrganize.Location = new System.Drawing.Point(35, 532);
this.btnReOrganize.Name = "btnReOrganize";
this.btnReOrganize.Size = new System.Drawing.Size(136, 23);
this.btnReOrganize.TabIndex = 8;
this.btnReOrganize.Text = "Reorganisera filer";
this.btnReOrganize.Click += new System.EventHandler(this.btnReOrganize_Click);
//
// label3
// HNyRotKatalog
//
this.label3.Location = new System.Drawing.Point(16, 528);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(128, 16);
this.label3.TabIndex = 9;
this.label3.Text = "Ny RotKatalog";
this.HNyRotKatalog.Location = new System.Drawing.Point(35, 564);
this.HNyRotKatalog.Name = "HNyRotKatalog";
this.HNyRotKatalog.Size = new System.Drawing.Size(128, 16);
this.HNyRotKatalog.TabIndex = 9;
this.HNyRotKatalog.Text = "Ny RotKatalog";
//
// txtRootDir
//
this.txtRootDir.Location = new System.Drawing.Point(16, 544);
this.txtRootDir.Location = new System.Drawing.Point(35, 580);
this.txtRootDir.Name = "txtRootDir";
this.txtRootDir.Size = new System.Drawing.Size(136, 20);
this.txtRootDir.TabIndex = 10;
this.txtRootDir.Text = "\\\\TFOASUS\\OurPictures";
this.txtRootDir.TextChanged += new System.EventHandler(this.txtRootDir_TextChanged);
//
// label4
// HGrundpath
//
this.label4.Location = new System.Drawing.Point(104, 48);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(64, 15);
this.label4.TabIndex = 12;
this.label4.Text = "GrundPath";
this.HGrundpath.Dock = System.Windows.Forms.DockStyle.Fill;
this.HGrundpath.Location = new System.Drawing.Point(3, 32);
this.HGrundpath.Name = "HGrundpath";
this.HGrundpath.Size = new System.Drawing.Size(66, 18);
this.HGrundpath.TabIndex = 12;
this.HGrundpath.Text = "GrundPath";
//
// lblGroundPath
//
this.lblGroundPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblGroundPath.Location = new System.Drawing.Point(166, 48);
this.lblGroundPath.BackColor = System.Drawing.Color.Transparent;
this.lblGroundPath.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblGroundPath.Location = new System.Drawing.Point(75, 32);
this.lblGroundPath.Name = "lblGroundPath";
this.lblGroundPath.Size = new System.Drawing.Size(174, 15);
this.lblGroundPath.Size = new System.Drawing.Size(279, 18);
this.lblGroundPath.TabIndex = 11;
//
// label6
// HSlutpath
//
this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.label6.Location = new System.Drawing.Point(355, 48);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(51, 15);
this.label6.TabIndex = 14;
this.label6.Text = "SlutPath";
this.HSlutpath.Dock = System.Windows.Forms.DockStyle.Fill;
this.HSlutpath.Location = new System.Drawing.Point(360, 32);
this.HSlutpath.Name = "HSlutpath";
this.HSlutpath.Size = new System.Drawing.Size(50, 18);
this.HSlutpath.TabIndex = 14;
this.HSlutpath.Text = "SlutPath";
//
// lblFinalPath
//
this.lblFinalPath.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lblFinalPath.Location = new System.Drawing.Point(412, 48);
this.lblFinalPath.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblFinalPath.Location = new System.Drawing.Point(416, 32);
this.lblFinalPath.Name = "lblFinalPath";
this.lblFinalPath.Size = new System.Drawing.Size(276, 15);
this.lblFinalPath.Size = new System.Drawing.Size(249, 18);
this.lblFinalPath.TabIndex = 13;
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 4;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20.16807F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 79.83193F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 56F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 254F));
this.tableLayoutPanel1.Controls.Add(this.lblCreated, 3, 1);
this.tableLayoutPanel1.Controls.Add(this.HGrundpath, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.HFilnamn, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.HSlutpath, 2, 2);
this.tableLayoutPanel1.Controls.Add(this.HSkapad, 2, 1);
this.tableLayoutPanel1.Controls.Add(this.lblFinalPath, 3, 2);
this.tableLayoutPanel1.Controls.Add(this.lblGroundPath, 1, 2);
this.tableLayoutPanel1.Controls.Add(this.lblPath, 1, 1);
this.tableLayoutPanel1.Controls.Add(this.HPath, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.lblFileName, 1, 0);
this.tableLayoutPanel1.Location = new System.Drawing.Point(35, 12);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 3;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(668, 50);
this.tableLayoutPanel1.TabIndex = 15;
//
// lblCreated
//
this.lblCreated.AutoSize = true;
this.lblCreated.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblCreated.Location = new System.Drawing.Point(416, 16);
this.lblCreated.Name = "lblCreated";
this.lblCreated.Size = new System.Drawing.Size(249, 16);
this.lblCreated.TabIndex = 16;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(704, 590);
this.Controls.Add(this.label6);
this.Controls.Add(this.lblFinalPath);
this.Controls.Add(this.label4);
this.Controls.Add(this.lblGroundPath);
this.ClientSize = new System.Drawing.Size(716, 611);
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.txtRootDir);
this.Controls.Add(this.label3);
this.Controls.Add(this.HNyRotKatalog);
this.Controls.Add(this.btnReOrganize);
this.Controls.Add(this.lblCreated);
this.Controls.Add(this.lstPicFiles);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.lblFileName);
this.Controls.Add(this.label2);
this.Controls.Add(this.lblPath);
this.Controls.Add(this.btnFileDialog);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@ -231,10 +267,12 @@ namespace PictureHandling
#endregion
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label HGrundpath;
private System.Windows.Forms.Label lblGroundPath;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label HSlutpath;
private System.Windows.Forms.Label lblFinalPath;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Label lblCreated;
}
}

View File

@ -20,6 +20,8 @@ namespace PictureHandling
{
public RegistryKey CU { get; set; }
public List<LocalPicture> pictureList = new List<LocalPicture>();
public List<string> DeleteList { get; set; } = new List<string>();
private bool noRegReact = false;
public Form1()
{
InitializeComponent();
@ -47,6 +49,7 @@ namespace PictureHandling
private void txtRootDir_TextChanged(object sender, EventArgs e)
{
if (noRegReact) return;
try
{
RegistryKey IdoIt4u = CU.OpenSubKey(@"SOFTWARE\IdoIt4u", true);
@ -67,7 +70,14 @@ namespace PictureHandling
}
else
{
noRegReact = true;
txtRootDir.Text = txtRootDir.Text.Trim().EndsWith(@"\") ? txtRootDir.Text.Trim() : txtRootDir.Text.Trim() + @"\";
noRegReact = false;
PictureHandling.SetValue(@"RootMap", txtRootDir.Text);
if (pictureList.Count > 0 && txtRootDir.Text != pictureList[0].RootPosition)
{
btnReOrganize.Enabled = true;
}
}
}
catch (Exception ex)
@ -80,6 +90,17 @@ namespace PictureHandling
private void btnReOrganize_Click(object sender, EventArgs e)
{
ReorganizeImages();
pictureList.Clear();
Deleting = true;
lstPicFiles.DataSource = null;
lstPicFiles.Refresh();
pictureBox1.Image = null;
pictureBox1.Refresh();
foreach (var fname in DeleteList)
{
File.Delete(fname);
}
Deleting = false;
}
private void ReorganizeImages()
@ -100,7 +121,7 @@ namespace PictureHandling
}
catch (Exception ex)
{
if (ex.Message == "Det går inte att hitta egenskapen.")
if (ex.HResult == -2147024809)
{
prp = localPic.AktImage.PropertyItems[0];
prp.Id = 306;
@ -114,15 +135,25 @@ namespace PictureHandling
prp.Value = System.Text.ASCIIEncoding.ASCII.GetBytes(localPic.CreatedDate);
localPic.AktImage.SetPropertyItem(prp);
}
if (localPic.RootPosition != txtRootDir.Text)
{
localPic.RootPosition = txtRootDir.Text;
}
DirectoryInfo dis = new DirectoryInfo(localPic.AarManDir);
if (!dis.Exists) dis.Create();
DirectoryInfo diss = new DirectoryInfo(localPic.AarManDayDir);
if (!diss.Exists) diss.Create();
localPic.AktImage.Save(localPic.ImageNewFullpath);
localPic.AktImage.Dispose();
DeleteList.Add(localPic.PictureFullPath);
}
btnReOrganize.Enabled = false;
}
private void lstPicFiles_SelectedIndexChanged(object sender, EventArgs e)
@ -131,9 +162,11 @@ namespace PictureHandling
{
string fName = ((ListBox)sender).SelectedValue.ToString();
var lp = ((ListBox)sender).SelectedItem;
//var lp = lstPicFiles.SelectedValue;
lblFileName.Text = fName;
lblCreated.Text = "Skapad: " + ((LocalPicture)lp).CreatedDate;
lblCreated.Text = ((LocalPicture)lp).CreatedDate;
lblGroundPath.Text = ((LocalPicture)lp).AarManDir;
lblFinalPath.Text = ((LocalPicture)lp).AarManDayDir;
int w = ((LocalPicture)lp).AktImWidth;
@ -141,8 +174,12 @@ namespace PictureHandling
int pw = pictureBox1.Width;
int ph = pictureBox1.Height;
pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
Bitmap to_bm = new Bitmap((Image)((LocalPicture)lp).AktImage.Clone(), w * ph / h, ph);
pictureBox1.Image = to_bm;
using (var bmpTmp = new Bitmap(((LocalPicture)lp).PictureFullPath))
{
pictureBox1.Image = new Bitmap(bmpTmp, w * ph / h,ph);
}
}
}
@ -159,7 +196,6 @@ namespace PictureHandling
}
}
}
//actPic.Dispose();
return sPropDatTaken;
}
@ -170,8 +206,20 @@ namespace PictureHandling
openFileDialog1.Filter = "Picture files (*.jpg)|*.jpg;*.jpeg|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
openFileDialog1.Multiselect = true;
openFileDialog1.ShowDialog();
openFileDialog1.Multiselect = false;
var fnames = openFileDialog1.FileNames;
if (fnames.Length > 1)
{
var outPut = new List<FileInfo>();
foreach (var fname in fnames)
{
outPut.Add(new FileInfo(fname));
}
listLocalFiles(outPut);
}
else
{
string fName = openFileDialog1.FileName;
if (fName.Trim() != "")
{
@ -191,13 +239,17 @@ namespace PictureHandling
}
}
}
private void listLocalFiles()
private void listLocalFiles(List<FileInfo> files = null)
{
if (files == null)
{
DirectoryInfo di = new DirectoryInfo(lblPath.Text);
var files = new List<FileInfo>();
files = new List<FileInfo>();
files.AddRange(di.GetFiles("*.jpg"));
files.AddRange(di.GetFiles("*.jpeg"));
}
//
Deleting = true;
lstPicFiles.DataSource = null;
@ -206,16 +258,17 @@ namespace PictureHandling
lstPicFiles.DisplayMember = "PictureFileName";
lstPicFiles.ValueMember = "PictureFullPath";
Deleting = false;
files.Clear();
files = null;
btnReOrganize.Enabled = true;
}
public List<LocalPicture> listBoxDataSource(List<FileInfo> fileInfos)
{
Cursor.Current = Cursors.WaitCursor;
var outPut = new List<LocalPicture>();
txtRootDir.Text = txtRootDir.Text.Trim().EndsWith(@"\") ? txtRootDir.Text.Trim() : txtRootDir.Text.Trim() + @"\";
foreach (var fi in fileInfos)
{
@ -237,12 +290,13 @@ namespace PictureHandling
outPut.Add(bufPicture);
}
Cursor.Current = Cursors.Default;
return FillupDateGaps(outPut);
}
private List<LocalPicture> FillupDateGaps(List<LocalPicture> inPut)
{
Debug.WriteLine($"FillupDateGaps input has {inPut.Count} files.");
var picReg = new SortedList<string, LocalPicture>();
foreach (var pict in inPut)
{
@ -281,7 +335,6 @@ namespace PictureHandling
outPut.Add(lPic.Value);
}
}
Debug.WriteLine($"FillupDateGaps output has {outPut.Count} files.");
return outPut;
}
}