Fixat numrering i sllaskkatalog
This commit is contained in:
@ -15,195 +15,241 @@ namespace PictureReposit
|
|||||||
public partial class Form1 : Form
|
public partial class Form1 : Form
|
||||||
{
|
{
|
||||||
|
|
||||||
private bool Deleting = false;
|
private bool Deleting = false;
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
RegistryKey PictureHandling = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Tfoman\PictureReposit");
|
RegistryKey PictureHandling = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Tfoman\PictureReposit");
|
||||||
if (PictureHandling == null)
|
if (PictureHandling == null)
|
||||||
{
|
{
|
||||||
txtRootDir.Text = @"D:\Bildlabb\LabRotCat";
|
txtRootDir.Text = @"D:\Bildlabb\LabRotCat";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
txtRootDir.Text = (string)PictureHandling.GetValue(@"RootMap");
|
txtRootDir.Text = (string)PictureHandling.GetValue(@"RootMap");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnFileDialog_Click(object sender, EventArgs e)
|
private void btnFileDialog_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
openFileDialog1.Title = "Välj bild-fil!";
|
openFileDialog1.Title = "Välj bild-fil!";
|
||||||
openFileDialog1.InitialDirectory = "C:\\";
|
openFileDialog1.InitialDirectory = "C:\\";
|
||||||
openFileDialog1.Filter = "Picture files (*.jpg)|*.jpg|All files (*.*)|*.*";
|
openFileDialog1.Filter = "Picture files (*.jpg)|*.jpg|All files (*.*)|*.*";
|
||||||
openFileDialog1.FilterIndex = 1;
|
openFileDialog1.FilterIndex = 1;
|
||||||
openFileDialog1.RestoreDirectory = true;
|
openFileDialog1.RestoreDirectory = true;
|
||||||
openFileDialog1.ShowDialog();
|
openFileDialog1.ShowDialog();
|
||||||
openFileDialog1.Multiselect = false;
|
openFileDialog1.Multiselect = false;
|
||||||
string fName = openFileDialog1.FileName;
|
string fName = openFileDialog1.FileName;
|
||||||
if (fName.Trim() != "")
|
if (fName.Trim() != "")
|
||||||
{
|
{
|
||||||
int fNamePos = fName.LastIndexOf(@"\") + 1;
|
int fNamePos = fName.LastIndexOf(@"\") + 1;
|
||||||
lblFileName.Text = fName.Substring(fNamePos);
|
lblFileName.Text = fName.Substring(fNamePos);
|
||||||
lblPath.Text = fName.Substring(0, fNamePos);
|
lblPath.Text = fName.Substring(0, fNamePos);
|
||||||
listLocalFiles();
|
listLocalFiles();
|
||||||
|
|
||||||
for (int i = 0; i < lstPicFiles.Items.Count; i++)
|
for (int i = 0; i < lstPicFiles.Items.Count; i++)
|
||||||
{
|
{
|
||||||
if (lstPicFiles.Items[i].ToString() == lblFileName.Text)
|
if (lstPicFiles.Items[i].ToString() == lblFileName.Text)
|
||||||
{
|
{
|
||||||
lstPicFiles.SelectedIndex = i;
|
lstPicFiles.SelectedIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void listLocalFiles()
|
private void listLocalFiles()
|
||||||
{
|
{
|
||||||
DirectoryInfo di = new DirectoryInfo(lblPath.Text);
|
DirectoryInfo di = new DirectoryInfo(lblPath.Text);
|
||||||
FileInfo[] files = di.GetFiles("*.jpg");
|
FileInfo[] files = di.GetFiles("*.jpg");
|
||||||
lstPicFiles.Items.Clear();
|
lstPicFiles.Items.Clear();
|
||||||
for (int i = 0; i < files.Length; i++)
|
for (int i = 0; i < files.Length; i++)
|
||||||
{
|
{
|
||||||
lstPicFiles.Items.Add(files[i].Name);
|
lstPicFiles.Items.Add(files[i].Name);
|
||||||
}
|
}
|
||||||
files = di.GetFiles("*.jpeg");
|
files = di.GetFiles("*.jpeg");
|
||||||
for (int i = 0; i < files.Length; i++)
|
for (int i = 0; i < files.Length; i++)
|
||||||
{
|
{
|
||||||
lstPicFiles.Items.Add(files[i].Name);
|
lstPicFiles.Items.Add(files[i].Name);
|
||||||
}
|
}
|
||||||
btnReOrganize.Enabled = true;
|
btnReOrganize.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lstPicFiles_SelectedIndexChanged(object sender, EventArgs e)
|
private void lstPicFiles_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (!Deleting)
|
if (!Deleting)
|
||||||
{
|
{
|
||||||
string fName = ((ListBox)sender).SelectedItem.ToString();
|
string fName = ((ListBox)sender).SelectedItem.ToString();
|
||||||
lblFileName.Text = fName;
|
lblFileName.Text = fName;
|
||||||
Image actPic = Image.FromFile(lblPath.Text + fName, true);
|
Image actPic = Image.FromFile(lblPath.Text + fName, true);
|
||||||
lblCreated.Text = "Skapad: " + TakenDate(actPic);
|
lblCreated.Text = "Skapad: " + TakenDate(actPic);
|
||||||
int w = actPic.Width;
|
int w = actPic.Width;
|
||||||
int h = actPic.Height;
|
int h = actPic.Height;
|
||||||
int pw = pictureBox1.Width;
|
int pw = pictureBox1.Width;
|
||||||
int ph = pictureBox1.Height;
|
int ph = pictureBox1.Height;
|
||||||
pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
|
pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
|
||||||
Bitmap to_bm = new Bitmap((Image)actPic.Clone(), w * ph / h, ph);
|
Bitmap to_bm = new Bitmap((Image)actPic.Clone(), w * ph / h, ph);
|
||||||
pictureBox1.Image = to_bm;
|
pictureBox1.Image = to_bm;
|
||||||
actPic = null;
|
actPic = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string TakenDate(Image actPic)
|
private string TakenDate(Image actPic)
|
||||||
{
|
{
|
||||||
string sPropDatTaken = "";
|
string sPropDatTaken = "";
|
||||||
for (int i = 0; i < actPic.PropertyIdList.Length; i++)
|
for (int i = 0; i < actPic.PropertyIdList.Length; i++)
|
||||||
{
|
{
|
||||||
if (actPic.PropertyIdList[i] == 306)
|
if (actPic.PropertyIdList[i] == 306)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < actPic.PropertyItems[i].Len; j++)
|
for (int j = 0; j < actPic.PropertyItems[i].Len; j++)
|
||||||
{
|
{
|
||||||
sPropDatTaken += Convert.ToChar(actPic.PropertyItems[i].Value[j]);
|
sPropDatTaken += Convert.ToChar(actPic.PropertyItems[i].Value[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//actPic.Dispose();
|
//actPic.Dispose();
|
||||||
return sPropDatTaken;
|
return sPropDatTaken;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnReOrganize_Click(object sender, EventArgs e)
|
private void btnReOrganize_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
bool error_upd = false;
|
bool error_upd = false;
|
||||||
if (txtRootDir.Text.Trim().Substring(txtRootDir.Text.Trim().Length - 1) != @"\")
|
bool slaskDir = false;
|
||||||
txtRootDir.Text = txtRootDir.Text.Trim() + @"\";
|
int slaskFilNr = 0;
|
||||||
DirectoryInfo di = new DirectoryInfo(txtRootDir.Text);
|
if (txtRootDir.Text.Trim().Substring(txtRootDir.Text.Trim().Length - 1) != @"\")
|
||||||
if (!di.Exists) di.Create();
|
txtRootDir.Text = txtRootDir.Text.Trim() + @"\";
|
||||||
Deleting = true;
|
DirectoryInfo di = new DirectoryInfo(txtRootDir.Text);
|
||||||
pictureBox1.Image = null;
|
if (!di.Exists) di.Create();
|
||||||
pictureBox1.Refresh();
|
Deleting = true;
|
||||||
for (int i = lstPicFiles.Items.Count - 1; i > -1; i--)
|
pictureBox1.Image = null;
|
||||||
{
|
pictureBox1.Refresh();
|
||||||
string lFileName = lstPicFiles.Items[i].ToString().Trim();
|
for (int i = lstPicFiles.Items.Count - 1; i > -1; i--)
|
||||||
string fName = lblPath.Text.Trim() + lFileName;
|
{
|
||||||
lblFileName.Text = fName;
|
string lFileName = lstPicFiles.Items[i].ToString().Trim();
|
||||||
Image actIm = Image.FromFile(fName, true);
|
string fName = lblPath.Text.Trim() + lFileName;
|
||||||
int w = actIm.Width;
|
lblFileName.Text = fName;
|
||||||
int h = actIm.Height;
|
Image actIm = Image.FromFile(fName, true);
|
||||||
int pw = pictureBox1.Width;
|
int w = actIm.Width;
|
||||||
int ph = pictureBox1.Height;
|
int h = actIm.Height;
|
||||||
pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
|
int pw = pictureBox1.Width;
|
||||||
Bitmap to_bm = new Bitmap((Image)actIm.Clone(), w * ph / h, ph);
|
int ph = pictureBox1.Height;
|
||||||
pictureBox1.Image = to_bm;
|
pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
|
||||||
string td = TakenDate(actIm);
|
Bitmap to_bm = new Bitmap((Image)actIm.Clone(), w * ph / h, ph);
|
||||||
|
pictureBox1.Image = to_bm;
|
||||||
|
string td = TakenDate(actIm);
|
||||||
|
|
||||||
actIm.Dispose();
|
actIm.Dispose();
|
||||||
if (td.Trim() != "")
|
if (td.Trim() != "")
|
||||||
{
|
{
|
||||||
lblCreated.Text = "Skapad: " + td;
|
lblCreated.Text = "Skapad: " + td;
|
||||||
td = td.Substring(0, 10);
|
td = td.Substring(0, 10);
|
||||||
DateTime dttd = DateTime.Parse(td.Replace(":", "-"));
|
DateTime dttd = DateTime.Parse(td.Replace(":", "-"));
|
||||||
string subDir1 = dttd.Year.ToString("0000") + "-" + dttd.Month.ToString("00") + @"\";
|
string subDir1 = dttd.Year.ToString("0000") + "-" + dttd.Month.ToString("00") + @"\";
|
||||||
string subDir2 = dttd.Year.ToString("0000") + "_" + dttd.Month.ToString("00") + "_" + dttd.Day.ToString("00") + @"\";
|
string subDir2 = dttd.Year.ToString("0000") + "_" + dttd.Month.ToString("00") + "_" + dttd.Day.ToString("00") + @"\";
|
||||||
DirectoryInfo dis = new DirectoryInfo(di.FullName + subDir1);
|
DirectoryInfo dis = new DirectoryInfo(di.FullName + subDir1);
|
||||||
if (!dis.Exists) dis.Create();
|
if (!dis.Exists) dis.Create();
|
||||||
DirectoryInfo diss = new DirectoryInfo(dis.FullName + subDir2);
|
DirectoryInfo diss = new DirectoryInfo(dis.FullName + subDir2);
|
||||||
if (!diss.Exists) diss.Create();
|
if (!diss.Exists) diss.Create();
|
||||||
|
|
||||||
FileInfo fi = new FileInfo(fName);
|
FileInfo fi = new FileInfo(fName);
|
||||||
//Tommy
|
//Tommy
|
||||||
fi.CopyTo(diss.FullName + lFileName);
|
fi.CopyTo(diss.FullName + lFileName);
|
||||||
error_upd = false;
|
error_upd = false;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
error_upd = false;
|
error_upd = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
lstPicFiles.BeginUpdate();
|
lstPicFiles.BeginUpdate();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
error_upd = true;
|
error_upd = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (error_upd);
|
while (error_upd);
|
||||||
lstPicFiles.Items.RemoveAt(i);
|
lstPicFiles.Items.RemoveAt(i);
|
||||||
lstPicFiles.EndUpdate();
|
lstPicFiles.EndUpdate();
|
||||||
lstPicFiles.Refresh();
|
lstPicFiles.Refresh();
|
||||||
lblCreated.Refresh();
|
lblCreated.Refresh();
|
||||||
lblFileName.Refresh();
|
lblFileName.Refresh();
|
||||||
pictureBox1.Refresh();
|
pictureBox1.Refresh();
|
||||||
this.Refresh();
|
this.Refresh();
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
Deleting = false;
|
{
|
||||||
lblCreated.Text = "";
|
DirectoryInfo dis = new DirectoryInfo(di.FullName + "NoDateInExif\\");
|
||||||
lblFileName.Text = "";
|
if (!slaskDir)
|
||||||
lblPath.Text = "";
|
{
|
||||||
btnReOrganize.Enabled = false;
|
if (!dis.Exists)
|
||||||
}
|
{
|
||||||
|
dis.Create();
|
||||||
|
set_Last_number(dis.FullName, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
slaskFilNr = get_Last_number(dis.FullName);
|
||||||
|
}
|
||||||
|
slaskDir = true;
|
||||||
|
}
|
||||||
|
|
||||||
private void txtRootDir_TextChanged(object sender, EventArgs e)
|
FileInfo fi = new FileInfo(fName);
|
||||||
{
|
//Tommy
|
||||||
//Software\Tfoman\PictureReposit
|
slaskFilNr++;
|
||||||
RegistryKey Tfoman = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Tfoman", true);
|
fi.CopyTo(dis.FullName + slaskFilNr.ToString() + "_" + lFileName);
|
||||||
RegistryKey PictureHandling = Tfoman.OpenSubKey(@"PictureReposit", true);
|
}
|
||||||
if (PictureHandling == null)
|
}
|
||||||
{
|
Deleting = false;
|
||||||
if (Tfoman == null)
|
lblCreated.Text = "";
|
||||||
{
|
lblFileName.Text = "";
|
||||||
Tfoman = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Tfoman");
|
lblPath.Text = "";
|
||||||
}
|
btnReOrganize.Enabled = false;
|
||||||
else
|
if (slaskFilNr > 0)
|
||||||
PictureHandling = Tfoman.CreateSubKey(@"PictureReposit");
|
{
|
||||||
}
|
set_Last_number(di.FullName + "NoDateInExif\\", slaskFilNr);
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
PictureHandling.SetValue(@"RootMap", txtRootDir.Text);
|
|
||||||
}
|
private void txtRootDir_TextChanged(object sender, EventArgs e)
|
||||||
}
|
{
|
||||||
|
//Software\Tfoman\PictureReposit
|
||||||
|
RegistryKey Tfoman = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Tfoman", true);
|
||||||
|
RegistryKey PictureHandling = Tfoman.OpenSubKey(@"PictureReposit", true);
|
||||||
|
if (PictureHandling == null)
|
||||||
|
{
|
||||||
|
if (Tfoman == null)
|
||||||
|
{
|
||||||
|
Tfoman = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Tfoman");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
PictureHandling = Tfoman.CreateSubKey(@"PictureReposit");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PictureHandling.SetValue(@"RootMap", txtRootDir.Text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int get_Last_number(string path)
|
||||||
|
{
|
||||||
|
int outPut = 0;
|
||||||
|
var lstNrFile = Path.Combine(path, "lastNrFile.txt");
|
||||||
|
if (File.Exists(lstNrFile))
|
||||||
|
{
|
||||||
|
outPut = int.Parse(File.ReadAllText(lstNrFile));
|
||||||
|
}
|
||||||
|
outPut++;
|
||||||
|
return outPut;
|
||||||
|
}
|
||||||
|
private void set_Last_number(string path, int lastNr)
|
||||||
|
{
|
||||||
|
var lstNrFile = Path.Combine(path, "lastNrFile.txt");
|
||||||
|
var SavedNumber = lastNr.ToString();
|
||||||
|
File.WriteAllText(lstNrFile, SavedNumber);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user