Пример #1
0
        public IEnumerable <Tuple <int, string> > GetThumbnailsPaths(string filePath, string fileName, RenderAspectEnum renderType)
        {
            Tuple <int, string>[] foundFiles = null;
            string cachePath          = GetCachePath();
            string filesNameForFilter = GetComposedFileNameForFilter(fileName, filePath, renderType);

            try
            {
                if (Directory.Exists(cachePath))
                {
                    var files = UtilMethods.EnumerateFiles(cachePath, filesNameForFilter, SearchOption.AllDirectories);
                    foundFiles = files.Select(f => new Tuple <int, string>(GetFileSizeFromFileName(f), f)).ToArray();
                }
            }
            catch (Exception ex)
            {
                logger.Trace(ex, "Exception loading cache file paths for {fullpath} as {renderType}", Path.Combine(filePath, fileName), renderType.ToString());
                return(null);
            }

            /*
             * if (foundFiles == null || foundFiles.Length == 0) logger.Info("No cache files found for {filePath} as {filesNameForFilter}", Path.Combine(filePath, fileName), filesNameForFilter);
             * else logger.Info("Found {fileCount} cache files for {filePath} as {filesNameForFilter}", foundFiles.Length, Path.Combine(filePath, fileName), filesNameForFilter);
             */

            return(foundFiles);
        }
Пример #2
0
        public long CacheSize()
        {
            long   size      = 0;
            string cachePath = GetCachePath();

            try
            {
                logger.Info("Calculating cache size...");
                if (Directory.Exists(cachePath))
                {
                    foreach (var filePath in UtilMethods.EnumerateFiles(cachePath, "*.png", SearchOption.AllDirectories))
                    {
                        using (var file = File.OpenRead(filePath))
                        {
                            size += file.Length;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Trace(ex, "Exception calculating cache size");
                return(-1);
            }
            logger.Info("Calculated cache size: {size}", size);

            return(size);
        }
Пример #3
0
        public bool MoveCacheToNewLocation(CachePathType oldPath, CachePathType newPath)
        {
            string currentCachePath = GetCachePath(pathType: oldPath);
            string newCachePath     = GetCachePath(pathType: newPath);

            try
            {
                logger.Info("Moving cache folder from [{currentCachePath}] to [{newCachePath}]", currentCachePath, newCachePath);

                IEnumerable <string> cacheFiles = UtilMethods.EnumerateFiles(currentCachePath, "*.png", SearchOption.AllDirectories).ToArray();

                if (Path.GetPathRoot(currentCachePath) == Path.GetPathRoot(newCachePath))
                {
                    Directory.Move(currentCachePath, newCachePath);
                }
                else
                {
                    if (!Directory.Exists(newCachePath))
                    {
                        Directory.CreateDirectory(newCachePath);
                    }

                    foreach (string cacheFile in cacheFiles)
                    {
                        var    imageSize   = Path.GetDirectoryName(cacheFile).Split(Path.DirectorySeparatorChar).Last();
                        string newImageDir = Path.Combine(newCachePath, imageSize);

                        if (!Directory.Exists(newImageDir))
                        {
                            Directory.CreateDirectory(newImageDir);
                        }

                        File.Copy(cacheFile, Path.Combine(newImageDir, Path.GetFileName(cacheFile)), true);
                    }

                    foreach (string cacheFile in cacheFiles)
                    {
                        File.Delete(cacheFile);
                    }

                    Directory.Delete(currentCachePath, true);
                }
            }
            catch (Exception ex)
            {
                logger.Debug(ex, "Error when moving cache folder from [{currentCachePath}] to [{newCachePath}]", currentCachePath, newCachePath);
                return(false);
            }
            return(true);
        }
Пример #4
0
        public bool LoadDirectories(IEnumerable <string> paths)
        {
            IsLoading               = false;
            MainDispatcher          = Dispatcher.CurrentDispatcher;
            cancellationTokenSource = new CancellationTokenSource();
            cancellationToken       = cancellationTokenSource.Token;

            cache        = DefaultFactory.GetDefaultThumbnailCache();
            userSettings = DefaultFactory.GetDefaultUserSettings();
            renderType   = (RenderAspectEnum)userSettings.GetSettingInt(UserSettingEnum.Thumbnails3DAspect);

            logger.Info("Loading paths: Received: [{0}]", string.Join("] [", paths));
            paths = paths.Where(p1 => !paths.Any(p2 => !p1.Equals(p2) && p1.Contains(p2))).ToArray(); // Remove selected subdirectories of other selected paths.
            logger.Info("Loading paths: After removed subdirs: [{0}]", string.Join("] [", paths));

            try
            {
                IEnumerable <string> pathsFound = new List <string>();
                for (int i = 0; i < SupportedExtensionsFilter.Length; i++)
                {
                    foreach (string path in paths)
                    {
                        pathsFound = pathsFound.Concat(UtilMethods.EnumerateFiles(path, SupportedExtensionsFilter[i], SearchOption.AllDirectories, cancellationToken));
                    }
                }
                pathsFound = pathsFound.ToArray();

                if (cancellationToken.IsCancellationRequested)
                {
                    return(false);
                }

                if (pathsFound.Count() > 0)
                {
                    CalculateThumnailSizes(pathsFound.Count());
                    InitializeFoundFilesObjects(pathsFound);
                    return(true);
                }
                else
                {
                    FilesFound = new ModelFileData[0];
                }
            }
            catch (Exception ex)
            {
                logger.Trace(ex, "Unable to load: {ex}", ex.Message);
            }
            return(false);
        }
Пример #5
0
        public bool ClearCacheForFiles(IEnumerable <string> filenames)
        {
            string cachePath       = GetCachePath();
            bool   allFilesCleared = true;

            try
            {
                if (Directory.Exists(cachePath))
                {
                    var files = UtilMethods.EnumerateFiles(cachePath, "*.png", SearchOption.AllDirectories);
                    files = files.Where(f => filenames.Any(n => f.Contains(n)));
                    logger.Info("Clearing cache for specific files. Detected {fileCount} files.", files.Count());

                    foreach (var filePath in files)
                    {
                        try
                        {
                            File.Delete(filePath);
                        }
                        catch (Exception ex)
                        {
                            allFilesCleared = false;
                            logger.Trace(ex, "Error deleting cache for specific file: {filePath}", filePath);
                        }
                    }
                }
                else
                {
                    logger.Info("Clearing cache for specific files... Cache path not found! {cachePath}", cachePath);
                }
            }
            catch (Exception ex)
            {
                logger.Trace(ex, "Exception calculating cache size for specific files");
                return(false);
            }
            return(allFilesCleared);
        }
Пример #6
0
        public IEnumerable <Tuple <int, BitmapSource> > GetThumbnailsImages(string filePath, string fileName, RenderAspectEnum renderType)
        {
            Tuple <int, BitmapSource>[] loadedFiles = new Tuple <int, BitmapSource> [0];
            string cachePath          = GetCachePath();
            string filesNameForFilter = GetComposedFileNameForFilter(fileName, filePath, renderType);

            try
            {
                if (Directory.Exists(cachePath))
                {
                    var files = UtilMethods.EnumerateFiles(cachePath, filesNameForFilter, SearchOption.AllDirectories);
                    loadedFiles = new Tuple <int, BitmapSource> [files.Count()];
                    int i = 0;
                    foreach (var foundFile in files)
                    {
                        using (var file = File.OpenRead(foundFile))
                        {
                            BitmapSource bmp = LoadImageFromStream(file);
                            loadedFiles[i] = new Tuple <int, BitmapSource>(GetFileSizeFromFileName(foundFile), bmp);
                        }
                        i++;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Trace(ex, "Exception loading cache file images for {fullpath} as {renderType}", Path.Combine(filePath, fileName), renderType.ToString());
            }

            /*
             * if (loadedFiles.Length == 0) logger.Info("No cache files found for {filePath} as {filesNameForFilter}", Path.Combine(filePath, fileName), filesNameForFilter);
             * else logger.Info("Loaded {fileCount} cache files found for {filePath} as {filesNameForFilter}", loadedFiles.Length, Path.Combine(filePath, fileName), filesNameForFilter);
             */

            return(loadedFiles);
        }
        private async Task <IEnumerable <string> > AutoFillProgramsTableAsync()
        {
            string appPath          = System.IO.Path.GetDirectoryName(Assembly.GetAssembly(typeof(ConfigurationWindow)).Location);
            string programsListFile = System.IO.Path.Combine(appPath, "Content", "Autodetect3DSoftwareList.txt");

            if (!System.IO.File.Exists(programsListFile))
            {
                return(new string[0]);
            }

            string[] recognicedProgramsNames = System.IO.File.ReadAllLines(programsListFile);

            string programsFolder1 = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
            string programsFolder2 = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string programsFolder3 = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
            string programsFolder4 = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar");

            string[] allProgramsFolder = { programsFolder1, programsFolder2, programsFolder3, programsFolder4 };

            WshShell      shell         = new WshShell();
            List <string> addedPrograms = new List <string>();

            foreach (string programFolder in allProgramsFolder)
            {
                try
                {
                    var allShortcutsFound = UtilMethods.EnumerateFiles(programFolder, "*.lnk", SearchOption.AllDirectories);

                    foreach (string shortcutFound in allShortcutsFound)
                    {
                        try
                        {
                            IWshShortcut link = (IWshShortcut)shell.CreateShortcut(shortcutFound);

                            string exeFileName = System.IO.Path.GetFileNameWithoutExtension(link.TargetPath);
                            if (recognicedProgramsNames.Any(p => string.Equals(p, exeFileName, StringComparison.InvariantCultureIgnoreCase)))
                            {
                                if (_modelConfigSettings.LinkedProgramsData.Any(p => p.ProgramFullPath == link.TargetPath))
                                {
                                    continue;
                                }

                                var newRow = new Data.DataObjects.LinkedProgramData()
                                {
                                    ProgramName     = System.IO.Path.GetFileNameWithoutExtension(shortcutFound),
                                    ProgramFullPath = link.TargetPath,
                                    SupportSTL      = true,
                                };

                                await this.Dispatcher.BeginInvoke(() =>
                                {
                                    _modelConfigSettings.LinkedProgramsData.Add(newRow);
                                });

                                addedPrograms.Add(newRow.ProgramName);
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Debug(ex, "Settings window: AutoFillProgramsTableAsync: Exception when processing shortcut '{0}'", shortcutFound);
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Debug(ex, "Settings window: AutoFillProgramsTableAsync: Exception when processing programs folder '{0}'", programFolder);
                }
            }
            return(addedPrograms);
        }