Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added FileDownloader.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Launcher.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2011
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher", "Launcher\Launcher.csproj", "{1BDB18BA-1B02-40C2-BF21-9A239A4CA751}"
EndProject
Expand Down
2 changes: 1 addition & 1 deletion Launcher/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/>
</startup>
</configuration>
51 changes: 49 additions & 2 deletions Launcher/Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,25 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Launcher</RootNamespace>
<AssemblyName>Launcher</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -32,11 +47,19 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject>Launcher.Program</StartupObject>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="FileDownloader, Version=1.0.6876.3612, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\FileDownloader.dll</HintPath>
</Reference>
<Reference Include="MetroFramework, Version=1.4.0.0, Culture=neutral, PublicKeyToken=5f91a84759bf584a, processorArchitecture=MSIL">
<HintPath>..\packages\MetroModernUI.1.4.0.0\lib\net\MetroFramework.dll</HintPath>
<Private>True</Private>
Expand All @@ -51,6 +74,9 @@
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Microsoft.VisualBasic.Compatibility" />
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
Expand All @@ -76,7 +102,9 @@
<DependentUpon>LauncherSettings.cs</DependentUpon>
</Compile>
<Compile Include="MainView\AutoUpdater.cs" />
<Compile Include="MainView\Cache.cs" />
<Compile Include="MainView\Downloader.cs" />
<Compile Include="MainView\IniFile.cs" />
<Compile Include="MainView\main.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -120,7 +148,9 @@
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="App.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<None Include="Resources\button.png" />
Expand All @@ -134,6 +164,23 @@
<ItemGroup>
<None Include="Resources\settingsFont.png" />
</ItemGroup>
<ItemGroup>
<Content Include="icon.ico" />
<Content Include="Resources\bg.jpeg" />
<Content Include="Resources\icon.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 und x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
13 changes: 13 additions & 0 deletions Launcher/Launcher.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory />
<InstallUrlHistory />
<SupportUrlHistory />
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory />
<FallbackCulture>de-DE</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>
75 changes: 75 additions & 0 deletions Launcher/MainView/Cache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.Net;
using System.IO;
using FileDownloader;
using Newtonsoft.Json;

namespace FileDownloader
{
class CachObject
{
public string URI { get; set; }
public string PATH { get; set; }
public string[] HEADERS { get; set; }
}

class Base64
{
public static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}

public static string Base64Decode(string base64EncodedData)
{
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
}

class Cache : IDownloadCache
{
string filepath
{
get {
if(Directory.Exists(System.IO.Path.GetFullPath("./") + @"\cache"))
return System.IO.Path.GetFullPath("./") + @"\cache\";
else
{
Directory.CreateDirectory(System.IO.Path.GetFullPath("./") + @"\cache");
return System.IO.Path.GetFullPath("./") + @"\cache\";
}
}
}
void IDownloadCache.Add(Uri uri, string path, WebHeaderCollection headers)
{
CachObject cach = new CachObject() { URI = uri.AbsoluteUri, PATH = path, HEADERS = headers.AllKeys };
string jsonData = JsonConvert.SerializeObject(cach);
string Path = Base64.Base64Encode(uri.AbsolutePath).Replace("\\", "");
File.WriteAllText(filepath + Path, jsonData);
}

string IDownloadCache.Get(Uri uri, WebHeaderCollection headers)
{
string Path = Base64.Base64Encode(uri.AbsolutePath).Replace("\\", "");
string PATH = filepath + Path;
if (File.Exists(PATH))
{
var JsonEncoded = File.ReadAllText(PATH);
CachObject account = JsonConvert.DeserializeObject<CachObject>(JsonEncoded);
return account.PATH;
}
else
return null;
}

void IDownloadCache.Invalidate(Uri uri)
{
string Path = Base64.Base64Encode(uri.AbsolutePath).Replace("\\", "");
string PATH = filepath + Path;
if (File.Exists(PATH))
File.Delete(PATH);
}
}
}
47 changes: 30 additions & 17 deletions Launcher/MainView/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
using System.Net;
using System.IO;
using System.Windows.Forms;
using FileDownloader;

namespace Launcher
{
public class Downloader
{
private main MainView;
private BackgroundWorker Worker;
private WebClient _wc = new WebClient();
public static IDownloadCache downloadCache = new Cache();
public IFileDownloader _wc = new FileDownloader.FileDownloader(downloadCache);
private List<string> downloadList;
public bool downloadInProgress = false;
private long downloadedAmount = 0;
Expand Down Expand Up @@ -52,9 +54,13 @@ stop the worker
/********************************/
public void CancelWorker()
{
_wc.Dispose();
Worker.CancelAsync();
inter.StopNetworkInterface();
if (Worker != null)
{
Worker.Dispose();
Worker.CancelAsync();
}
if(inter != null)
inter.StopNetworkInterface();
}
/*******************************
simple function to check if a file exist
Expand All @@ -77,7 +83,7 @@ private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
if (Worker.CancellationPending)
{
MainView = null;
_wc.CancelAsync();
_wc.CancelDownloadAsync();
e.Cancel = true;
}
else
Expand Down Expand Up @@ -139,10 +145,10 @@ public void startDownload(string fileToDownloadLink, string PathToSaveFile)
{
try
{
using (_wc = new WebClient())
using (_wc = new FileDownloader.FileDownloader(downloadCache))
{
_wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
_wc.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
_wc.DownloadProgressChanged += new EventHandler<DownloadFileProgressChangedArgs>(client_DownloadProgressChanged);
_wc.DownloadFileCompleted += new EventHandler<DownloadFileCompletedArgs>(client_DownloadFileCompleted);
_wc.DownloadFileAsync(new Uri(fileToDownloadLink), PathToSaveFile);
}
}
Expand All @@ -157,7 +163,7 @@ public void startDownload(string fileToDownloadLink, string PathToSaveFile)
/*******************************
update the progress of the download
/********************************/
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
void client_DownloadProgressChanged(object sender, DownloadFileProgressChangedArgs e)
{
if (MainView != null && MainView.Created)
{
Expand All @@ -169,25 +175,32 @@ void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventA
/*******************************
file downloaded
/********************************/
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
void client_DownloadFileCompleted(object sender, DownloadFileCompletedArgs e)
{
if (e.Cancelled)
if (e.State == CompletedState.Canceled)
{
_wc.CancelAsync();
_wc.CancelDownloadAsync();
}
else if (e.Error != null)
{
_wc.CancelAsync();
_wc.CancelDownloadAsync();
}

downloadInProgress = false;

totalDownloaded += downloadedAmount;
MainView.Invoke(new Action(() => MainView.updateAlreadyDownloaded(downloadedAmount)));
if ( ( (totalDownloaded / totalSize) * 100) == 100 || currentFile == downloadList.Count)
try
{
MainView.Invoke(new Action(() => MainView.UpdateCompleted()));
inter.StopNetworkInterface();
MainView.Invoke(new Action(() => MainView.updateAlreadyDownloaded(downloadedAmount)));
if (((totalDownloaded / totalSize) * 100) == 100 || currentFile == downloadList.Count)
{
MainView.Invoke(new Action(() => MainView.UpdateCompleted()));
inter.StopNetworkInterface();
}
}
catch
{

}
}
}
Expand Down
52 changes: 52 additions & 0 deletions Launcher/MainView/IniFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;

// Change this to match your program's normal namespace
namespace Launcher.MainView
{
class IniFile // revision 11
{
string Path;
string EXE = Assembly.GetExecutingAssembly().GetName().Name;

[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath);

[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath);

public IniFile(string IniPath = null)
{
Path = new FileInfo(IniPath ?? EXE + ".ini").FullName.ToString();
}

public string Read(string Key, string Section = null)
{
var RetVal = new StringBuilder(255);
GetPrivateProfileString(Section ?? EXE, Key, "", RetVal, 255, Path);
return RetVal.ToString();
}

public void Write(string Key, string Value, string Section = null)
{
WritePrivateProfileString(Section ?? EXE, Key, Value, Path);
}

public void DeleteKey(string Key, string Section = null)
{
Write(Key, null, Section ?? EXE);
}

public void DeleteSection(string Section = null)
{
Write(null, null, Section ?? EXE);
}

public bool KeyExists(string Key, string Section = null)
{
return Read(Key, Section).Length > 0;
}
}
}
4 changes: 4 additions & 0 deletions Launcher/MainView/Repair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public void PerformRepair(main MainfForm)
fileToDownload.Add(FilePath);
TotalSize += long.Parse(converted[2]); // size of the file
}
//else if ()
//{

//}
}
counter+=1;
if (MainfForm != null && MainfForm.Created)
Expand Down
Loading