Exemple #1
0
        public FormRelease(ProjectInfo projectInfo)
        {
            InitializeComponent();

            m_project = projectInfo;

            m_loveVersion         = new LoveVersion();
            m_loveVersion.Type    = projectInfo.m_type;
            m_loveVersion.Version = LoveVersion.GetInstalledVersion(projectInfo.m_type);

            m_tasks = new List <Task>();

            if (File.Exists(GetVersionPath("win32")))
            {
                m_loveVersion.Download_Win32 = "..";
            }
            if (File.Exists(GetVersionPath("win64")))
            {
                m_loveVersion.Download_Win64 = "..";
            }
            if (File.Exists(GetVersionPath("macos")))
            {
                m_loveVersion.Download_MacOS = "..";
            }

            if (!m_loveVersion.HasAllDownloads())
            {
                labelStatus.Text = "Finding version downloads for " + m_loveVersion.Version + "...";

                var wc = new WebClient();
                wc.DownloadStringCompleted += (o, e) => {
                    if (e.Error != null)
                    {
                        MessageBox.Show(this, "There was a problem fetching the Love2D downloads list from Github: " + e.Error.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Close();
                        return;
                    }

                    var arrValues = (ArrayList)Json.JsonDecode(e.Result);
                    foreach (Hashtable value in arrValues)
                    {
                        var version = (string)value["tag_name"];
                        var assets  = (ArrayList)value["assets"];

                        if (version != m_loveVersion.Version)
                        {
                            continue;
                        }

                        foreach (Hashtable asset in assets)
                        {
                            var contentType = (string)asset["content_type"];
                            if (contentType != "application/zip" && contentType != "application/x-zip-compressed")
                            {
                                continue;
                            }

                            var filename = (string)asset["name"];
                            var platform = "";

                            if (m_loveVersion.Type == LoveType.Love2D)
                            {
                                // "love-11.3-macos.zip"
                                // "love-11.3-win32.zip"
                                // "love-11.3-win64.zip"
                                var matchVersion = Regex.Match(filename, @"^love-[^\-]+-([^\.]+)\.zip$");
                                if (!matchVersion.Success)
                                {
                                    continue;
                                }

                                platform = matchVersion.Groups[1].Value;
                            }
                            else if (m_loveVersion.Type == LoveType.Lovr)
                            {
                                // "lovr-v0.12.0-windows-32.zip"
                                // "lovr-v0.13.0-windows-64.zip"
                                var matchVersion = Regex.Match(filename, @"^lovr-[^\-]+-([^\.]+)\.zip$");
                                if (!matchVersion.Success)
                                {
                                    continue;
                                }

                                platform = matchVersion.Groups[1].Value;
                            }

                            var url = (string)asset["browser_download_url"];

#if DEBUG
                            Console.WriteLine("Possible version: {0} (platform {1})", filename, platform);
#endif

                            if (platform == "win64" || platform == "windows-64")
                            {
                                m_loveVersion.Download_Win64 = url;
                            }
                            else if (platform == "win32" || platform == "windows-32")
                            {
                                m_loveVersion.Download_Win32 = url;
                            }
                            else if (platform == "macos")
                            {
                                m_loveVersion.Download_MacOS = url;
                            }
                        }

                        FoundVersions(true);
                    }
                };
                wc.Headers[HttpRequestHeader.UserAgent] = "Loveman / nimble.tools";

                switch (m_loveVersion.Type)
                {
                case LoveType.Love2D: wc.DownloadStringAsync(new Uri(URL_LOVE_DOWNLOADS)); break;

                case LoveType.Lovr: wc.DownloadStringAsync(new Uri(URL_LOVR_DOWNLOADS)); break;
                }
            }

            Interface.InterfaceTheme(this);
        }