/// <summary>
        /// Determines whether or not the local copy of the manifest for the specifed module is outdated.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Will be thrown if the <see cref="EModule"/> passed to the function is not a valid value.
        /// </exception>
        protected virtual bool IsModuleManifestOutdated(EModule module)
        {
            string manifestPath;

            switch (module)
            {
            case EModule.Launcher:
            case EModule.Game:
            {
                manifestPath = this.FileManifestHandler.GetManifestPath((EManifestType)module, false);
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(module), module,
                                                      "An invalid module value was passed to RefreshModuleManifest.");
            }
            }

            if (File.Exists(manifestPath))
            {
                string remoteHash = GetRemoteModuleManifestChecksum(module);
                using (Stream file = File.OpenRead(manifestPath))
                {
                    string localHash = MD5Handler.GetStreamHash(file);

                    return(remoteHash != localHash);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        public UHFDeskMain()
        {
            if (!System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "config.ini"))
            {
                MessageBox.Show("Cant't find configuration file, please contact with administror!");
                System.Environment.Exit(0);
            }

            DealINI._inipath = AppDomain.CurrentDomain.BaseDirectory + "config.ini";

            ReadIni();

#if !DEBUG
            if (MD5Handler.verifyMd5Hash(_license))
            {
                _licensedPorduct = true;
            }

            _licensedPorduct = true;
#endif
#if DEBUG
            _licensedPorduct = true;
#endif

            if (!CheckServerAvailable(_server))
            {
                MessageBox.Show("Cant't connect server, please contact with administror!");
                System.Environment.Exit(0);
            }

            InitializeComponent();
        }
Exemplo n.º 3
0
        private async void submitButton_Click(object sender, EventArgs e)
        {
            string validateResult = validate();

            if (!validateResult.Equals(""))
            {
                ErrorForm errorForm = new ErrorForm(validateResult, "Ошибка валидации", false);
                errorForm.ShowDialog(Owner);
            }
            else
            {
                string resultString = await Task.Run(() => ApiRequests.LoginPost(emailTextBox.Text,
                                                                                 MD5Handler.GetMd5Hash(passwordTextBox.Text)));

                bool result = Parser.ResultParse(resultString);
                if (result)
                {
                    //добавить что-то дополнительное об успешности
                    Memory.isAuth = true;
                    Settings.SaveSettingsCrypt();
                    changeToMain();
                }
                else
                {
                    Error("Авторизация не удалась", closeApp: false);
                }
            }
        }
Exemplo n.º 4
0
        public HFDesk()
        {
            if (!System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "config.ini"))
            {
                MessageBox.Show("Cant't find configuration file, please contact with administror!");
                System.Environment.Exit(0);
            }

            DealINI._inipath = AppDomain.CurrentDomain.BaseDirectory + "config.ini";

            if (GetLicenseFromFile())
            {
                CheckLicense(_license);
            }

            //ReadIni();

#if !DEBUG
            if (MD5Handler.verifyMd5Hash(_license))
            {
                _licensedPorduct = true;
            }

            //_licensedPorduct = true;
#endif
#if DEBUG
            _licensedPorduct = true;
#endif

            /*
             *
             *
             *
             * if (!CheckServerAvailable(_server))
             * {
             *  MessageBox.Show("Cant't connect server, please contact with administror!");
             *  System.Environment.Exit(0);
             * }
             *
             */

            InitializeComponent();

            /*
             * this is avoid flicker
             */
            int style = NativeWinAPI.GetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE);
            style |= NativeWinAPI.WS_EX_COMPOSITED;
            NativeWinAPI.SetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE, style);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Determines whether the launchpad manifest is outdated.
        /// </summary>
        /// <returns><c>true</c> if the manifest is outdated; otherwise, <c>false</c>.</returns>
        private bool IsLaunchpadManifestOutdated()
        {
            if (File.Exists(ManifestHandler.GetLaunchpadManifestPath()))
            {
                string remoteHash = GetRemoteLaunchpadManifestChecksum();

                using (Stream file = File.OpenRead(ManifestHandler.GetLaunchpadManifestPath()))
                {
                    string localHash = MD5Handler.GetStreamHash(file);

                    return(remoteHash != localHash);
                }
            }
            else
            {
                return(true);
            }
        }
        /// <summary>
        /// Determines whether or not the local copy of the manifest for the specifed module is outdated.
        /// </summary>
        protected virtual bool IsModuleManifestOutdated(EModule Module)
        {
            string manifestPath;

            switch (Module)
            {
            case EModule.Launcher:
            {
                manifestPath = ManifestHandler.GetLaunchpadManifestPath();
                break;
            }

            case EModule.Game:
            {
                manifestPath = ManifestHandler.GetGameManifestPath();
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(Module), Module, "The module passed to RefreshModuleManifest was invalid.");
            }
            }

            if (File.Exists(manifestPath))
            {
                string remoteHash = GetRemoteModuleManifestChecksum(Module);
                using (Stream file = File.OpenRead(manifestPath))
                {
                    string localHash = MD5Handler.GetStreamHash(file);

                    return(remoteHash != localHash);
                }
            }

            return(true);
        }
Exemplo n.º 7
0
        private void button2_Click(object sender, EventArgs e)
        {
            string validateResult = validatePasswordChange();

            if (!validateResult.Equals(""))
            {
                Error(validateResult, closeApp: false);
                clearTextBox();
                return;
            }

            bool requestResult = Parser.ResultParse(ApiRequests.ProfilePasswordPut
                                                        (MD5Handler.GetMd5Hash(textBox3.Text), MD5Handler.GetMd5Hash(textBox4.Text)));

            if (requestResult)
            {
                Owner.popUC();
            }
            else
            {
                Error("Данные введены неправильно", closeApp: false);
                clearTextBox();
            }
        }
Exemplo n.º 8
0
        private void btn_register_Click(object sender, EventArgs e)
        {
            if (tbx_md5code.Text.Trim() == "")
            {
                MessageBox.Show("product key can't be empty!");
                return;
            }
            if (MD5Handler.verifyMd5Hash(tbx_md5code.Text))
            {
                m_bLicensed = true;

                DealINI.IniWriteValue("SETTING", "LICENSE", tbx_md5code.Text);

                groupBox1.Visible = !m_bLicensed;

                label3.Visible = m_bLicensed;

                HFDesk._licensedPorduct = true;
            }
            else
            {
                MessageBox.Show("product key is not correct!");
            }
        }
Exemplo n.º 9
0
 private bool CheckLicense(string license)
 {
     return(MD5Handler.verifyMd5Hash(license));
 }
Exemplo n.º 10
0
 public void TestHashStream()
 {
     Assert.AreEqual(ExpectedHash, MD5Handler.GetStreamHash(this.DataStream));
 }
        /// <summary>
        /// Downloads the file referred to by the specifed manifest entry.
        /// </summary>
        /// <param name="fileEntry">The entry to download.</param>
        /// <param name="module">The module that the entry belongs to.</param>
        /// <param name="oldFileEntry">The old entry, if one exists.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Will be thrown if the <see cref="EModule"/> passed to the function is not a valid value.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Will be thrown if the local path set in the <paramref name="fileEntry"/> passed to the function is not a valid value.
        /// </exception>
        protected virtual void DownloadManifestEntry(ManifestEntry fileEntry, EModule module, ManifestEntry oldFileEntry = null)
        {
            this.ModuleDownloadProgressArgs.Module = module;

            string baseRemoteURL;
            string baseLocalPath;

            switch (module)
            {
            case EModule.Launcher:
            {
                baseRemoteURL = this.Config.GetLauncherBinariesURL();
                baseLocalPath = ConfigHandler.GetTempLauncherDownloadPath();
                break;
            }

            case EModule.Game:
            {
                baseRemoteURL = this.Config.GetGameURL();
                baseLocalPath = this.Config.GetGamePath();
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(module), module,
                                                      "An invalid module value was passed to DownloadManifestEntry.");
            }
            }

            // Build the access strings
            string remoteURL = $"{baseRemoteURL}{fileEntry.RelativePath}";
            string localPath = $"{baseLocalPath}{fileEntry.RelativePath}";

            // Make sure we have a directory to put the file in
            if (!string.IsNullOrEmpty(localPath))
            {
                string localPathParentDir = Path.GetDirectoryName(localPath);
                if (!Directory.Exists(localPathParentDir))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(localPath));
                }
            }
            else
            {
                throw new ArgumentNullException(nameof(localPath), "The local path was null or empty.");
            }

            // Reset the cookie
            File.WriteAllText(ConfigHandler.GetGameCookiePath(), string.Empty);

            // Write the current file progress to the install cookie
            using (TextWriter textWriterProgress = new StreamWriter(ConfigHandler.GetGameCookiePath()))
            {
                textWriterProgress.WriteLine(fileEntry);
                textWriterProgress.Flush();
            }

            // First, let's see if an old file exists, and is valid.
            if (oldFileEntry != null)
            {
                // Check if the file is present, the correct size, and the correct hash
                if (oldFileEntry.IsFileIntegrityIntact())
                {
                    // If it is, delete it.
                    File.Delete(localPath);
                }
            }

            if (File.Exists(localPath))
            {
                FileInfo fileInfo = new FileInfo(localPath);
                if (fileInfo.Length != fileEntry.Size)
                {
                    // If the file is partial, resume the download.
                    if (fileInfo.Length < fileEntry.Size)
                    {
                        Log.Info($"Resuming interrupted file \"{Path.GetFileNameWithoutExtension(fileEntry.RelativePath)}\" at byte {fileInfo.Length}.");
                        DownloadRemoteFile(remoteURL, localPath, fileEntry.Size, fileInfo.Length);
                    }
                    else
                    {
                        // If it's larger than expected, toss it in the bin and try again.
                        Log.Info($"Restarting interrupted file \"{Path.GetFileNameWithoutExtension(fileEntry.RelativePath)}\": File bigger than expected.");

                        File.Delete(localPath);
                        DownloadRemoteFile(remoteURL, localPath, fileEntry.Size);
                    }
                }
                else
                {
                    string localHash;
                    using (FileStream fs = File.OpenRead(localPath))
                    {
                        localHash = MD5Handler.GetStreamHash(fs);
                    }

                    if (localHash != fileEntry.Hash)
                    {
                        // If the hash doesn't match, toss it in the bin and try again.
                        Log.Info($"Redownloading file \"{Path.GetFileNameWithoutExtension(fileEntry.RelativePath)}\": " +
                                 $"Hash sum mismatch. Local: {localHash}, Expected: {fileEntry.Hash}");

                        File.Delete(localPath);
                        DownloadRemoteFile(remoteURL, localPath, fileEntry.Size);
                    }
                }
            }
            else
            {
                // No file, download it
                DownloadRemoteFile(remoteURL, localPath, fileEntry.Size);
            }

            // We've finished the download, so empty the cookie
            File.WriteAllText(ConfigHandler.GetGameCookiePath(), string.Empty);
        }
Exemplo n.º 12
0
        private async void submitButton_Click(object sender, System.EventArgs e)
        {
            string validateResult = validate();

            if (!validateResult.Equals(""))
            {
                ErrorForm errorForm = new ErrorForm(validateResult, "Ошибка валидации", false);
                errorForm.ShowDialog(Owner);
            }
            else
            {
                try
                {
                    string resultString = await Task.Run(() => ApiRequests.RegistrationPost(loginTextBox.Text,
                                                                                            emailTextBox.Text, MD5Handler.GetMd5Hash(passwordTextBox.Text)));

                    bool result = Parser.ResultParse(resultString);
                    if (result)
                    {
                        //добавить что-то дополнительное об успешности
                        changeToLogin();
                    }
                    else
                    {
                        Error("Регистрация не удалась", closeApp: false);
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc);
                    Error("Не удалось выполнить запрос на регистрацию.", closeApp: false);
                }
            }
        }
Exemplo n.º 13
0
 public void HashesCorrectly()
 {
     Assert.Equal(ExpectedHash, MD5Handler.GetStreamHash(this.DataStream));
 }
Exemplo n.º 14
0
        /// <summary>
        /// Downloads the provided manifest entry.
        /// This function resumes incomplete files, verifies downloaded files and
        /// downloads missing files.
        /// </summary>
        /// <param name="Entry">The entry to download.</param>
        /// <param name="Module">The module to download the file for. Determines download location.</param>
        private void DownloadEntry(ManifestEntry Entry, EModule Module)
        {
            ModuleDownloadProgressArgs.Module = Module;

            string baseRemotePath;
            string baseLocalPath;

            if (Module == EModule.Game)
            {
                baseRemotePath = Config.GetGameURL();
                baseLocalPath  = Config.GetGamePath();
            }
            else
            {
                baseRemotePath = Config.GetLauncherBinariesURL();
                baseLocalPath  = ConfigHandler.GetTempLauncherDownloadPath();
            }

            string RemotePath = String.Format("{0}{1}",
                                              baseRemotePath,
                                              Entry.RelativePath);

            string LocalPath = String.Format("{0}{1}{2}",
                                             baseLocalPath,
                                             Path.DirectorySeparatorChar,
                                             Entry.RelativePath);

            // Make sure we have a directory to put the file in
            Directory.CreateDirectory(Path.GetDirectoryName(LocalPath));

            // Reset the cookie
            File.WriteAllText(ConfigHandler.GetInstallCookiePath(), String.Empty);

            // Write the current file progress to the install cookie
            using (TextWriter textWriterProgress = new StreamWriter(ConfigHandler.GetInstallCookiePath()))
            {
                textWriterProgress.WriteLine(Entry);
                textWriterProgress.Flush();
            }

            if (File.Exists(LocalPath))
            {
                FileInfo fileInfo = new FileInfo(LocalPath);
                if (fileInfo.Length != Entry.Size)
                {
                    // If the file is partial, resume the download.
                    if (fileInfo.Length < Entry.Size)
                    {
                        DownloadRemoteFile(RemotePath, LocalPath, fileInfo.Length);
                    }
                    else
                    {
                        // If it's larger than expected, toss it in the bin and try again.
                        File.Delete(LocalPath);
                        DownloadRemoteFile(RemotePath, LocalPath);
                    }
                }
                else
                {
                    string LocalHash;
                    using (FileStream fs = File.OpenRead(LocalPath))
                    {
                        LocalHash = MD5Handler.GetStreamHash(fs);
                    }

                    if (LocalHash != Entry.Hash)
                    {
                        File.Delete(LocalPath);
                        DownloadRemoteFile(RemotePath, LocalPath);
                    }
                }
            }
            else
            {
                //no file, download it
                DownloadRemoteFile(RemotePath, LocalPath);
            }

            if (ChecksHandler.IsRunningOnUnix())
            {
                //if we're dealing with a file that should be executable,
                string gameName = Config.GetGameName();
                bool   bFileIsGameExecutable = (Path.GetFileName(LocalPath).EndsWith(".exe")) || (Path.GetFileName(LocalPath) == gameName);
                if (bFileIsGameExecutable)
                {
                    //set the execute bits
                    UnixHandler.MakeExecutable(LocalPath);
                }
            }

            // We've finished the download, so empty the cookie
            File.WriteAllText(ConfigHandler.GetInstallCookiePath(), String.Empty);
        }
Exemplo n.º 15
0
        protected virtual void DownloadManifestEntry(ManifestEntry Entry, EModule Module)
        {
            ModuleDownloadProgressArgs.Module = Module;

            string baseRemoteURL;
            string baseLocalPath;

            switch (Module)
            {
            case EModule.Launcher:
            {
                baseRemoteURL = Config.GetLauncherBinariesURL();
                baseLocalPath = ConfigHandler.GetTempLauncherDownloadPath();
                break;
            }

            case EModule.Game:
            {
                baseRemoteURL = Config.GetGameURL();
                baseLocalPath = Config.GetGamePath();
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(Module), Module, "The module passed to DownloadManifestEntry was invalid.");
            }
            }

            // Build the access strings
            string remoteURL = $"{baseRemoteURL}{Entry.RelativePath}";
            string localPath = $"{baseLocalPath}{Path.DirectorySeparatorChar}{Entry.RelativePath}";

            // Make sure we have a directory to put the file in
            if (Path.GetDirectoryName(localPath) != null)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(localPath));
            }
            else
            {
                throw new ArgumentNullException(nameof(localPath), "The local path was null.");
            }

            // Reset the cookie
            File.WriteAllText(ConfigHandler.GetInstallCookiePath(), string.Empty);

            // Write the current file progress to the install cookie
            using (TextWriter textWriterProgress = new StreamWriter(ConfigHandler.GetInstallCookiePath()))
            {
                textWriterProgress.WriteLine(Entry);
                textWriterProgress.Flush();
            }

            if (File.Exists(localPath))
            {
                FileInfo fileInfo = new FileInfo(localPath);
                if (fileInfo.Length != Entry.Size)
                {
                    // If the file is partial, resume the download.
                    if (fileInfo.Length < Entry.Size)
                    {
                        Log.Info($"Resuming interrupted file \"{Path.GetFileNameWithoutExtension(Entry.RelativePath)}\" at byte {fileInfo.Length}.");
                        DownloadRemoteFile(remoteURL, localPath, Entry.Size, fileInfo.Length);
                    }
                    else
                    {
                        // If it's larger than expected, toss it in the bin and try again.
                        Log.Info($"Restarting interrupted file \"{Path.GetFileNameWithoutExtension(Entry.RelativePath)}\": File bigger than expected.");

                        File.Delete(localPath);
                        DownloadRemoteFile(remoteURL, localPath, Entry.Size);
                    }
                }
                else
                {
                    string localHash;
                    using (FileStream fs = File.OpenRead(localPath))
                    {
                        localHash = MD5Handler.GetStreamHash(fs);
                    }

                    if (localHash != Entry.Hash)
                    {
                        // If the hash doesn't match, toss it in the bin and try again.
                        Log.Info($"Redownloading file \"{Path.GetFileNameWithoutExtension(Entry.RelativePath)}\": " +
                                 $"Hash sum mismatch. Local: {localHash}, Expected: {Entry.Hash}");

                        File.Delete(localPath);
                        DownloadRemoteFile(remoteURL, localPath, Entry.Size);
                    }
                }
            }
            else
            {
                // No file, download it
                DownloadRemoteFile(remoteURL, localPath, Entry.Size);
            }

            if (ChecksHandler.IsRunningOnUnix())
            {
                // If we're dealing with a file that should be executable,
                string gameName = Config.GetGameName();
                bool   bFileIsGameExecutable = (Path.GetFileName(localPath).EndsWith(".exe")) || (Path.GetFileName(localPath) == gameName);
                if (bFileIsGameExecutable)
                {
                    // Set the execute bits
                    UnixHandler.MakeExecutable(localPath);
                }
            }

            // We've finished the download, so empty the cookie
            File.WriteAllText(ConfigHandler.GetInstallCookiePath(), string.Empty);
        }
Exemplo n.º 16
0
 /// <summary>
 ///     用户信息加密
 /// </summary>
 /// <param name="text"></param>
 /// <returns></returns>
 public static string Encrypt(string text)
 {
     return(MD5Handler.EnMD5(text));
 }