Ejemplo n.º 1
0
        private async Task <bool> InstallLatestVersionAsync()
        {
            try
            {
                Log.Debug($"Downloading remote setup {latestUri} ...");

                LatestInfo latestInfo = GetCachedLatestVersionInfo();
                if (latestInfo == null)
                {
                    // No installed version.
                    return(false);
                }

                using (HttpClient httpClient = GetHttpClient())
                {
                    string setupPath = await DownloadSetupAsync(httpClient, latestInfo);

                    InstallDownloadedSetup(setupPath);
                    return(true);
                }
            }
            catch (Exception e) when(e.IsNotFatal())
            {
                Log.Exception(e, "Failed to install new version");
            }

            return(false);
        }
Ejemplo n.º 2
0
        private async Task <bool> DownloadLatestVersionAsync()
        {
            try
            {
                Log.Info($"Downloading remote setup {latestUri} ...");

                LatestInfo latestInfo = GetCachedLatestVersionInfo();
                if (latestInfo == null)
                {
                    // No installed version.
                    return(false);
                }

                using (HttpClientDownloadWithProgress httpClient = GetDownloadHttpClient())
                {
                    await DownloadSetupAsync(httpClient, latestInfo);

                    return(true);
                }
            }
            catch (Exception e) when(e.IsNotFatal())
            {
                Log.Error($"Failed to install new version {e}");
            }

            return(false);
        }
Ejemplo n.º 3
0
        private static async Task <string> DownloadSetupAsync(
            HttpClientDownloadWithProgress httpClient, LatestInfo latestInfo)
        {
            Asset setupFileInfo = latestInfo.assets.First(a => a.name == $"{ProgramInfo.Name}Setup.exe");

            string downloadUrl = setupFileInfo.browser_download_url;

            Log.Info($"Downloading {latestInfo.tag_name} from {downloadUrl} ...");

            Timing t = Timing.Start();

            httpClient.ProgressChanged += (totalFileSize, totalBytesDownloaded, progressPercentage) =>
            {
                Log.Info($"Downloading {latestInfo.tag_name} {progressPercentage}% (time: {t.Elapsed}) ...");
            };

            string setupPath = ProgramInfo.GetSetupFilePath();

            if (File.Exists(setupPath))
            {
                File.Delete(setupPath);
            }

            await httpClient.StartDownloadAsync(downloadUrl, setupPath);

            Log.Info($"Downloaded {latestInfo.tag_name} to {setupPath}");
            return(setupPath);
        }
Ejemplo n.º 4
0
        private static async Task <string> DownloadSetupAsync(HttpClient httpClient, LatestInfo latestInfo)
        {
            Asset setupFileInfo = latestInfo.assets.First(a => a.name == "GitMindSetup.exe");

            string downloadUrl = setupFileInfo.browser_download_url;

            Log.Debug($"Downloading {latestInfo.tag_name} from {downloadUrl} ...");

            byte[] remoteFileData = await httpClient.GetByteArrayAsync(downloadUrl);

            string setupPath = ProgramInfo.GetTempFilePath() + "." + setupFileInfo.name;

            File.WriteAllBytes(setupPath, remoteFileData);

            Log.Debug($"Downloaded {latestInfo.tag_name} to {setupPath}");
            return(setupPath);
        }
Ejemplo n.º 5
0
    private IEnumerator GetLatestCoroutine(LatestReceivedCallback success, LatestFailedCallback failure, string path, int totalCount, bool mailinglist)
    {
        string url = "/api/messages/latest/" + path;

        UnityWebRequest request = UnityWebRequest.Get(Constants.serverAddress + url);

        request.chunkedTransfer = false;

        yield return(request.SendWebRequest());

        while (!request.isDone)
        {
            yield return(new WaitForEndOfFrame());
        }

        if (request.isNetworkError)
        {
            Debug.Log("Network error: Cannot get latest: " + request.error + ", Code = " + request.responseCode);
            if (failure != null)
            {
                failure();
            }
        }
        else if (request.isHttpError)
        {
            Debug.Log("Http error: Cannot get latest: " + request.error + ", Code = " + request.responseCode);
            if (failure != null)
            {
                failure();
            }
        }
        else
        {
            List <LatestInfo> latest = null;
            try
            {
                latest = new List <LatestInfo>();
                // Reprocess the info to a common format to make it unified for both cases
                if (mailinglist)
                {
                    List <LatestMailingListInfo> tmp = JsonConvert.DeserializeObject <List <LatestMailingListInfo> >(request.downloadHandler.text);
                    for (int i = 0; i < tmp.Count; ++i)
                    {
                        LatestInfo info = new LatestInfo();
                        info._id       = tmp[i].recipientList._id;
                        info.createdAt = tmp[i].createdAt;
                        latest.Add(info);
                    }
                }
                else
                {
                    List <LatestMessageInfo> tmp = JsonConvert.DeserializeObject <List <LatestMessageInfo> >(request.downloadHandler.text);
                    for (int i = 0; i < tmp.Count; ++i)
                    {
                        LatestInfo info = new LatestInfo();
                        info._id       = tmp[i].recipient._id;
                        info.createdAt = tmp[i].createdAt;
                        latest.Add(info);
                    }
                }
            } catch (Exception)
            {
                Debug.LogError("Warning: cannot get latest messages.");
            }
            if (latest != null)
            {
                m_LatestResults.AddRange(latest);

                m_LatestResultCount++;
                if (m_LatestResultCount == totalCount)
                {
                    m_LatestResults.Sort((m1, m2) => { return(MessageManager.ParseTimeStamp(m2.createdAt).CompareTo(MessageManager.ParseTimeStamp(m1.createdAt))); });
                    m_LatestResults = m_LatestResults.GetRange(0, Mathf.Min(m_LatestResults.Count, 10));

                    if (success != null)
                    {
                        success(m_LatestResults);
                    }
                }
            }
        }
    }