From de0aa5793302852461fa51fb0ac30725f59f9246 Mon Sep 17 00:00:00 2001 From: BigETI Date: Wed, 25 Apr 2018 19:53:59 +0200 Subject: [PATCH] Added Universal Charset Detector. Removed update question dialog. --- .vs/SAMPLauncherNET/v15/.suo | Bin 304640 -> 300544 bytes README.md | 4 ++ SAMPLauncherNET/Properties/AssemblyInfo.cs | 4 +- SAMPLauncherNET/SAMPLauncherNET.csproj | 8 ++- .../Source/SAMPLauncherNET/Core/Program.cs | 9 ++- .../Source/SAMPLauncherNET/Core/Server.cs | 14 ++--- .../Core/ServerListConnector.cs | 2 +- .../Source/SAMPLauncherNET/Core/Utils.cs | 56 ++++++++++++++++++ 8 files changed, 80 insertions(+), 17 deletions(-) diff --git a/.vs/SAMPLauncherNET/v15/.suo b/.vs/SAMPLauncherNET/v15/.suo index 903e4ae6816baeb90081589a951fe6cdd798e509..59502a7aba66de0317e1464c47b0e29c9f318f7f 100644 GIT binary patch delta 10202 zcmdT~dt6mjzCXXUHb+3j10o_29+8v~5D}5Qq^L-yfQV*3@QL6X5wWyTk7h3=MRxKt zGY825D|1X5j~StqmU$h;cd02Fni&##(@FDjzv~%D&O-`X3? z0e8!0_q^!#YYhfNGvMyMd-rfNNT3z)B+vqQPM@%%)w`Kzh$8g%qMcJ-aVxF-%u#w< zpDPlb$RAzW1Nz|(fwW)0E*4RUK36UpGnNbn<5aZZnho5+{0)~{OI;f3V}S%fm51Q& z1#ALT|An}>0epc@Kmnlo8TBEKogYv=I-+JEUjh`odtb;ebsn2)l(EnAm%>d>C&jTL7 z7+?X=9Y_bd0Xm>&9)SD9Ky-as)!oz2JGF9AboWQ?OdwyxlgY->s;M3g95pWbhdi{+ zf}aO5R#C3zQv7SES3Fz}{1G0i@ecYBtwV(3{_y%)ev6lirj0-_5CTjF^i7(tjkWP8 z+|SyVQ5UXQ8~IDt8VrvLgTWcC_zP8MIL%^^J9&L(%|My4hF?meN|2{eWqV`Nz^|!cGa_6 zGgRO~{hUa3Qp798=WGvJN>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--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 ///