Add project files.

This commit is contained in:
2021-04-20 23:55:50 +02:00
parent 8cf0bcdb1d
commit fbb246d09b
6 changed files with 505 additions and 0 deletions

194
PictureReposit/Form1.Designer.cs generated Normal file
View File

@ -0,0 +1,194 @@

namespace PictureReposit
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.lstPicFiles = new System.Windows.Forms.ListBox();
this.label1 = new System.Windows.Forms.Label();
this.lblPath = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.lblFileName = new System.Windows.Forms.Label();
this.lblCreated = new System.Windows.Forms.Label();
this.btnFileDialog = new System.Windows.Forms.Button();
this.btnReOrganize = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.txtRootDir = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(183, 72);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(654, 548);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// lstPicFiles
//
this.lstPicFiles.FormattingEnabled = true;
this.lstPicFiles.ItemHeight = 15;
this.lstPicFiles.Location = new System.Drawing.Point(13, 72);
this.lstPicFiles.Name = "lstPicFiles";
this.lstPicFiles.Size = new System.Drawing.Size(164, 424);
this.lstPicFiles.TabIndex = 1;
this.lstPicFiles.SelectedIndexChanged += new System.EventHandler(this.lstPicFiles_SelectedIndexChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(146, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(31, 15);
this.label1.TabIndex = 2;
this.label1.Text = "Path";
//
// lblPath
//
this.lblPath.AutoSize = true;
this.lblPath.Location = new System.Drawing.Point(183, 9);
this.lblPath.Name = "lblPath";
this.lblPath.Size = new System.Drawing.Size(574, 15);
this.lblPath.TabIndex = 3;
this.lblPath.Text = " " +
" " +
" x";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(127, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(50, 15);
this.label2.TabIndex = 4;
this.label2.Text = "Filnamn";
//
// lblFileName
//
this.lblFileName.AutoSize = true;
this.lblFileName.Location = new System.Drawing.Point(183, 24);
this.lblFileName.Name = "lblFileName";
this.lblFileName.Size = new System.Drawing.Size(373, 15);
this.lblFileName.TabIndex = 5;
this.lblFileName.Text = " " +
" x";
//
// lblCreated
//
this.lblCreated.AutoSize = true;
this.lblCreated.Location = new System.Drawing.Point(563, 23);
this.lblCreated.Name = "lblCreated";
this.lblCreated.Size = new System.Drawing.Size(51, 15);
this.lblCreated.TabIndex = 6;
this.lblCreated.Text = "Skapad: ";
//
// btnFileDialog
//
this.btnFileDialog.Location = new System.Drawing.Point(13, 43);
this.btnFileDialog.Name = "btnFileDialog";
this.btnFileDialog.Size = new System.Drawing.Size(75, 23);
this.btnFileDialog.TabIndex = 7;
this.btnFileDialog.Text = "Välj Fil";
this.btnFileDialog.UseVisualStyleBackColor = true;
this.btnFileDialog.Click += new System.EventHandler(this.btnFileDialog_Click);
//
// btnReOrganize
//
this.btnReOrganize.Location = new System.Drawing.Point(13, 503);
this.btnReOrganize.Name = "btnReOrganize";
this.btnReOrganize.Size = new System.Drawing.Size(164, 23);
this.btnReOrganize.TabIndex = 8;
this.btnReOrganize.Text = "Reorganisera Filer";
this.btnReOrganize.UseVisualStyleBackColor = true;
this.btnReOrganize.Click += new System.EventHandler(this.btnReOrganize_Click);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(13, 533);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(83, 15);
this.label3.TabIndex = 9;
this.label3.Text = "Ny RotKatalog";
//
// txtRootDir
//
this.txtRootDir.Location = new System.Drawing.Point(13, 563);
this.txtRootDir.Name = "txtRootDir";
this.txtRootDir.Size = new System.Drawing.Size(164, 23);
this.txtRootDir.TabIndex = 10;
this.txtRootDir.Text = "D:\\Bildlabb\\LabRotCat";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(869, 642);
this.Controls.Add(this.txtRootDir);
this.Controls.Add(this.label3);
this.Controls.Add(this.btnReOrganize);
this.Controls.Add(this.btnFileDialog);
this.Controls.Add(this.lblCreated);
this.Controls.Add(this.lblFileName);
this.Controls.Add(this.label2);
this.Controls.Add(this.lblPath);
this.Controls.Add(this.label1);
this.Controls.Add(this.lstPicFiles);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.ListBox lstPicFiles;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lblPath;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label lblFileName;
private System.Windows.Forms.Label lblCreated;
private System.Windows.Forms.Button btnFileDialog;
private System.Windows.Forms.Button btnReOrganize;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtRootDir;
}
}

194
PictureReposit/Form1.cs Normal file
View File

@ -0,0 +1,194 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PictureReposit
{
public partial class Form1 : Form
{
private bool Deleting = false;
public Form1()
{
InitializeComponent();
RegistryKey PictureHandling = Registry.LocalMachine.OpenSubKey(@"Software\Tfoman\PictureHandling");
if (PictureHandling == null)
{
txtRootDir.Text = @"D:\Bildlabb\LabRotCat";
}
else
{
txtRootDir.Text = (string)PictureHandling.GetValue(@"RootMap");
}
}
private void btnFileDialog_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Välj bild-fil!";
openFileDialog1.InitialDirectory = "C:\\";
openFileDialog1.Filter = "Picture files (*.jpg)|*.jpg|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
openFileDialog1.ShowDialog();
openFileDialog1.Multiselect = false;
string fName = openFileDialog1.FileName;
if (fName.Trim() != "")
{
int fNamePos = fName.LastIndexOf(@"\") + 1;
lblFileName.Text = fName.Substring(fNamePos);
lblPath.Text = fName.Substring(0, fNamePos);
listLocalFiles();
for (int i = 0; i < lstPicFiles.Items.Count; i++)
{
if (lstPicFiles.Items[i].ToString() == lblFileName.Text)
{
lstPicFiles.SelectedIndex = i;
break;
}
}
}
}
private void listLocalFiles()
{
DirectoryInfo di = new DirectoryInfo(lblPath.Text);
FileInfo[] files = di.GetFiles("*.jpg");
lstPicFiles.Items.Clear();
for (int i = 0; i < files.Length; i++)
{
lstPicFiles.Items.Add(files[i].Name);
}
files = di.GetFiles("*.jpeg");
for (int i = 0; i < files.Length; i++)
{
lstPicFiles.Items.Add(files[i].Name);
}
btnReOrganize.Enabled = true;
}
private void lstPicFiles_SelectedIndexChanged(object sender, EventArgs e)
{
if (!Deleting)
{
string fName = ((ListBox)sender).SelectedItem.ToString();
lblFileName.Text = fName;
Image actPic = Image.FromFile(lblPath.Text + fName, true);
lblCreated.Text = "Skapad: " + TakenDate(actPic);
int w = actPic.Width;
int h = actPic.Height;
int pw = pictureBox1.Width;
int ph = pictureBox1.Height;
pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
Bitmap to_bm = new Bitmap((Image)actPic.Clone(), w * ph / h, ph);
pictureBox1.Image = to_bm;
actPic = null;
}
}
private string TakenDate(Image actPic)
{
string sPropDatTaken = "";
for (int i = 0; i < actPic.PropertyIdList.Length; i++)
{
if (actPic.PropertyIdList[i] == 306)
{
for (int j = 0; j < actPic.PropertyItems[i].Len; j++)
{
sPropDatTaken += Convert.ToChar(actPic.PropertyItems[i].Value[j]);
}
}
}
//actPic.Dispose();
return sPropDatTaken;
}
private void btnReOrganize_Click(object sender, EventArgs e)
{
bool error_upd = false;
if (txtRootDir.Text.Trim().Substring(txtRootDir.Text.Trim().Length - 1) != @"\")
txtRootDir.Text = txtRootDir.Text.Trim() + @"\";
DirectoryInfo di = new DirectoryInfo(txtRootDir.Text);
if (!di.Exists) di.Create();
Deleting = true;
pictureBox1.Image = null;
pictureBox1.Refresh();
for (int i = lstPicFiles.Items.Count - 1; i > -1; i--)
{
string lFileName = lstPicFiles.Items[i].ToString().Trim();
string fName = lblPath.Text.Trim() + lFileName;
lblFileName.Text = fName;
Image actIm = Image.FromFile(fName, true);
int w = actIm.Width;
int h = actIm.Height;
int pw = pictureBox1.Width;
int ph = pictureBox1.Height;
pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
Bitmap to_bm = new Bitmap((Image)actIm.Clone(), w * ph / h, ph);
pictureBox1.Image = to_bm;
string td = TakenDate(actIm);
actIm.Dispose();
if (td.Trim() != "")
{
lblCreated.Text = "Skapad: " + td;
td = td.Substring(0, 10);
DateTime dttd = DateTime.Parse(td.Replace(":", "-"));
string subDir1 = dttd.Year.ToString("0000") + "-" + dttd.Month.ToString("00") + @"\";
string subDir2 = dttd.Year.ToString("0000") + "_" + dttd.Month.ToString("00") + "_" + dttd.Day.ToString("00") + @"\";
DirectoryInfo dis = new DirectoryInfo(di.FullName + subDir1);
if (!dis.Exists) dis.Create();
DirectoryInfo diss = new DirectoryInfo(dis.FullName + subDir2);
if (!diss.Exists) diss.Create();
FileInfo fi = new FileInfo(fName);
//Tommy
fi.CopyTo(diss.FullName + lFileName);
error_upd = false;
do
{
error_upd = false;
try
{
lstPicFiles.BeginUpdate();
}
catch
{
error_upd = true;
}
}
while (error_upd);
lstPicFiles.Items.RemoveAt(i);
lstPicFiles.EndUpdate();
lstPicFiles.Refresh();
lblCreated.Refresh();
lblFileName.Refresh();
pictureBox1.Refresh();
this.Refresh();
}
}
Deleting = false;
lblCreated.Text = "";
lblFileName.Text = "";
lblPath.Text = "";
btnReOrganize.Enabled = false;
}
private void txtRootDir_TextChanged(object sender, EventArgs e)
{
}
}
}

60
PictureReposit/Form1.resx Normal file
View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>

23
PictureReposit/Program.cs Normal file
View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PictureReposit
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}