示例#1
0
        private void imageDownloadBtn_Click(object sender, RoutedEventArgs e)
        {
            ChanCatalogThread cct = threadLst.SelectedValue as ChanCatalogThread;

            string path = string.IsNullOrEmpty(Properties.Settings.Default.RootFolder) ? "DUMP" : Properties.Settings.Default.RootFolder;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            string allPath = Path.Combine(path, "[ALL]");

            if (!Directory.Exists(allPath))
            {
                Directory.CreateDirectory(allPath);
            }

            string topicPath = Path.Combine(path, string.Format("{0}-{1}", cct.BoardSlug, cct.ThreadId));

            if (!Directory.Exists(topicPath))
            {
                Directory.CreateDirectory(topicPath);
            }


            List <Task> tl = new List <Task>();

            foreach (ChanPostFile item in imageLst.SelectedItems)
            {
                string itemPath = Path.Combine(allPath, string.Format("{0}{1}", item.MD5String, item.Extension));

                if (!File.Exists(itemPath))
                {
                    using (WebClient wc = new WebClient())
                    {
                        var dlTask = wc.DownloadFileTaskAsync(item.Uri, itemPath);
                        tl.Add(dlTask);
                    }
                }

                string linkPath = Path.Combine(topicPath, string.Format("{0}{1}", item.Name, item.Extension));

                if (!File.Exists(linkPath))
                {
                    InteropHelper.CreateHardLink(linkPath, itemPath, IntPtr.Zero);
                }
            }

            Task.WhenAll(tl).ContinueWith((t) =>
            {
                Dispatcher.Invoke(() =>
                {
                    MessageBox.Show("COMPLETE");
                });
            });
        }