Beispiel #1
0
        public static void MoveFile(FtpMove ftpMove)
        {
            var ftpConfigDownload = new FtpDownload(new FtpConfig(new Uri($"{ftpMove.FtpConfig.Uri}/{ftpMove.From}"), ftpMove.FtpConfig.Login, ftpMove.FtpConfig.Password), ftpMove.FileName);
            var downloadContet    = DownloadFile(ftpConfigDownload);

            var ftpConfigMove = new FtpUpload(new FtpConfig(new Uri($"{ftpMove.FtpConfig.Uri}/{ftpMove.To}"), ftpMove.FtpConfig.Login, ftpMove.FtpConfig.Password), downloadContet, ftpMove.FileName);
            var ftpDelete     = new FtpDelete(new FtpConfig(new Uri($"{ftpMove.FtpConfig.Uri}/{ftpMove.From}"), ftpMove.FtpConfig.Login, ftpMove.FtpConfig.Password), ftpMove.FileName);

            DeleteFile(ftpDelete);

            UploadFile(ftpConfigMove);
        }
Beispiel #2
0
        public static byte[] DownloadFile(FtpDownload ftpDownload)
        {
            byte[] bytes = null;

            WebClient wc = new WebClient();

            wc.Credentials = new NetworkCredential(ftpDownload.FtpConfig.Login, ftpDownload.FtpConfig.Password);

            bytes = wc.DownloadData(string.Format(@"{0}/{1}",
                                                  ftpDownload.FtpConfig.Uri.ToString(),
                                                  ftpDownload.FileName));

            return(bytes);
        }
Beispiel #3
0
    private IEnumerator DownloadUpdate(string filePath)
    {
        DownloadPopup.Instance.message.text = "Fazendo o download da nova versão. Por favor, aguarde...";
        DownloadPopup.Instance.ShowPopup(true);
        DownloadPopup.Instance.buttom.onClick.AddListener(CancelDownload);

        //Get changelog from server
        string fileName = Path.GetFileName(filePath);

        fileName = IndexedFilename(Path.GetFileNameWithoutExtension(fileName), Path.GetExtension(fileName));

        client = null;
        //Check the type of the selected client
        if (clientType == ClientType.FtpClient)
        {
            client = FtpDownload.CreateNewInstance();
        }
        else if (clientType == ClientType.HttpClient)
        {
            client = HttpDownload.CreateNewInstance();
        }

        //Starts the Download process
        client.SetCredentials(username, password);
        client.Download(serverPath + "/" + filePath, FilesPath + fileName);
        while (!client.Done && !client.Failed)
        {
            DownloadPopup.Instance.SetProgress(client.Progress);
            yield return(null);
        }

        if (client.Failed)
        {
            DownloadPopup.Instance.message.text    = "O download falhou. Tente novamente mais tarde ou contate o suporte. Erro:" + client.ErrorMessage;
            DownloadPopup.Instance.buttonText.text = "Fechar";
        }
        else
        {
            DownloadPopup.Instance.ShowPopup(false);
            ChangelogPopup.Instance.Message          = "O arquivo " + fileName + " foi salvo em 'Downlaods'. Pressione 'Ok' para executar a intalação ou 'Fechar' para instalar posteriormente";
            ChangelogPopup.Instance.FirstButtonText  = "Ok";
            ChangelogPopup.Instance.SecondButtonText = "Fechar";
            AddToAndroidDownloads(fileName);
            ChangelogPopup.Instance.ShowPopup(true);
            ChangelogPopup.Instance.FirstButtom.onClick.AddListener(() => { RunFile(fileName); CancelDownload(); ChangelogPopup.Instance.ShowPopup(false); });
            ChangelogPopup.Instance.SecondButtom.onClick.AddListener(() => { CancelDownload(); ChangelogPopup.Instance.ShowPopup(false); });
        }
    }
Beispiel #4
0
    private IEnumerator CheckUpdates()
    {
        DownloadPopup.Instance.message.text = "Checando atualizações, Por favor, aguarde...";
        DownloadPopup.Instance.ShowPopup(true);
        DownloadPopup.Instance.buttom.onClick.AddListener(CancelDownload);

        //Check the type of the selected client
        client = null;
        if (clientType == ClientType.FtpClient)
        {
            client = FtpDownload.CreateNewInstance();
        }
        else if (clientType == ClientType.HttpClient)
        {
            client = HttpDownload.CreateNewInstance();
        }

        //Starts the download process
        client.SetCredentials(username, password);
        client.Download(serverPath + "/" + changelogFileName, "");
        while (!client.Done && !client.Failed)
        {
            DownloadPopup.Instance.SetProgress(client.Progress);
            yield return(null);
        }

        //Verify if the file download succeed
        if (client.Failed)
        {
            DownloadPopup.Instance.message.text    = "Falha ao verificar atualizações. Tente novamente mais tarde ou contate o suporte. Erro: " + client.ErrorMessage;
            DownloadPopup.Instance.buttonText.text = "Fechar";
        }
        else
        {
            DownloadPopup.Instance.ShowPopup(false);
        }

        //Each line on the file represent a new version and contains the information of the updates
        string str = System.Text.Encoding.UTF8.GetString(FtpDownload.Instance.Bytes);

        //Parse the first line which must contains the headers and the last line, which is the last version
        logsHistory = new List <string>(System.Text.RegularExpressions.Regex.Split(str, "\r\n|\r|\n"));
        string[] headers = null;
        string[] infos   = null;
        if (logsHistory.Count > 0)
        {
            headers = logsHistory[0].Split(':');
            infos   = logsHistory[logsHistory.Count - 1].Split(':');
            for (int i = 0; i < headers.Length && i < infos.Length; i++)
            {
                changes.Add(headers[i], infos[i]);
            }
        }


        string version;

        //Compare if the last version from the file is higher than the current running
        if (changes.TryGetValue("versao", out version) && version.CompareTo(currentVersion) == 1)
        {
            string fileName;
            changes.TryGetValue(headers[0], out fileName);

            string message = FileExists(FilesPath + fileName)? "Um arquivo referente à atualização detectada já existe. Gostaria de fazer o download novamente?\n":
                             "Uma nova versão foi detectada. Gostaria de iniciar o download?\n";

            ChangelogPopup.Instance.Message = message +
                                              "\nVersão disponível: " + changes["versao"] + "\n" +
                                              "\nData: " + changes["data"] + "\n" +
                                              "\nMudanças detectadas:\n";
            string[] updates = changes["updates"].Split(',');
            foreach (string s in updates)
            {
                ChangelogPopup.Instance.Message += "- " + s + "\n";
            }

            int response = 0;
            ChangelogPopup.Instance.FirstButtonText  = "Sim";
            ChangelogPopup.Instance.SecondButtonText = "Não";
            ChangelogPopup.Instance.FirstButtom.onClick.AddListener(() => { response = 1; });
            ChangelogPopup.Instance.SecondButtom.onClick.AddListener(() => { response = 2; });
            ChangelogPopup.Instance.ShowPopup(true);

            //Wait until the user choose an option
            yield return(new WaitUntil(() => response != 0));

            ChangelogPopup.Instance.ShowPopup(false);
            if (response == 1)
            {
                StartCoroutine(DownloadUpdate(fileName));
            }
            //Ask if the user wnats to execute the file, if it already exists and he choose to not download again
            else if (FileExists(FilesPath + fileName))
            {
                ChangelogPopup.Instance.Message          = "Gostaria de executar o arquivo encontrado?";
                ChangelogPopup.Instance.FirstButtonText  = "Sim";
                ChangelogPopup.Instance.SecondButtonText = "Não";
                ChangelogPopup.Instance.FirstButtom.onClick.AddListener(() => { RunFile(fileName); ChangelogPopup.Instance.ShowPopup(false);  onFinished.Invoke(); });
                ChangelogPopup.Instance.SecondButtom.onClick.AddListener(() => { ChangelogPopup.Instance.ShowPopup(false); onFinished.Invoke(); });
                ChangelogPopup.Instance.ShowPopup(true);
            }
            else
            {
                onFinished.Invoke();
            }
        }
        else
        {
            onFinished.Invoke();
        }
    }