コード例 #1
0
ファイル: Stats.cs プロジェクト: Lukelluke/FallGuysStats
        private void menuUpdate_Click(object sender, EventArgs e)
        {
            try {
                string assemblyInfo = null;
                using (ZipWebClient web = new ZipWebClient()) {
                    assemblyInfo = web.DownloadString(@"https://raw.githubusercontent.com/ShootMe/FallGuysStats/master/Properties/AssemblyInfo.cs");

                    int index = assemblyInfo.IndexOf("AssemblyVersion(");
                    if (index > 0)
                    {
                        int     indexEnd   = assemblyInfo.IndexOf("\")", index);
                        Version newVersion = new Version(assemblyInfo.Substring(index + 17, indexEnd - index - 17));
                        if (newVersion > Assembly.GetEntryAssembly().GetName().Version)
                        {
                            if (MessageBox.Show(this, $"There is a new version of Fall Guy Stats available (v{newVersion.ToString(2)}). Do you wish to update now?", "Update Program", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                            {
                                byte[] data    = web.DownloadData($"https://raw.githubusercontent.com/ShootMe/FallGuysStats/master/FallGuyStats.zip");
                                string exeName = null;
                                using (MemoryStream ms = new MemoryStream(data)) {
                                    using (ZipArchive zipFile = new ZipArchive(ms, ZipArchiveMode.Read)) {
                                        foreach (var entry in zipFile.Entries)
                                        {
                                            if (entry.Name.IndexOf(".exe", StringComparison.OrdinalIgnoreCase) > 0)
                                            {
                                                exeName = entry.Name;
                                            }
                                            File.Move(entry.Name, $"{entry.Name}.old");
                                            entry.ExtractToFile(entry.Name, true);
                                        }
                                    }
                                }

                                Process.Start(new ProcessStartInfo(exeName));
                                this.Close();
                            }
                        }
                        else
                        {
                            MessageBox.Show(this, "You are at the latest version.", "Updater", MessageBoxButtons.OK, MessageBoxIcon.None);
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "Could not determine version.", "Error Updating", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show(this, ex.ToString(), "Error Updating", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        private void SendNDI()
        {
#if AllowUpdate
            try {
                lock (GlobalFont) {
                    if (NDISender == null)
                    {
                        NDISender = new Sender("Fall Guys Stats Overlay", true, false, null, "Fall Guys Stats Overlay");
                    }
                    if (NDIFrame == null)
                    {
                        NDIFrame = new VideoFrame(Background.Width, Background.Height, (float)Background.Width / Background.Height, 20, 1);
                    }
                    if (NDIImage == null)
                    {
                        NDIImage = new Bitmap(NDIFrame.Width, NDIFrame.Height, NDIFrame.Stride, PixelFormat.Format32bppPArgb, NDIFrame.BufferPtr);
                    }
                    if (NDIGraphics == null)
                    {
                        NDIGraphics = Graphics.FromImage(NDIImage);
                        NDIGraphics.SmoothingMode = SmoothingMode.AntiAlias;
                    }

                    NDIGraphics.Clear(Color.Transparent);
                    NDIGraphics.DrawImage(Background, 0, 0);

                    foreach (Control control in Controls)
                    {
                        if (control is TransparentLabel label)
                        {
                            NDIGraphics.TranslateTransform(label.Location.X, label.Location.Y);
                            label.Draw(NDIGraphics);
                            NDIGraphics.TranslateTransform(-label.Location.X, -label.Location.Y);
                        }
                    }

                    NDISender.Send(NDIFrame);
                }
            } catch (Exception ex) {
                if (ex.Message.IndexOf("Unable to load dll", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    StatsForm.CurrentSettings.UseNDI = false;
                    Cleanup();
                    if (triesToDownload < 5)
                    {
                        triesToDownload++;
                        Task.Run(delegate() {
                            try {
                                using (ZipWebClient web = new ZipWebClient()) {
                                    byte[] data = web.DownloadData($"https://raw.githubusercontent.com/ShootMe/FallGuysStats/master/NDI.zip");
                                    using (MemoryStream ms = new MemoryStream(data)) {
                                        using (ZipArchive zipFile = new ZipArchive(ms, ZipArchiveMode.Read)) {
                                            foreach (var entry in zipFile.Entries)
                                            {
                                                entry.ExtractToFile(entry.Name, true);
                                            }
                                        }
                                    }
                                }
                                StatsForm.CurrentSettings.UseNDI = true;
                            } catch {
                                Thread.Sleep(10000);
                            }
                        });
                    }
                }
            }
#endif
        }