コード例 #1
0
        private async Task DownloadIMGFiles(string folderPath, List <string> fileNames)
        {
            DirectoryInfo directory     = new DirectoryInfo(folderPath);
            List <string> existingFiles = new List <string>();

            foreach (FileInfo info in directory.GetFiles())
            {
                existingFiles.Add(info.Name);
            }

            List <string> downloadFileNames = new List <string>();

            foreach (string fileName in fileNames)
            {
                if (!existingFiles.Contains(fileName))
                {
                    downloadFileNames.Add(fileName);
                }
            }

            foreach (string fileName in downloadFileNames)
            {
                StringBuilder urlStr = new StringBuilder();
                if (folderPath.Equals(SystemEnv.DefaultFolderPath))
                {
                    urlStr.AppendFormat(@"{0}/{1}/{2}/{3}",
                                        HTTPPacket.Url_IMG_Downlaod,
                                        Download_Type_Default,
                                        fileName,
                                        "0");
                }
                else
                {
                    urlStr.AppendFormat(@"{0}/{1}/{2}/{3}",
                                        HTTPPacket.Url_IMG_Downlaod,
                                        Download_Type_User,
                                        fileName,
                                        SystemEnv.GetProductKey());
                }
                string filePath = folderPath + @"/" + fileName;
                Console.WriteLine("> Downlaod Url : {0}", urlStr);
                await httpClient.DownloadFile(new Uri(urlStr.ToString()), filePath);
            }
        }