/// <summary> /// Loads the specified files. /// </summary> /// <param name="files">The files.</param> /// <returns>Returns <c>true</c> if successful; Otherwise <c>false</c>.</returns> public bool Load(string[] files) { Error = string.Empty; PageType = Utils.ValidateImageFileExtension(files[0]) ? PageType.Image : PageType.Archive; for (int i = 1; i < files.Length; i++ ) { if (Utils.ValidateImageFileExtension(files[i]) && PageType != PageType.Image) { Error = "Please select only archives or only images."; return true; } } if (PageType == PageType.Archive) { //var archiveLoader = new ArchiveLoader(); //LoadedFileData = archiveLoader.LoadComicBook(files); _asyncLoader = new ArchiveLoadAsync(); LoadedFileData = _asyncLoader.LoadComicBook(files); } else if (PageType == PageType.Image) { var imageLoader = new ImageLoader(); // Q&D: if the user selects only one image, load all images in the folder if (files.Length == 1) LoadedFileData = imageLoader.LoadComicBook(Path.GetDirectoryName(files[0])); else LoadedFileData = imageLoader.LoadComicBook(files); } Error = LoadedFileData.Error; return string.IsNullOrEmpty(Error); }
/// <summary> /// Loads the specified files. /// </summary> /// <param name="files">The files.</param> /// <returns>Returns <c>true</c> if successful; Otherwise <c>false</c>.</returns> public bool Load(string[] files) { //Clear error this.Error = string.Empty; this.PageType = PageType.Archive; bool returnValue; //Check for file types. foreach (string file in files) { int startExtension = file.ToLower().LastIndexOf('.'); if (startExtension < 0) { //File does not have an extension so skip it. break; } string extension = file.ToLower().Substring(startExtension + 1); SupportedImages empty; if (Enum.TryParse<SupportedImages>(extension, true, out empty)) { this.PageType = PageType.Image; break; } else if (this.PageType == PageType.Image) { this.Error = "Please select only archives or only images."; } } if (string.IsNullOrEmpty(this.Error)) { if (PageType == PageType.Archive) { ArchiveLoader archiveLoader = new ArchiveLoader(); LoadedFileData = archiveLoader.LoadComicBook(files); this.Error = LoadedFileData.Error; } else if (PageType == PageType.Image) { ImageLoader imageLoader = new ImageLoader(); LoadedFileData = imageLoader.LoadComicBook(files); this.Error = LoadedFileData.Error; } } returnValue = string.IsNullOrEmpty(this.Error) ? true : false; return returnValue; }