Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Muteo42 authored Dec 7, 2023
1 parent 677ebe9 commit 3015f78
Show file tree
Hide file tree
Showing 21 changed files with 1,295 additions and 9 deletions.
46 changes: 44 additions & 2 deletions LoslandLauncher/Classes/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LoslandLauncher.Classes
{
Expand All @@ -25,8 +26,13 @@ public static int CheckNetwork()
return 0;
}
}
public static string ReadTextFromUrl(string url)
public static string ReadTextFromUrl(string url, bool nocache = false)
{
if(nocache)
{
Random random = new Random();
url = url + "?r=" + random.Next().ToString();
}
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.UserAgent = "SECAC/1.0";
Expand All @@ -45,8 +51,9 @@ public static void UpdateApp()
registryKey = Registry.LocalMachine.CreateSubKey("Software\\Microsoft\\loslauncher");
}
registryKey.SetValue("app_path", System.Reflection.Assembly.GetExecutingAssembly().Location);
Random random = new Random();
WebClient indir = new WebClient();
Uri yol = new Uri(Globals.WEBAPI + "files/LoslandUpdater.exe");
Uri yol = new Uri(Globals.WEBAPI + "files/LoslandUpdater.exe" + "?r=" + random.Next().ToString());
indir.DownloadFileCompleted += new AsyncCompletedEventHandler(FileDownloaded);
indir.DownloadFileAsync(yol, Path.GetTempPath() + "LoslandUpdater.exe");
}
Expand All @@ -56,5 +63,40 @@ public static void FileDownloaded(object sender, AsyncCompletedEventArgs e)
System.Diagnostics.Process.Start(Path.GetTempPath() + "LoslandUpdater.exe");
Environment.Exit(0);
}

public static long GetDirectorySize(DirectoryInfo d)
{
long size = 0;
// Add file sizes.
FileInfo[] fis = d.GetFiles();
foreach (FileInfo fi in fis)
{
size += fi.Length;
}
// Add subdirectory sizes.
DirectoryInfo[] dis = d.GetDirectories();
foreach (DirectoryInfo di in dis)
{
size += GetDirectorySize(di);
}
return size;
}

public static long GetDirectorySize(string p)
{
// Get array of all file names.
string[] a = Directory.GetFiles(p, "*.*");

// Calculate total bytes of all files in a loop.
long b = 0;
foreach (string name in a)
{
// Use FileInfo to get length of each file.
FileInfo info = new FileInfo(name);
b += info.Length;
}
// Return total size
return b;
}
}
}
2 changes: 1 addition & 1 deletion LoslandLauncher/Classes/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace LoslandLauncher.Classes
class Globals
{
public static string WEBAPI = "http://fast.sec-nine.com/secac/losland/app/";
public static string Version = "0.6";
public static string Version = "0.7";
public static string GameIP = "51.77.74.142";
public static string _GamePath = Registry.CurrentUser.OpenSubKey(@"Software\\SAMP").GetValue("gta_sa_exe").ToString();
public static string GamePath = _GamePath = _GamePath.Substring(0, _GamePath.LastIndexOf(@"\") + 1);
Expand Down
7 changes: 7 additions & 0 deletions LoslandLauncher/Downloader.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 78 additions & 3 deletions LoslandLauncher/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -25,6 +27,7 @@ private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont,

string[] downloadArray;
string[] downloadTempArray;
bool downloadingZip = false;
public Downloader()
{
InitializeComponent();
Expand Down Expand Up @@ -56,7 +59,7 @@ private void Downloader_Load(object sender, EventArgs e)
Environment.Exit(0);
return;
}
if (Globals.Version != Functions.ReadTextFromUrl(Globals.WEBAPI + "version.php"))
if (Globals.Version != Functions.ReadTextFromUrl(Globals.WEBAPI + "version.php", true))
{
Functions.UpdateApp();
return;
Expand All @@ -65,7 +68,7 @@ private void Downloader_Load(object sender, EventArgs e)
{
Directory.CreateDirectory(Globals.GamePath + "\\secac\\data");
}
downloadArray = Functions.ReadTextFromUrl(Globals.WEBAPI + "patch.php?r55").Split('|');
downloadArray = Functions.ReadTextFromUrl(Globals.WEBAPI + "patch.php", true).Split('|');
CheckUpdate();
}
catch (Exception ex)
Expand Down Expand Up @@ -100,7 +103,7 @@ private void CheckUpdate()
downloadTempArray = downloadArray[i].Split(',');
if (!File.Exists(Globals.GamePath + "\\" + downloadTempArray[0]))
{
if (downloadTempArray[0] == "samp.exe" || downloadTempArray[0] == "samp.asi") continue;
if (downloadTempArray[0] == "samp.asi") continue;
founded = 1;
DownloadFile(Globals.WEBAPI + "files/" + downloadTempArray[0], Globals.GamePath + "\\" + downloadTempArray[0]);
label1.Text = "Oyun dosyaları güncelleniyor...";
Expand All @@ -122,6 +125,52 @@ private void CheckUpdate()
}
if (founded == 0)
{
if (Convert.ToBoolean(Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\loslauncher").GetValue("settings_2")))
{
if (Directory.Exists(Globals.GamePath + "\\modloader"))
{
int needdownload = 0;
if (Directory.Exists(Globals.GamePath + "\\modloader\\mod_loslandlauncher"))
{
long filesize = Functions.GetDirectorySize(new DirectoryInfo(Globals.GamePath + "\\modloader\\mod_loslandlauncher"));
long neededfilesize = Convert.ToInt64(Functions.ReadTextFromUrl(Globals.WEBAPI + "modpatch.php", true));
if(filesize != neededfilesize)
{
needdownload = 1;
}
}
else
{
if (File.Exists(Globals.GamePath + "\\modloader\\mod_loslandlauncher.zip"))
{
label1.Text = "Mod dosyaları güncelleniyor...";
label2.Text = "mod_loslandlauncher.zip çıkartılıyor...";
label3.Text = "Bu işlem disk hızına göre biraz zaman alabilir.";
zipExtractor.RunWorkerAsync();
return;
}
else
{
needdownload = 1;
}
}
if(needdownload == 1)
{
downloadingZip = true;
DownloadFile(Globals.WEBAPI + "files/mod_loslandlauncher.zip", Globals.GamePath + "\\modloader\\mod_loslandlauncher_crc.zip");
label1.Text = "Mod dosyaları güncelleniyor...";
label2.Text = "mod_loslandlauncher.zip indiriliyor...";
return;
}
}
}
else
{
if (Directory.Exists(Globals.GamePath + "\\modloader\\mod_loslandlauncher"))
{
Directory.Delete(Globals.GamePath + "\\modloader\\mod_loslandlauncher", true);
}
}
timer1.Start();
}
}
Expand All @@ -132,6 +181,9 @@ private void CheckUpdate()

public void DownloadFile(string url, string path)
{
Random random = new Random();
url = url + "?r=" + random.Next().ToString();

WebClient down = new WebClient();
Uri link = new Uri(url);
down.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadUpdate);
Expand All @@ -149,6 +201,12 @@ public void DownloadUpdate(object sender, DownloadProgressChangedEventArgs e)

private void DownloadFinish(object sender, AsyncCompletedEventArgs e)
{
if(downloadingZip)
{
File.Move(Globals.GamePath + "\\modloader\\mod_loslandlauncher_crc.zip", Globals.GamePath + "\\modloader\\mod_loslandlauncher.zip");
File.Delete(Globals.GamePath + "\\modloader\\mod_loslandlauncher_crc.zip");
downloadingZip = false;
}
stopWatch.Reset();
CheckUpdate();
}
Expand All @@ -172,5 +230,22 @@ private void timer1_Tick(object sender, EventArgs e)
main.WindowState = FormWindowState.Normal;
main.CloseDownloaderForm();
}

private void zipExtractor_DoWork(object sender, DoWorkEventArgs e)
{
if(Directory.Exists(Globals.GamePath + "\\modloader\\mod_loslandlauncher")) Directory.Delete(Globals.GamePath + "\\modloader\\mod_loslandlauncher", true);
Directory.CreateDirectory(Globals.GamePath + "\\modloader\\mod_loslandlauncher");

ZipFile.ExtractToDirectory(Globals.GamePath + "\\modloader\\mod_loslandlauncher.zip", Globals.GamePath + "\\modloader\\mod_loslandlauncher");
ZipArchive archive = ZipFile.OpenRead(Globals.GamePath + "\\modloader\\mod_loslandlauncher.zip");
archive.Dispose();

File.Delete(Globals.GamePath + "\\modloader\\mod_loslandlauncher.zip");
}

private void zipExtractor_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
CheckUpdate();
}
}
}
3 changes: 3 additions & 0 deletions LoslandLauncher/Downloader.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="zipExtractor.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>105, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down
2 changes: 2 additions & 0 deletions LoslandLauncher/LoslandLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down
2 changes: 1 addition & 1 deletion LoslandLauncher/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public Main()
}
userNameBox.Select(userNameBox.Text.Length, userNameBox.Text.Length);
ipAddress.Text = Globals.GameIP + ":7777";
serverInfoWorker.RunWorkerAsync();
}

private PrivateFontCollection fonts = new PrivateFontCollection();
Expand All @@ -84,6 +83,7 @@ private void SetFonts()
private void Main_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
serverInfoWorker.RunWorkerAsync();
}

public void CloseDownloaderForm()
Expand Down
17 changes: 16 additions & 1 deletion LoslandLauncher/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion LoslandLauncher/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Microsoft.Win32;
using LoslandLauncher.Classes;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
Expand All @@ -20,13 +22,17 @@ public partial class Settings : Form
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont,
IntPtr pdv, [System.Runtime.InteropServices.In] ref uint pcFonts);

bool inital = false;

public Settings()
{
InitializeComponent();
LoadFonts();
SetFonts();
inital = true;
checkBox1.Checked = Convert.ToBoolean(Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\loslauncher").GetValue("settings_1"));
checkBox2.Checked = Convert.ToBoolean(Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\loslauncher").GetValue("settings_2"));
inital = false;
}

private PrivateFontCollection fonts = new PrivateFontCollection();
Expand All @@ -43,6 +49,7 @@ private void LoadFonts()
private void SetFonts()
{
checkBox1.Font = new Font(fonts.Families[0], 10, FontStyle.Regular);
checkBox2.Font = new Font(fonts.Families[0], 10, FontStyle.Regular);
label1.Font = new Font(fonts.Families[0], 12, FontStyle.Bold);
}

Expand All @@ -65,7 +72,21 @@ private void closeForm_Click(object sender, EventArgs e)

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (inital) return;
Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\loslauncher", true).SetValue("settings_1", Convert.ToInt32(checkBox1.Checked));
}

private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (inital) return;
if (!Directory.Exists(Globals.GamePath + "\\modloader"))
{
MessageBox.Show("Oyun klasöründe modloader yazılımı bulunamadı.", "Losland Launcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\loslauncher", true).SetValue("settings_2", Convert.ToInt32(checkBox2.Checked));
Application.Restart();
Environment.Exit(0);
}
}
}
Loading

0 comments on commit 3015f78

Please sign in to comment.