Exemple #1
0
        private void Window_Drop(object sender, DragEventArgs e)
        {
            if (string.IsNullOrEmpty(Dest.Value))
            {
                MessageBox.Show(this, $"フォルダーが設定されていないよう");
                return;
            }
            var dest    = Dest.Value;
            var move    = Move.Value;
            var targets = from k in e.Data.GetData(DataFormats.FileDrop) as string[]
                          where File.Exists(k)
                          select new FileInfo(k);

            if (targets.Count() == 0)
            {
                return;
            }
            TotalFiles.Value = targets.Count();
            Progress.Value   = 0;
            spool.Schedule(t =>
            {
                busy = true;
                foreach (var n in targets)
                {
                    Dispatcher.Invoke(() => Progress.Value = Progress.Value + 1);
                    n.Refresh();
                    var d = new FileInfo(System.IO.Path.Combine(dest, n.Name));
                    if (!n.Exists || n.FullName.Equals(d.FullName, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    if (d.Exists)
                    {
                        if (葱.比較(n, d))
                        {
                            continue;
                        }
                        if ((d = Rename(d.FullName)) == null)
                        {
                            continue;
                        }
                    }

                    if (move)
                    {
                        File.Move(n.FullName, d.FullName);
                    }
                    else
                    {
                        File.Copy(n.FullName, d.FullName);
                    }
                }
            }, t =>
            {
                busy           = false;
                Progress.Value = 0;
            });
        }
Exemple #2
0
        private void WriteFileAsync(string path)
        {
            spool.Schedule(token =>
            {
                bool cancel = false;
                Dispatcher.Invoke(() => lblFileStat.Content = $"Task: {spool.TaskCount}");

                if (File.Exists(path))
                {
                    return;
                }

                var free = Nira.GetDriveFreeSpace(rootDir.FullName);
                if (free < blockZise * blockCount)
                {
                    WriteFile(path, free);
                    return;
                }
                rand.NextBytes(writeBuffer);
                var tmp = tmpDir.FullName + $"\\{Guid.NewGuid().ToString()}...mp4";
                using (var fs = new FileStream(tmp, FileMode.OpenOrCreate)) {
                    for (int i = 0; i < blockCount; ++i)
                    {
                        if (token.IsCancellationRequested)
                        {
                            cancel = true;
                            Debug.WriteLine($"CancellationRequested");
                            break;
                        }
                        fs.Write(writeBuffer, 0, writeBuffer.Length);
                    }
                    fs.Flush();
                }
                File.Move(tmp, path);
                FixTimestamp(path);
                return;
            },
                           token => {
                Dispatcher.Invoke(() => lblFileStat.Content = $"Task: {spool.TaskCount}");
            });
        }