public Task Extract(NFSFile file) { if (working) { throw new InvalidOperationException("operation is already running"); } if (file == null) { throw new ArgumentNullException("file"); } //return extractFile(file) // .ContinueWith(t => // { // if (t.IsFaulted) // throw t.Exception.Flatten(); // string destFolder = checkDirectory(file); // moveFile(file, destFolder); // }); string filename; if (file.Order > 0) { filename = string.Format("{0} {1}", file.Name, file.Order + 1); } else { filename = file.Name; } return(unpackFile(filename) .ContinueWith(t => { if (t.IsFaulted) { if (file.Order > 0) { try { //retry with default order 0 unpackFile(file.Name).Wait(); } catch { throw; } } else { throw t.Exception.Flatten(); } } string destFolder = checkDirectory(file); moveFile(file, destFolder); })); }
public FileData(NFSFile file, FolderData parentFolder) : base(parentFolder) { if (file == null) { throw new ArgumentNullException("file"); } this.source = file; this.name = file.Name; this.filename = file.Filename; this.extension = file.Extension; this.size = formatSize(file.Size); }
//if file already in dest, it will be overwritten private void moveFile(NFSFile file, string destFolder) { string filename = file.Name; string order = null; if (file.Order > 0) { order = (file.Order + 1).ToString(); } string sourceFile = Path.Combine(this.rootPath, filename + order); string destFile = Path.Combine(destFolder, filename); File.Copy(sourceFile, destFile, true); File.Delete(sourceFile); }
private string checkDirectory(NFSFile file) { List <string> folders = new List <string>(); var folder = file.Folder; while (folder != null) { folders.Add(folder.Name); folder = folder.ParentFolder; } string path = string.Join("\\", folders.Reverse <string>()); string dest = Path.Combine(this.rootPath, path); if (!Directory.Exists(dest)) { Directory.CreateDirectory(dest); } return(dest); }
private Task extractFile(NFSFile file) { //order start from 1 in extractor, and hide if it's first file. //such as for first xxx.xxx use origin name, for second use xxx.xxx 2 //this.invoker.Invoke( // string.Format("{0} {1}", file.Name, file.Order + 1)); string filename; if (file.Order > 0) { filename = string.Format("{0} {1}", file.Name, file.Order + 1); } else { filename = file.Name; } return(unpackFile(filename)); //this.invoker.Invoke(filename); //this.nfsReadBlock = new AutoResetEvent(false); //return Task.Factory.StartNew(() => //{ // this.nfsReadBlock.WaitOne(); // this.nfsReadBlock.Dispose(); // this.nfsReadBlock = null; // this.working = false; // var result = this.result; // if (result.HasError) // throw new Exception("error occurred while extract nfs file: " + result.Error); //}); }