Da ich dies einfach aus rein Lern Interesse gemacht habe veröffentliche ich dies nun.
Mir ist bewusst, dass es eventuell nicht Resourcen Sparend oder optimiert ist, jedoch hat es einfach Spaß gemacht, etwas zu schreiben was vielleicht ein oder anderes Projekt nützlich sein könnte.
Wie funktioniert das?
Ganz einfach ! Ihr ladet eure Dateien auf ein Webspace hoch, samt der PHP Datei und passt diese ggf. an, wenn ihr dies gemacht habt führt die PHP Datei aus und der Server erstellt eine XML Datei.
Das Programm nimmt sich diese und verarbeitet dies und fügt das in eine Downloadliste ein und am Ende sollte dann alles runtergeladen werden.
Die Hauptseite arbeitet mit RSS Feed, fand ich in dem Moment am einfachsten. Habe Breadfish als Testzwecke Missbraucht aufs übelste.
Wichtig!
Das Programm ist noch nicht zu 100 % fertig und wird von mir ein bisschen weiterentwickelt, Design änderbar etc
Selbstverständlich ist das Programm nicht fehlerfrei und kann BUgs beinhalten diese könnt ihr gerne hier rein Schreiben, werde es dann ggf., wenn Zeit da ist beheben.
Hoffe trotzdem das es gut ankommt.
Bilder:
Sourcecode von der Hauptdatei
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows.Forms;
using System.Xml;
using Koopakiller.NewsFeed;
using MetroFramework;
using MetroFramework.Forms;
namespace AG_Launcher
{
public partial class Form1 : MetroForm
{
int fileLoadedCount;
int getAllFilesCount;
long getServerSize;
bool isPauseDownload;
private string URLDownload = "LINK ZUR XML Datei";
private string rss_feed_url = "RSS FEED LINK";
private Button[] _Buttons;
private Button[] noButton;
private Queue<string> DownloadList = new Queue<string>();
private Queue<string> DownloadFolder = new Queue<string>();
WebClient _downloader;
Stopwatch sw = new Stopwatch();
ag_function AppFunction = new ag_function();
public Form1()
{
InitializeComponent();
this.BorderStyle = MetroFormBorderStyle.FixedSingle;
this.ShadowType = MetroFormShadowType.AeroShadow;
}
private void Form1_Load(object sender, EventArgs e)
{
if (AppFunction.getAppSetting("firstStart") == "true")
{
DialogResult result = MetroMessageBox.Show(this, "Dies scheint dein erster Start zu sein, dieses Programm ist noch in der Entwicklung. Bitte melde Bugs oder Vorschläge im Forum.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
if(result == DialogResult.OK)
{
AppFunction.setAppSetting("firstStart", "false");
}
}
else
{
PathGTAV.Text = AppFunction.getAppSetting("GTAVPath");
}
loadNewsPage();
}
private void closeBtn_Click(object sender, EventArgs e)
{
this.Close();
}
private void hideBtn_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void metroListView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void loadAllDatabtn_Click(object sender, EventArgs e)
{
getAllFilesCount = 0;
if (File.Exists(PathGTAV.Text + "/PlayGTAV.exe") == false)
{
DialogResult folderError = MetroMessageBox.Show(this, "Bitte wähle erst dein GTA V Ordner aus.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (folderError == DialogResult.OK)
{
DialogResult FolderSearch = findGTAVFolder.ShowDialog();
if (FolderSearch == DialogResult.OK)
{
if (File.Exists(findGTAVFolder.SelectedPath + "/PlayGTAV.exe") == false)
{
MetroMessageBox.Show(this, "Die \"PlayGTAV.exe\" wurde nicht gefunden!", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
PathGTAV.Text = findGTAVFolder.SelectedPath;
if (Directory.Exists(PathGTAV.Text + "/mods") == false)
{
Directory.CreateDirectory(PathGTAV.Text + "/mods");
}
}
}
}
}
fileListLoad.Nodes.Clear();
DownloadList.Clear();
DownloadFolder.Clear();
XmlTextReader DataReader = new XmlTextReader(URLDownload + "/files.xml");
while(DataReader.Read())
{
if(DataReader.IsStartElement())
{
switch(DataReader.Name)
{
case "file":
if(DataReader.GetAttribute("folder") == "true")
{
DownloadFolder.Enqueue(PathGTAV.Text + "/mods/" + DataReader.GetAttribute("name"));
}
else if (DataReader.GetAttribute("folder") == "false")
{
if(File.Exists(PathGTAV.Text + "/mods/" + DataReader.GetAttribute("name")) == false)
{
fileListLoad.Nodes.Add(DataReader.GetAttribute("name"));
DownloadList.Enqueue(DataReader.GetAttribute("name"));
getAllFilesCount++;
}
else
{
FileInfo fi = new FileInfo(@PathGTAV.Text + "/mods/" + DataReader.GetAttribute("name"));
if (ag_function.CalculateMD5(@PathGTAV.Text + "/mods/" + DataReader.GetAttribute("name")) != DataReader.GetAttribute("md5"))
{
fileListLoad.Nodes.Add(DataReader.GetAttribute("name"));
DownloadList.Enqueue(DataReader.GetAttribute("name"));
getAllFilesCount++;
}
}
if(DownloadList.Any())
{
downloadBtn.Enabled = true;
pauseBtn.Enabled = true;
stoppBtn.Enabled = true;
}
}
break;
case "allSize":
getServerSize = Convert.ToInt32(DataReader.GetAttribute("size"));
break;
}
}
}
muchFileLoadedCount.Text = fileLoadedCount + " / " + getAllFilesCount + " Dateien";
folderSizeLBL.Text = Convert.ToString(AppFunction.ConvertBytesToMegabytes(AppFunction.GetDirectorySize(PathGTAV.Text + "/mods", true))) + " / " + Convert.ToString(AppFunction.ConvertBytesToMegabytes(getServerSize)) + " mb";
}
private void fontDialog1_Apply(object sender, EventArgs e)
{
}
private void gamePath_Click(object sender, EventArgs e)
{
DialogResult folderError = MetroMessageBox.Show(this, "Bitte wähle dein GTA V Ordner aus.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (folderError == DialogResult.OK)
{
DialogResult FolderSearch = findGTAVFolder.ShowDialog();
if (FolderSearch == DialogResult.OK)
{
if (File.Exists(findGTAVFolder.SelectedPath + "/PlayGTAV.exe") == false)
{
MetroMessageBox.Show(this, "Die \"PlayGTAV.exe\" wurde nicht gefunden!", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
PathGTAV.Text = findGTAVFolder.SelectedPath;
AppFunction.setAppSetting("GTAVPath", PathGTAV.Text);
if (Directory.Exists(PathGTAV.Text + "/mods") == false)
{
Directory.CreateDirectory(PathGTAV.Text + "/mods");
}
}
}
}
}
private void downloadBtn_Click(object sender, EventArgs e)
{
if(DownloadFolder.Any())
{
foreach(string DownloadCreateFolder in DownloadFolder)
{
DirectoryInfo info = Directory.CreateDirectory(DownloadCreateFolder.ToString());
}
}
if(DownloadList.Any())
{
loadAllDatabtn.Enabled = false;
DownloadHandleAsync();
}
else { AddLogData("Keine Dateien zum laden gefunden!"); }
}
private void downloadBG_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
}
private void DownloadHandleAsync()
{
int lastCount = 0;
using (WebClient downloader = new WebClient())
{
if (downloader.IsBusy == false)
{
if (DownloadList.Any())
{
if (AppFunction.URLExists(URLDownload + "/files" + DownloadList.First()))
{
_downloader = downloader;
sw.Reset();
string[] words = DownloadList.First().Split('/');
for (int i = 0; i < words.Length; i++)
{
lastCount = i;
}
currentFile.Text = words[lastCount];
downloader.DownloadFileAsync(new Uri(URLDownload + "/files" + DownloadList.First()), PathGTAV.Text + "/mods/" + DownloadList.First());
downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileCompleted);
sw.Start();
}
else
AddLogData("[Downloader] Keine Dateien gefunden. " + URLDownload + "/files" + DownloadList.First());
}
}
}
}
private void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
downloadProgressBar.Value = e.ProgressPercentage;
downloadPercent.Text = Convert.ToString( e.ProgressPercentage ) + "%";
speedLBL.Text = AppFunction.ConvertBytesToMegabytes(e.BytesReceived) + "mb /" + AppFunction.ConvertBytesToMegabytes(e.TotalBytesToReceive) + "mb";
dlspeed.Text = string.Format("{0} mb/s", (e.BytesReceived / 1024d / 1024d / sw.Elapsed.TotalSeconds).ToString("0.00"));
}
private void downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Cancelled)
{
File.Delete(PathGTAV.Text + "/mods/" + DownloadList.First());
return;
}
if (e.Error != null)
MessageBox.Show(e.Error.Message);
else
{
downloadProgressBarAll.Value = Convert.ToInt16(100 * AppFunction.ConvertBytesToMegabytes(AppFunction.GetDirectorySize(PathGTAV.Text + "/mods", true)) / AppFunction.ConvertBytesToMegabytes(getServerSize));
folderSizeLBL.Text = Convert.ToString(AppFunction.ConvertBytesToMegabytes(AppFunction.GetDirectorySize(PathGTAV.Text + "/mods", true))) + " / " + Convert.ToString(AppFunction.ConvertBytesToMegabytes(getServerSize)) + " mb";
downloadPercentAll.Text = Convert.ToString(downloadProgressBarAll.Value) + "%";
string deleteFile = DownloadList.Dequeue();
fileLoadedCount++;
if(fileListLoad.Nodes.Count > 0) fileListLoad.Nodes.RemoveAt(0);
muchFileLoadedCount.Text = fileLoadedCount + " / " + getAllFilesCount + " Dateien";
if (DownloadList.Any())
{
//AddLogData("[Downloader] Nächste Datei wird geladen. Datei: " + DownloadList.First());
DownloadHandleAsync();
return;
}
downloadProgressBar.Value = 0;
downloadProgressBarAll.Value = 0;
loadAllDatabtn.Enabled = true;
downloadBtn.Enabled = false;
pauseBtn.Enabled = false;
stoppBtn.Enabled = false;
dlspeed.Text = "0 mb/s";
muchFileLoadedCount.Text = "0/0";
speedLBL.Text = "0 mb/s";
downloadPercent.Text = "0%";
downloadPercentAll.Text = "0%";
folderSizeLBL.Text = "0";
fileLoadedCount = 0;
getAllFilesCount = 0;
AddLogData("Dateien erfolgreich geladen!");
}
}
private void AddLogData(string text)
{
statusLBL.Text = text;
}
private void muchFileFoundCount_Click(object sender, EventArgs e)
{
}
private void metroTile1_Click(object sender, EventArgs e)
{
_downloader.CancelAsync();
downloadBtn.Enabled = true;
}
private void metroTile2_Click(object sender, EventArgs e)
{
if (isPauseDownload == false) isPauseDownload = true;
else if (isPauseDownload == true) isPauseDownload = false;
}
private void loadNewsPage()
{
_Buttons = new Button[22];
noButton = new Button[1];
int getOldPos = -1;
int Index_ = 0;
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "MyRSSReader/1.0");
RSSFeed rss_read = new RSSFeed();
rss_read.Load(webClient.OpenRead(rss_feed_url));
foreach (RSSFeedArticle feed in rss_read.Articles)
{
Index_++;
if(getOldPos == -1) getOldPos = 0;
else getOldPos = getOldPos + 45;
_Buttons[Index_] = new MetroFramework.Controls.MetroTile
{
Location = new Point(3, getOldPos),
Name = feed.Title,
Size = new Size(212, 41),
TabIndex = 0,
Text = feed.Title,
};
scrollable.Controls.Add(_Buttons[Index_]);
_Buttons[Index_].Click += new System.EventHandler(testButton_Click);
}
if(Index_ == 0)
{
noButton[0] = new MetroFramework.Controls.MetroTile
{
Location = new Point(3, 0),
Size = new Size(212, 41),
TabIndex = 0,
Text = "Keine Neuigkeiten!",
};
scrollable.Controls.Add(noButton[0]);
noButton[0].Click += new System.EventHandler(refreshButton_Click);
}
AddLogData("" + Index_);
}
private void testButton_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "MyRSSReader/1.0");
RSSFeed rss_read = new RSSFeed();
rss_read.Load(webClient.OpenRead(rss_feed_url));
foreach (RSSFeedArticle feed in rss_read.Articles)
{
if (feed.Title == btn.Text)
{
loadBrowserPage.DocumentText = feed.Content;
}
AddLogData(feed.ArticleUrl);
}
}
private void refreshButton_Click(object sender, EventArgs e)
{
loadNewsPage();
AddLogData("Neuigikeiten neu geladen!");
}
}
}
Alles anzeigen
PHP Datei:
<?php
error_reporting(E_ALL);
$alledateien = scandir('files');
$dom = new DOMDocument('1.0', 'utf-8');
$root = $dom->createElement('data');
$dom->appendChild($root);
function directoryScan($dir) {
if (isset($dir) && is_readable($dir)) {
$directionList = Array();
$dir = realpath($dir);
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir,FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST);
$x = 0;
foreach($objects as $entry => $object){
$getpath = str_replace($dir, '', $entry);
$size = ceil($object->getSize());
$changed = date($object->getMTime());
$directionList[$x]['path'] = $getpath;
$directionList[$x]['size'] = $size;
$directionList[$x]['changed'] = $changed;
$x ++;
}
return $directionList;
}
}
$allSize = 0;
foreach (directoryScan('files') as $datei)
{
if ($datei != "." && $datei != ".." && $datei != "files.xml" && $datei != "server.xml")
{
$root->appendChild($firstNode = $dom->createElement("file"));
$firstNode->setAttribute("name", $datei['path']);
$firstNode->setAttribute("md5", md5_file("files/". $datei['path']));
$firstNode->setAttribute("sizeFile", $datei['size']);
if (is_dir("files/". $datei['path']) == true) {
$firstNode->setAttribute("folder", "true");
}else{
$firstNode->setAttribute("folder", "false");
}
$allSize += $datei['size'];
}
};
$root->appendChild($firstNode = $dom->createElement("allSize"));
$firstNode->setAttribute("size", $allSize);
header('Content-type: text/xml; charset=utf-8');
echo $dom->saveXML();
$handle = fopen ("files.xml", "w");
fwrite ($handle, $dom->saveXML());
fclose ($handle);
?>
Alles anzeigen
Im Anhang habe ich den ganzen Ordner samt PHP Datei eingefügt.
Mfg #Jerola