示例#1
0
            public void Download(string Patch, string UrlFile, string Password = null, byte MaxFilesUpload = 1, FunctionAndSetting.Massenge massenge = null)
            {
                if (!Directory.Exists(Patch))
                {
                    if (massenge != null)
                    {
                        massenge.Invoke("[-] Неправильно указан путь к директории\r\n", ConsoleColor.Red);
                    }
                    return;
                }
                // Качаем главный файл
                try
                {
                    BdDirectory bdDirectory = JsonConvert.DeserializeObject <BdDirectory>(Encoding.UTF8.GetString(functionAndSetting.DeCompress(functionAndSetting.Download(UrlFile), Password)));
                    if (bdDirectory.UploadetFiles.Count <= 0)
                    {
                        if (massenge != null)
                        {
                            massenge.Invoke("[Error] Ошибка получения главного файла", ConsoleColor.Red);
                        }
                        return;
                    }
                    else
                    {
                        TemporaryFileInfoSaved = Path.Combine(Patch, functionAndSetting.GetKeyFile(UrlFile) + FunctionAndSetting.ExpansionDownloadDirectory);
                        List <string> maskDownload = new List <string>(0);
                        if (File.Exists(TemporaryFileInfoSaved))
                        {
                            string[] res = File.ReadAllText(TemporaryFileInfoSaved).Split("\r\n");
                            for (long i = 1; i < res.LongLength; i++)
                            {
                                maskDownload.Add(res[i]);
                            }
                        }
                        else
                        {
                            File.WriteAllText(TemporaryFileInfoSaved, null);
                        }
                        DownloadFile downloadFile = new DownloadFile(functionAndSetting);
                        foreach (var Elem in bdDirectory.UploadetFiles)
                        {
                            if (!maskDownload.Contains(Elem.ResulUploadFileInfo.UrlSave))
                            {
                                // Проверяем является запись пустой папкой
                                if (Elem.ResulUploadFileInfo.UrlSave == null)
                                {
                                    Directory.CreateDirectory((Elem.SaveDirectory != null && Elem.SaveDirectory.Length > 0 && Elem.SaveDirectory.Replace('/', '\\')[0] == '\\') ? Path.Combine(Patch, Elem.SaveDirectory.Remove(0, 1)) : Path.Combine(Patch, Elem.SaveDirectory));
                                }
                                else
                                {
                                    string PatchSave = GetPatchLocal(Elem.SaveDirectory) != null?Path.Combine(Patch, GetPatchLocal(Elem.SaveDirectory)) : Patch;

                                    Directory.CreateDirectory(PatchSave);
                                    downloadFile.DownloadHendler(Elem.ResulUploadFileInfo.UrlSave, PatchSave, Path.GetFileName(Elem.SaveDirectory), MaxFilesUpload, Elem.Password, massenge);
                                }
                                resSevInfo : try { File.AppendAllText(TemporaryFileInfoSaved, "\r\n" + Elem.ResulUploadFileInfo.UrlSave); } catch { goto resSevInfo; }
                            }
                        }
                    }
                    resDel : try { if (File.Exists(TemporaryFileInfoSaved))
                                   {
                                       File.Delete(TemporaryFileInfoSaved);
                                   }
                    } catch { goto resDel; }
                }
                catch (Exception e)
                {
                    if (massenge != null)
                    {
                        massenge.Invoke("[Error] Ошибка получения главного файла", ConsoleColor.Red);
                    }
                    return;
                }
            }