Ejemplo n.º 1
0
        private void MainForm_Shown(object sender, EventArgs ea)
        {
            // Looking for xrCore...
            _corePath        = "xrCore.dll";
            dx9LUse.Checked  = (Properties.Settings.Default.RenderMode == "r2");
            dx9FUse.Checked  = (Properties.Settings.Default.RenderMode == "r2.5");
            dx11FUse.Checked = (Properties.Settings.Default.RenderMode == "r4");

            if (!File.Exists(_corePath))
            {
                if (!Properties.Settings.Default.isRememberLibPath || !File.Exists(Properties.Settings.Default.xrCorePath))
                {
                    if (searchCoreDialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    _corePath = searchCoreDialog.FileName;

                    if (Properties.Settings.Default.isRememberLibPath)
                    {
                        Properties.Settings.Default.xrCorePath = _corePath;
                        Properties.Settings.Default.Save();
                    }
                }
                else
                {
                    _corePath = Properties.Settings.Default.xrCorePath;
                }
            }
            tbWorkingDir.Text = (Properties.Settings.Default.WorkDir == "nullptr") ? Path.GetDirectoryName(_corePath)
                                                                                                   : Properties.Settings.Default.WorkDir;

            // Retrieving local commit info...
            string localHash = string.Empty;

            try
            {
                localHash = Utils.GetLocalReleaseHash(_corePath);
            }

            catch (Exception ex) when(ex is ENoCore || ex is ENoEntryPoint)
            {
                lcommitText.Text   = ex.Message;
                lcommitDate.Text   = DateTime.Now.ToString();
                lcommitAuthor.Text = "";
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                lcommitDate.Text   = DateTime.Now.ToString();
                lcommitAuthor.Text = "";
            }

            Release        localReleaseInfo = null;
            CommitResponse localCommitInfo  = null;

            if (!string.IsNullOrEmpty(localHash))
            {
                // Getting info for local release from GitHub

                localReleaseInfo = Utils.GetReleaseByHash(localHash);

                if (localReleaseInfo != default(Release))
                {
                    gbLocal.Text = localReleaseInfo.Name;

                    lcommitText.Text = string.IsNullOrWhiteSpace(localReleaseInfo.Message)
                        ? "No description available"
                        : localReleaseInfo.Message.Replace("\r\n", Environment.NewLine);

                    lcommitDate.Text   = localReleaseInfo.PublishedDate.ToString(CultureInfo.InvariantCulture);
                    lcommitAuthor.Text = localReleaseInfo.Author.Login;
                    lcommiteeAvatar.LoadAsync(localReleaseInfo.Author.Avatar);
                }
                else
                {
                    // get info about release commit, if didn't find in releases

                    localCommitInfo = OxyCommitParser.GetCommitByHash(localHash);

                    if (localCommitInfo != default(CommitResponse))
                    {
                        lcommitText.Text = HelperTextGen(localCommitInfo.CommitInfo.Message);
                        lcommitDate.Text =
                            localCommitInfo.CommitInfo.AuthorDetails.Date.ToString(CultureInfo.InvariantCulture);
                        lcommitAuthor.Text = localCommitInfo.Author.Login;
                        lcommiteeAvatar.LoadAsync(localCommitInfo.Author.Avatar);
                    }
                    else
                    {
                        MessageBox.Show(string.Format(ErrorMessage, "Error in getting local commit info"));
                    }
                }
            }

            ManageLatestRelease(localHash, localReleaseInfo, localCommitInfo);

            if (!CheckLastDump())
            {
                CheckLastLog();
            }
        }
Ejemplo n.º 2
0
        private void UpdateLocalRelease(string localHash, Release latestRelease, Release localReleaseInfo, CommitResponse localCommitInfo)
        {
            bool isUpToDate = latestRelease.Hash.StartsWith(localHash);

            // Ask for update if not up to date...
            if (localReleaseInfo != null && latestRelease.PublishedDate <= localReleaseInfo.PublishedDate)
            {
                if (isUpToDate || latestRelease.Assets.Length == 0 || localCommitInfo != null)
                {
                    return;
                }
            }

            if (MessageBox.Show("Update to recent release?", "Update", MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            // Do download...
            Asset asset =
                latestRelease.Assets.FirstOrDefault(ast => ast.Url.EndsWith(".zip") || ast.Url.EndsWith(".7z"));

            if (asset == default(Asset))
            {
                rcommitText.Text = "Unable to find release zip file!";
                return;
            }

            // Prepare...
            _tempFile = Path.GetTempPath();
            if (_tempFile.EndsWith("\\") == false)
            {
                _tempFile += "\\";
            }

            string unixTimeNow = ((int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();

            _tempDir = $"{_tempFile}oxy_{unixTimeNow}\\";
            string[] parts = asset.Url.Split('.');
            string   ext   = parts[parts.Length - 1];

            _tempFile += unixTimeNow + "_oxy." + ext;

            // Download and unpack on download complete
            DownloadUpdate(asset.Url, _tempFile);
        }