private void GetFileSize(String file , ref UInt64 bytes) { IFileInfo fi = IOServices.GetFileInfo(file); bytes += fi.Length; }
private Boolean CheckForPartner(String currentFile , Boolean toHD) { Boolean valid = true; IFileInfo fi = IOServices.GetFileInfo(currentFile); String fileWithoutExtension = fi.Name.Substring(0, fi.Name.LastIndexOf(".")); if ((fileWithoutExtension.EndsWith(".480")) || (fileWithoutExtension.EndsWith(".720")) || (fileWithoutExtension.EndsWith(".1080"))) { fileWithoutExtension = fileWithoutExtension.Substring(0, fileWithoutExtension.LastIndexOf(".")); } IEnumerable <String> partners = toHD ? GetHDExtensions() : GetSDExtensions(); foreach (String partner in partners) { String folder = fi.FolderName + @"\..\" + (toHD ? "HD" : "SD"); String fileInQuestion = folder + @"\" + fileWithoutExtension + partner; if (IOServices.File.Exists(fileInQuestion)) { valid = false; break; } } return(valid); }
private void AddFiles() { OpenFileDialogOptions options = new OpenFileDialogOptions(); options.CheckFileExists = true; options.Filter = "Film files|*.avi;*.srt;*.mkv;*.mp4;*.flv|Recent files|RecentFiles.*.xml|All files|*.*"; options.InitialFolder = LastFolder; options.Title = "Select File(s) to Copy"; String[] fileNames; if (UIServices.ShowOpenFileDialog(options, out fileNames)) { LastFolder = IOServices.GetFileInfo(fileNames[0]).FolderName; foreach (String file in fileNames) { if ((file.Contains("RecentFiles")) && (file.EndsWith(".xml"))) { Model.ReadXml(file); TryAutoApplyFilter(); } else { Model.AddEntry(file); } } RaiseFileEntriesChanged(); } }
public void Copy(String targetLocation , String overwrite , CancellationToken cancellationToken) { TargetLocation = targetLocation; Overwrite = overwrite; CancellationToken = cancellationToken; ProgressValue = 0; List <SourceTarget> fileInfos = new List <SourceTarget>(); foreach (String entry in Entries) { if (IOServices.Folder.Exists(entry)) { IEnumerable <String> files = IOServices.Folder.GetFiles(entry, searchOption: System.IO.SearchOption.AllDirectories); fileInfos.AddRange(files.Select(file => new SourceTarget(IOServices.GetFileInfo(file)))); } else if (IOServices.File.Exists(entry)) { fileInfos.Add(new SourceTarget(IOServices.GetFileInfo(entry))); } else { UIServices.ShowMessageBox("Something is weird about\n" + entry, "?!?", Buttons.OK, Icon.Error); return; } } ResetSize(); IDriveInfo driveInfo = IOServices.GetDriveInfo(IOServices.GetFolderInfo(TargetLocation).Root.Name.Substring(0, 1)); if (driveInfo.AvailableFreeSpace <= Size) { FileSize spaceSize = new FileSize(driveInfo.AvailableFreeSpace); FileSize bytesSize = new FileSize(Size); UIServices.ShowMessageBox($"Target is Full!{Environment.NewLine}Available: {spaceSize}{Environment.NewLine}Needed: {bytesSize}", "Target Full", Buttons.OK, Icon.Warning); return; } Copy(fileInfos); ProgressValue = 0; App.WasCopied = true; }
private void ReadLastRecentFile() { String recentFile = IOServices.Path.Combine(Properties.Settings.Default.SourcePath, "_RecentFiles", "RecentFiles.xml"); if (IOServices.File.Exists(recentFile)) { Model.ReadXml(recentFile); LastFolder = IOServices.GetFileInfo(recentFile).FolderName; } SaschasFunction(); TryAutoApplyFilter(); }
private Boolean CommenceCopy(List <SourceTarget> fileInfos) { foreach (SourceTarget fileInfo in fileInfos) { if (CancellationToken.IsCancellationRequested) { UIServices.ShowMessageBox("The Copy process was aborted.", String.Empty, Buttons.OK, Icon.Warning); return(true); } String path = IOServices.Path.Combine(fileInfo.TargetFolder.FullName, fileInfo.SourceFile.Name); IFileInfo targetFileInfo = IOServices.GetFileInfo(path); Result result = GetOverwriteResult(fileInfo, targetFileInfo); if (result == Result.Cancel) { return(true); } else if (result == Result.No) { m_Size -= fileInfo.SourceFile.Length; SizeChanged?.Invoke(this, EventArgs.Empty); continue; } else if (result == Result.Yes) { try { if (IOServices.File.Exists(targetFileInfo.FullName)) { IOServices.File.SetAttributes(targetFileInfo.FullName, System.IO.FileAttributes.Normal | System.IO.FileAttributes.Archive); } IOServices.File.Copy(fileInfo.SourceFile.FullName, targetFileInfo.FullName, true); } catch (Exception ex) { Int64 startTicks = DateTime.Now.Ticks; if (UIServices.ShowMessageBox(ex.Message + "\nContinue?", "Continue?", Buttons.YesNo, Icon.Question) == Result.Yes) { Int64 endTicks = DateTime.Now.Ticks; TimeSpan span = new TimeSpan(endTicks - startTicks); CopyPaused?.Invoke(this, new EventArgs <TimeSpan>(span)); continue; } else { return(true); } } ProgressValue += fileInfo.SourceFile.Length; ProgressChanged?.Invoke(this, EventArgs.Empty); } } return(false); }