diff --git a/.vs/SAMPLauncherNET/v15/.suo b/.vs/SAMPLauncherNET/v15/.suo index 903e4ae..59502a7 100644 Binary files a/.vs/SAMPLauncherNET/v15/.suo and b/.vs/SAMPLauncherNET/v15/.suo differ diff --git a/README.md b/README.md index deb8670..05879f7 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,12 @@ Note: You don't need to commit `TranslatorInterface.cs`. You can change anything within the source code to contribute. ## Projects associated with this project +- https://github.com/BigETI/INIEngine - https://github.com/BigETI/UpdaterNET - https://github.com/BigETI/WinFormsTranslator +- https://github.com/errepi/ude +- https://github.com/icsharpcode/SharpZipLib +- https://github.com/IgnaceMaes/MaterialSkin - https://github.com/Hual/samp-discord-plugin - https://github.com/Southclaws/samp-servers-api - https://github.com/Southclaws/sampctl diff --git a/SAMPLauncherNET/Properties/AssemblyInfo.cs b/SAMPLauncherNET/Properties/AssemblyInfo.cs index 1a97ee8..d3d1bca 100644 --- a/SAMPLauncherNET/Properties/AssemblyInfo.cs +++ b/SAMPLauncherNET/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.6.0")] -[assembly: AssemblyFileVersion("1.0.6.0")] +[assembly: AssemblyVersion("1.0.6.1")] +[assembly: AssemblyFileVersion("1.0.6.1")] diff --git a/SAMPLauncherNET/SAMPLauncherNET.csproj b/SAMPLauncherNET/SAMPLauncherNET.csproj index ee713ce..6495990 100644 --- a/SAMPLauncherNET/SAMPLauncherNET.csproj +++ b/SAMPLauncherNET/SAMPLauncherNET.csproj @@ -79,6 +79,9 @@ + + libs\Ude.dll + ..\libs\UpdaterNET.dll @@ -393,13 +396,14 @@ - + \ No newline at end of file diff --git a/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Program.cs b/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Program.cs index a183096..c2d3917 100644 --- a/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Program.cs +++ b/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Program.cs @@ -152,13 +152,9 @@ private static void OnDownloadFileCompleted(object sender, AsyncCompletedEventAr [STAThread] static void Main() { +#if !DEBUG GitHubUpdateTask update = new GitHubUpdateTask("BigETI", "SAMPLauncherNET"); - bool start_update = false; if (update.IsUpdateAvailable) - { - start_update = (MessageBox.Show("A new update for SA:MP Launcher .NET is available.\r\nVersion: " + update.Version + "\r\n\r\nDo you want to install it now?", "Update available", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes); - } - if (start_update) { if (Utils.ExportResource("SAMPLauncherNET.PreBuilds.SAMPLauncherNETUpdater.exe", Path.Combine(Environment.CurrentDirectory, "SAMPLauncherNETUpdater.exe"))) { @@ -174,6 +170,7 @@ static void Main() } else { +#endif try { Translator.TranslatorInterface = new TranslatorInterface(); @@ -196,6 +193,7 @@ static void Main() { MessageBox.Show("A fatal error has occured:\r\n\r\n" + e.Message, "Fatal error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } +#if !DEBUG } if (installerPath != null) { @@ -204,6 +202,7 @@ static void Main() Thread.Sleep(200); } } +#endif Application.Exit(); } } diff --git a/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Server.cs b/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Server.cs index 932db38..6ab1529 100644 --- a/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Server.cs +++ b/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Server.cs @@ -922,9 +922,9 @@ private void Receive() hasPassword = (reader.ReadByte() != 0); playerCount = reader.ReadUInt16(); maxPlayers = reader.ReadUInt16(); - hostname = Encoding.Default.GetString(reader.ReadBytes(reader.ReadInt32())); - gamemode = Encoding.Default.GetString(reader.ReadBytes(reader.ReadInt32())); - language = Encoding.Default.GetString(reader.ReadBytes(reader.ReadInt32())); + hostname = Utils.GuessedStringEncoding(reader.ReadBytes(reader.ReadInt32())); + gamemode = Utils.GuessedStringEncoding(reader.ReadBytes(reader.ReadInt32())); + language = Utils.GuessedStringEncoding(reader.ReadBytes(reader.ReadInt32())); requestsRequired[ERequestType.Information] = false; break; @@ -938,8 +938,8 @@ private void Receive() { for (int i = 0; i < rc; i++) { - k = Encoding.Default.GetString(reader.ReadBytes(reader.ReadByte())); - rules.Add(k, Encoding.Default.GetString(reader.ReadBytes(reader.ReadByte()))); + k = Utils.GuessedStringEncoding(reader.ReadBytes(reader.ReadByte())); + rules.Add(k, Utils.GuessedStringEncoding(reader.ReadBytes(reader.ReadByte()))); } } catch (Exception e) @@ -961,7 +961,7 @@ private void Receive() for (int i = 0; i < pc; i++) { // Name and score - k = Encoding.Default.GetString(reader.ReadBytes(reader.ReadByte())); + k = Utils.GuessedStringEncoding(reader.ReadBytes(reader.ReadByte())); clients.Add(k, reader.ReadInt32()); } } @@ -987,7 +987,7 @@ private void Receive() for (ushort i = 0; i != playerCount; i++) { id = reader.ReadByte(); - pn = Encoding.Default.GetString(reader.ReadBytes(reader.ReadByte())); + pn = Utils.GuessedStringEncoding(reader.ReadBytes(reader.ReadByte())); s = reader.ReadInt32(); p = reader.ReadUInt32(); players.Add(id, new Player(id, pn, s, p)); diff --git a/SAMPLauncherNET/Source/SAMPLauncherNET/Core/ServerListConnector.cs b/SAMPLauncherNET/Source/SAMPLauncherNET/Core/ServerListConnector.cs index 1161697..f9faf6a 100644 --- a/SAMPLauncherNET/Source/SAMPLauncherNET/Core/ServerListConnector.cs +++ b/SAMPLauncherNET/Source/SAMPLauncherNET/Core/ServerListConnector.cs @@ -236,7 +236,7 @@ public Dictionary ServerListIO { string ip = Encoding.Default.GetString(reader.ReadBytes(reader.ReadInt32())); ushort port = (ushort)(reader.ReadUInt32()); - string cn = Encoding.Default.GetString(reader.ReadBytes(reader.ReadInt32())); + string cn = Utils.GuessedStringEncoding(reader.ReadBytes(reader.ReadInt32())); string sp = Encoding.Default.GetString(reader.ReadBytes(reader.ReadInt32())); string rp = Encoding.Default.GetString(reader.ReadBytes(reader.ReadInt32())); ip = ip + ":" + port; diff --git a/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Utils.cs b/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Utils.cs index 03b5ff1..b36e03f 100644 --- a/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Utils.cs +++ b/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Utils.cs @@ -6,6 +6,9 @@ using System.Diagnostics; using System.Windows.Forms; using System.Reflection; +using Ude; +using System.Text; +using System.Threading; /// /// SA:MP launcher .NET namespace @@ -22,6 +25,11 @@ public static class Utils /// public static readonly Size GalleryImageSize = new Size(256, 256); + /// + /// Charset detector + /// + private static readonly CharsetDetector charsetDetector = new CharsetDetector(); + /// /// Are arrays equal /// @@ -119,6 +127,54 @@ public static string NAString(string str) return ((str == null) ? "N/A" : ((str.Length > 0) ? str : "N/A")); } + /// + /// Guessed string encoding + /// + /// Bytes to encode + /// Encoded string + public static string GuessedStringEncoding(byte[] bytes) + { + string ret = null; + if (bytes != null) + { + charsetDetector.Reset(); + charsetDetector.Feed(bytes, 0, bytes.Length); + charsetDetector.DataEnd(); + try + { + string charset_name = charsetDetector.Charset; + if (charset_name != null) + { + Encoding encoding = Encoding.GetEncoding(charset_name); + if (encoding != null) + { + ret = encoding.GetString(bytes); + } + } + } + catch (Exception e) + { + Console.Error.WriteLine(e.Message); + } + if (ret == null) + { + try + { + ret = Encoding.Default.GetString(bytes); + } + catch (Exception e) + { + Console.Error.WriteLine(e.Message); + } + } + } + if (ret == null) + { + ret = ""; + } + return ret; + } + /// /// Get file resources from directory ///