using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
namespace wurst
{
public partial class cmdSource : Form
{
public cmdSource()
{
InitializeComponent();
}
//Zuweisen der Hilfsvariablen.
int gcheck = 0;
int check = 0;
Point pgone = new Point(2000, 2000);
Point pback = new Point(77, 256);
Point phoi = new Point(0, 0);
Point ptscho = new Point(160, 10);
public void button1_Click(object sender, EventArgs e)
{
//Defenierung einiger Variablen im cmdStart
this.Refresh();
lstBox.Items.Clear();
Point pCache = new Point (10, this.Height - 70);
lblAnzeige.Text = "";
//Einstellungen für den Folderbrowserdialog
Directory.CreateDirectory(@"C:\Bildcache\");
System.Windows.Forms.FolderBrowserDialog objDialog = new FolderBrowserDialog();
objDialog.Description = "Beschreibung";
objDialog.SelectedPath = @"C:\Users\";
DialogResult objResult = objDialog.ShowDialog(this);
if (objResult == DialogResult.OK)
{
//Deklariert den Suchordner
string[] sfiles = Directory.GetFiles(objDialog.SelectedPath);
string[] sfolder = Directory.GetDirectories(objDialog.SelectedPath);
//Dateien im Urordner
for (int i = 0; i < sfiles.Length; i++)
{
string sviles = Path.GetFileName(sfiles[i]);
//Überprüfung ob die Endung .bmp ist
if (cBbmp.Checked == true && Path.GetExtension(sfiles[i]) == ".bmp" || Path.GetExtension(sfiles[i]) == ".BMP")
{
if (File.Exists(@"C:\Bildcache\" + sviles))
{
lstBox.Items.Add(sviles);
}
else
{
lstBox.Items.Add(sviles);
File.Copy(sfiles[i], @"C:\Bildcache\" + sviles);
}
}
//Überprüfung ob die Endung .jpg ist
if (cBjpg.Checked == true && Path.GetExtension(sfiles[i]) == ".jpg" || cBjpg.Checked == true && Path.GetExtension(sfiles[i]) == ".JPG" || cBjpg.Checked == true && Path.GetExtension(sfiles[i]) == ".jpe" || cBjpg.Checked == true && Path.GetExtension(sfiles[i]) == ".JPE" || cBjpg.Checked == true && Path.GetExtension(sfiles[i]) == ".jpeg" || cBjpg.Checked == true && Path.GetExtension(sfiles[i]) == ".JPEG")
{
if (File.Exists(@"C:\Bildcache\" + sviles))
{
lstBox.Items.Add(sviles);
}
else
{
lstBox.Items.Add(sviles);
File.Copy(sfiles[i], @"C:\Bildcache\" + sviles);
}
}
//Überprüfung ob die Endung .png ist
if (cBpng.Checked == true && Path.GetExtension(sfiles[i]) == ".png" || Path.GetExtension(sfiles[i]) == ".PNG")
{
if (File.Exists(@"C:\Bildcache\" + sviles))
{
lstBox.Items.Add(sviles);
}
else
{
lstBox.Items.Add(sviles);
File.Copy(sfiles[i], @"C:\Bildcache\" + sviles);
}
}
//Überprüfung ob die Endung .tga ist
if (cBtga.Checked == true && Path.GetExtension(sfiles[i]) == ".tga" || Path.GetExtension(sfiles[i]) == ".TGA")
{
if (File.Exists(@"C:\Bildcache\" + sviles))
{
lstBox.Items.Add(sviles);
}
else
{
lstBox.Items.Add(sviles);
File.Copy(sfiles[i], @"C:\Bildcache\" + sviles);
}
}
}
for (int i2 = 0; i2 < sfolder.Length; i2++)
{
//Dateien in den anderen untergeordneten Ordnern
string[] sfiles2 = Directory.GetFiles(sfolder[i2]);
for (int i3 = 0; i3 < sfiles2.Length; i3++)
{
string sviles = Path.GetFileName(sfiles2[i3]);
//Überprüfung ob die Endung .bmp ist
if (cBbmp.Checked == true && Path.GetExtension(sfiles2[i3]) == ".bmp" || Path.GetExtension(sfiles2[i3]) == ".BMP")
{
if (File.Exists(@"C:\Bildcache\" + sviles))
{
lstBox.Items.Add(sviles);
}
else
{
lstBox.Items.Add(sviles);
File.Copy(sfiles2[i3], @"C:\Bildcache\" + sviles);
}
}
//Überprüfung ob die Endung .jpg ist
if (cBjpg.Checked == true && Path.GetExtension(sfiles2[i3]) == ".jpg" || cBjpg.Checked == true && Path.GetExtension(sfiles2[i3]) == ".JPG" || cBjpg.Checked == true && Path.GetExtension(sfiles2[i3]) == ".jpe" || cBjpg.Checked == true && Path.GetExtension(sfiles2[i3]) == ".JPE" || cBjpg.Checked == true && Path.GetExtension(sfiles2[i3]) == ".jpeg" || cBjpg.Checked == true && Path.GetExtension(sfiles2[i3]) == ".JPEG")
{
if (File.Exists(@"C:\Bildcache\" + sviles))
{
lstBox.Items.Add(sviles);
}
else
{
lstBox.Items.Add(sviles);
File.Copy(sfiles2[i3], @"C:\Bildcache\" + sviles);
}
}
//Überprüfung ob die Endung .png ist
if (cBpng.Checked == true && Path.GetExtension(sfiles2[i3]) == ".png" || Path.GetExtension(sfiles2[i3]) == ".PNG")
{
if (File.Exists(@"C:\Bildcache\" + sviles))
{
lstBox.Items.Add(sviles);
}
else
{
lstBox.Items.Add(sviles);
File.Copy(sfiles2[i3], @"C:\Bildcache\" + sviles);
}
}
//Überprüfung ob die Endung .tga ist
if (cBtga.Checked == true && Path.GetExtension(sfiles2[i3]) == ".tga" || Path.GetExtension(sfiles2[i3]) == ".TGA")
{
if (File.Exists(@"C:\Bildcache\" + sviles))
{
lstBox.Items.Add(sviles);
}
else
{
lstBox.Items.Add(sviles);
File.Copy(sfiles2[i3], @"C:\Bildcache\" + sviles);
}
}
}
}
//Gibt die Anzahl der Dateien wieder und schatet Bauelemente an/ aus
if (lstBox.Items.Count == 0)
{
lblAnzeige.Text = "-/-";
}
else
{
MessageBox.Show(lstBox.Items.Count.ToString() + " Dateien gefunden!");
tmrtimer.Enabled = true;
this.Location = phoi;
cmdCache.Enabled = false;
}
//Gibt die Ordnergröße via Tooltip wieder
double ergi = 0;
string[] scache = Directory.GetFiles(@"C:\Bildcache\");
for (int icache = 0; icache < scache.Length; icache++)
{
string stool = File.ReadAllBytes(scache[icache]).Length.ToString();
double dtool = Convert.ToDouble(stool);
dtool = dtool / 1000000;
dtool = Math.Round(dtool, 3);
ergi = ergi + dtool;
this.Text = "Bildproggy by Philipp Tusch - Größe des Bildcaches: " + ergi.ToString() + " MB" + " - Letztes Update: 08.10.2010";
}
string[] scache2 = Directory.GetFiles(@"C:\Bildcache\");
if (scache2.Length == 0)
{
this.Text = "Bildproggy by Philipp Tusch - Größe des Bildcaches: " + "0 MB" + " - Letztes Update: 08.10.2010";
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
Point pSource = new Point(15, 314);
Point pCachedel = new Point(15, 343);
cmdCache.Location = pCachedel;
cmdSourcecode.Location = pSource;
//Defenierung des Tooltips
ToolTip TTeins = new ToolTip();
TTeins.ShowAlways = true;
//Gibt die Ordnergröße via Tooltip wieder
double ergi = 0;
string[] scache = Directory.GetFiles(@"C:\Bildcache\");
for (int icache = 0; icache < scache.Length; icache++)
{
string stool = File.ReadAllBytes(scache[icache]).Length.ToString();
double dtool = Convert.ToDouble(stool);
dtool = dtool / 1000000;
dtool = Math.Round(dtool, 3);
ergi = ergi + dtool;
this.Text = "Bildproggy by Philipp Tusch - Größe des Bildcaches: " + ergi.ToString() + " MB" + " - Letztes Update: 08.10.2010";
}
string[] scache2 = Directory.GetFiles(@"C:\Bildcache\");
if (scache2.Length == 0)
{
this.Text = "Bildproggy by Philipp Tusch - Größe des Bildcaches: " + "0 MB" + " - Letztes Update: 08.10.2010";
}
}
private void lstBox_SelectedIndexChanged(object sender, EventArgs e)
{
}
public void tmrtimer_Tick(object sender, EventArgs e)
{
//Deklariert den Punkt und die Pixelaneige des Bildes.
Point plabel = new Point(pcbBox.Width / 2, pcbBox.Height + 20);
lblAnzeige.Text = pcbBox.Width.ToString() + " x " + pcbBox.Height.ToString();
if (lstBox.SelectedIndex >= 0 && lstBox.SelectedItem.ToString().Equals(lstBox.SelectedItem))
{
//vergrößert/ verkleinert die Anfendung, je nach größe des Bildes.
this.Width = Screen.PrimaryScreen.Bounds.Width;
this.Height = Screen.PrimaryScreen.Bounds.Height;
pcbBox.Width = System.Drawing.Bitmap.FromFile(@"C:\Bildcache\" + lstBox.SelectedItem).Width;
pcbBox.Height = System.Drawing.Bitmap.FromFile(@"C:\Bildcache\" + lstBox.SelectedItem).Height;
pcbBox.BackgroundImage = System.Drawing.Bitmap.FromFile(@"C:\Bildcache\" + lstBox.SelectedItem);
//Gibt die Dateigröße wieder.
cmdCache.Text = File.ReadAllBytes(@"C:\Bildcache\" + lstBox.SelectedItem).LongLength.ToString();
double derg = Convert.ToDouble(cmdCache.Text);
derg = derg / 1000000;
derg = Math.Round(derg, 3);
//Größenangabe der Datei
if (derg < 1)
{
derg = derg * 1000;
cmdCache.Text = derg.ToString() + " KB";
}
else if (derg >= 1)
{
cmdCache.Text = derg.ToString() + " MB";
}
}
//Aktivierung des cmdFull
if (pcbBox.Width >= 1920)
{
cmdFull.Visible = true;
}
else
cmdFull.Visible = false;
}
private void pcbBox_Click(object sender, EventArgs e)
{
if (pcbBox.Width >= 1920)
{
if (check == 0)
{
//Macht die Bauteile unsichtbar/ verschiebt diese
//Damit man das Bild komplett angucken kann
cmdSelect.Visible = false;
this.Location = phoi;
lstBox.Visible = false;
lblAnzeige.Visible = false;
cmdStart.Visible = false;
cmdSourcecode.Visible = false;
cmdFull.Visible = false;
cmdCache.Visible = false;
cmdFull.Location = pgone;
cmdFull.Enabled = false;
this.FormBorderStyle = FormBorderStyle.None;
pcbBox.Location = phoi;
gB1.Visible = false;
cBtga.Visible = false;
cBpng.Visible = false;
cBjpg.Visible = false;
cBbmp.Visible = false;
gcheck = 0;
check = 1;
}
else if (check == 1)
{
//Macht die Bauteile sichtbar
lstBox.Visible = true;
lblAnzeige.Visible = true;
cmdStart.Visible = true;
cmdSelect.Visible = true;
cmdFull.Enabled = true;
cmdCache.Visible = true;
cmdSourcecode.Visible = true;
cmdFull.Location = pback;
cmdFull.Visible = true;
this.FormBorderStyle = FormBorderStyle.Sizable;
pcbBox.Location = ptscho;
check = 0;
}
}
}
private void cmdFull_Click(object sender, EventArgs e)
{
//Macht die Bauteile unsichtbar/ verschiebt diese
//Damit man das Bild komplett angucken kann
check = 1;
cmdSelect.Visible = false;
this.Location = phoi;
lstBox.Visible = false;
lblAnzeige.Visible = false;
cmdStart.Visible = false;
cmdSourcecode.Visible = false;
cmdFull.Visible = false;
cmdCache.Visible = false;
cmdFull.Location = pgone;
cmdFull.Enabled = false;
this.FormBorderStyle = FormBorderStyle.None;
pcbBox.Location = phoi;
gB1.Visible = false;
cBtga.Visible = false;
cBpng.Visible = false;
cBjpg.Visible = false;
cBbmp.Visible = false;
gcheck = 0;
}
private void cmdSelect_Click(object sender, EventArgs e)
{
Point pSource = new Point(15, 314);
Point pCachedel = new Point(15, 343);
Point pSource2 = new Point (15, 444);
Point pCachedel2 = new Point (15, 473);
//überprüft, ob der Button cmdselect geklickt ist oder nicht
if (gcheck == 0)
{
gB1.Visible = true;
cBbmp.Visible = true;
cBjpg.Visible = true;
cBpng.Visible = true;
cBtga.Visible = true;
gcheck = 1;
cmdCache.Location = pCachedel2;
cmdSourcecode.Location = pSource2;
}
else if (gcheck == 1)
{
gB1.Visible = false;
cBtga.Visible = false;
cBpng.Visible = false;
cBjpg.Visible = false;
cBbmp.Visible = false;
gcheck = 0;
cmdCache.Location = pCachedel;
cmdSourcecode.Location = pSource;
}
}
private void cmdCache_Click(object sender, EventArgs e)
{
//Löscht den Inhalt des Cache- Speicher
System.Windows.Forms.FolderBrowserDialog objDialog = new FolderBrowserDialog();
objDialog.Description = "Beschreibung";
objDialog.SelectedPath = @"C:\Bildcache";
string[] sfiles = Directory.GetFiles(objDialog.SelectedPath);
for (int i = 0; i < sfiles.Length; i++)
{
File.Delete(sfiles[i]);
}
//Gibt die Ordnergröße via Formtext wieder
double ergi = 0;
string[] scache = Directory.GetFiles(@"C:\Bildcache\");
for (int icache = 0; icache < scache.Length; icache++)
{
string stool = File.ReadAllBytes(scache[icache]).Length.ToString();
double dtool = Convert.ToDouble(stool);
dtool = dtool / 1000000;
dtool = Math.Round(dtool, 3);
ergi = ergi + dtool;
this.Text = "Bildproggy by Philipp Tusch - Größe des Bildcaches: " + ergi.ToString() + " MB" + " - Letztes Update: 08.10.2010";
}
if (scache.Length == 0)
{
this.Text = "Bildproggy by Philipp Tusch - Größe des Bildcaches: " + "0 MB" + " - Letztes Update: 08.10.2010";
}
}
private void button1_Click_2(object sender, EventArgs e)
{
//Speichert den Sourcecode in
//C:\Bildcache\Sourcecode.txt ab.
if (File.Exists(@"C:\Bildcache\Sourcecode.txt"))
{
System.Diagnostics.Process.Start(@"C:\Bildcache\Sourcecode.txt");
}
else
{
StreamWriter swriter = new StreamWriter(@"C:\Bildcache\Sourcecode.txt");
swriter.Write(Properties.Resources.Sourcecode);
swriter.Close();
MessageBox.Show("Sourcecode gespeichert in: C:\\Bildercache\\");
System.Diagnostics.Process.Start(@"C:\Bildcache\Sourcecode.txt");
}
}
}
}