public WallpaperFile[] GetWallpaperFiles(string directoryPath) { try { var directoryInfo = new DirectoryInfo(string.IsNullOrEmpty(directoryPath) ? "dummy" : directoryPath); if (directoryInfo.Exists) { var dic = new Dictionary <ushort, WallpaperFile>(); foreach (var file in directoryInfo.GetFiles()) { ushort number; if (ushort.TryParse(Path.GetFileNameWithoutExtension(file.Name), out number) && _supportedExtensions.Any(x => x == file.Extension) && !dic.ContainsKey(number)) { dic[number] = new WallpaperFile(number, file.FullName); } } return(dic .OrderBy(kvp => kvp.Key) .Select(x => x.Value) .ToArray()); } } catch (Exception ex) { LoggingService.Instance.Register(ex); } return(Array.Empty <WallpaperFile>()); }
public WallpaperFile[] GetWallpaperFiles(string directoryPath) { try { var directoryInfo = new DirectoryInfo(string.IsNullOrEmpty(directoryPath) ? "dummy" : directoryPath); if (directoryInfo.Exists) { var col = new Collection <WallpaperFile>(); foreach (var file in directoryInfo.GetFiles()) { if (_supportedExtensions.Any(x => x == file.Extension)) { var wallpaper = WallpaperFile.CreateFromFile(file); col.Add(wallpaper); } } return(col.OrderBy(w => w.Number).ToArray()); } } catch (Exception ex) { LoggingService.Instance.Register(ex); } return(Array.Empty <WallpaperFile>()); }
public WallpaperFile[] GetWallpaperFiles(string directoryPath) { try { var directoryInfo = new DirectoryInfo(string.IsNullOrEmpty(directoryPath) ? "dummy" : directoryPath); if (directoryInfo.Exists) { var dic = new Dictionary<ushort, WallpaperFile>(); foreach (var file in directoryInfo.GetFiles()) { ushort number; if (ushort.TryParse(Path.GetFileNameWithoutExtension(file.Name), out number) && _supportedExtensions.Any(x => x == file.Extension) && !dic.ContainsKey(number)) { dic[number] = new WallpaperFile(number, file.FullName); } } return dic .OrderBy(kvp => kvp.Key) .Select(x => x.Value) .ToArray(); } } catch (Exception ex) { LoggingService.Instance.Register(ex); } return Array.Empty<WallpaperFile>(); }