示例#1
0
        private void LoadNewImageFile(string imagePath)
        {
            try
            {
                pictureBox1.SizeMode = (PictureBoxSizeMode)_applicationSettingsService.Settings.PrimaryImageSizeMode;


                if (_applicationSettingsService.Settings.NextImageAnimation == ImageViewApplicationSettings.ChangeImageAnimation.None)
                {
                    _changeImageAnimation = ImageViewApplicationSettings.ChangeImageAnimation.None;
                }

                _pictureBoxAnimation.ImageLocation = null;

                if (pictureBox1.Image != null && _changeImageAnimation != ImageViewApplicationSettings.ChangeImageAnimation.None)
                {
                    _pictureBoxAnimation.Image = _imageCacheService.GetImageFromCache(imagePath);
                    _pictureBoxAnimation.Refresh();
                }
                else
                {
                    pictureBox1.Image = _imageCacheService.GetImageFromCache(imagePath);
                    pictureBox1.Refresh();
                }

                Text = _windowTitle + @" | " + GeneralConverters.GetFileNameFromPath(imagePath);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "FormMain.LoadNewImageFile(string imagePath) Error when trying to load file: {imagePath} : {Message}", imagePath, ex.Message);
            }
        }
示例#2
0
        private void createMD5FileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (FileListDataGridView.SelectedRows.Count == 0)
            {
                return;
            }
            var fileSystemFileWrapper = (FileListDataGridView.SelectedRows[0].DataBoundItem as FileSystemFileWrapper);

            if (fileSystemFileWrapper == null)
            {
                MessageBox.Show("Unexprected error in createMD5File. DataBoundItem is " + FileListDataGridView.SelectedRows[0].DataBoundItem.GetType());
                return;
            }

            // Root folder?
            string sfvFilename            = fileSystemFileWrapper.FilePath ?? _currentFileSystemDrive.DriveLetter + fileSystemFileWrapper.Name;
            int    fileExtensionDelimiter = sfvFilename.LastIndexOf('.');

            if (fileExtensionDelimiter > 0)
            {
                sfvFilename = sfvFilename.Substring(0, fileExtensionDelimiter) + ".md5";
            }
            else
            {
                sfvFilename += ".md5";
            }


            LoadAndSaveProgressBar.Visible      = true;
            ChecksumFileGenerationLabel.Visible = true;
            Action <ChecksumProgress> checksumProgressLamdaFunction = progress =>
            {
                ChecksumFileGenerationLabel.Text = GeneralConverters.GetFileNameFromPath(progress.Text).PadLeft(5);
                LoadAndSaveProgressBar.Value     = progress.TotalProgress;

                if (progress.Completed)
                {
                    LoadAndSaveProgressBar.Visible      = false;
                    ChecksumFileGenerationLabel.Visible = false;
                    MessageBox.Show("Successfully created MD5 file");
                }
            };

            var checksumFileGenerator = new ChecksumFileGenerator(Application.ProductName + " " + Application.ProductVersion, new Progress <ChecksumProgress>(checksumProgressLamdaFunction));
            var paths = new StringCollection();

            foreach (DataGridViewRow selectedRow in FileListDataGridView.SelectedRows)
            {
                var selectedFile = selectedRow.DataBoundItem as FileSystemFileWrapper;
                if (selectedFile != null && selectedFile.FilePath != null)
                {
                    paths.Add(selectedFile.FilePath);
                }
            }

            checksumFileGenerator.GenrateMD5FileAsync(paths, sfvFilename);
        }
示例#3
0
 private void UpdateFileHashStatus(object sender, FileHashEventArgs e)
 {
     lblFileHashesRunning.Text = Math.Max(0, _hashComputeCount).ToString();
     if (e.FileName == null)
     {
         lblFileHashInfo.Text = "";
     }
     else
     {
         lblFileHashInfo.Text = GeneralConverters.GetFileNameFromPath(e.FileName) + " - " + GeneralConverters.FormatFileSizeToString(e.FileSize);
     }
 }
示例#4
0
        public void SaveConfigFile(string path)
        {
            try
            {
                if (!GeneralConverters.GetFileNameFromPath(path).EndsWith(".ini"))
                {
                    throw new ArgumentException("Invalid filename. Filename must end with .ini");
                }

                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                FileStream fs = File.Create(path);
                TextWriter tw = new StreamWriter(fs);

                foreach (string rootItemName in _iniFileData.ConfigItems.AllKeys)
                {
                    tw.WriteLine(rootItemName + "=" + _iniFileData.ConfigItems[rootItemName]);
                }

                foreach (string sectionName in _iniFileData.ConfigSections.Keys)
                {
                    IniConfigFileSection section = _iniFileData.ConfigSections[sectionName];
                    tw.WriteLine("[" + sectionName + "]");

                    foreach (string itemName in section.ConfigItems.AllKeys)
                    {
                        tw.WriteLine(itemName + "=" + section.ConfigItems[itemName]);
                    }
                }
                tw.Flush();
                fs.Flush();

                fs.Close();
            }
            catch (Exception ex)
            {
                Log.Error(ex, "IniConfigFileManager->SaveConfigFile");
            }
        }
示例#5
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                try
                {
                    _searchProfileManager.SearchProfile.FullPath    = saveFileDialog1.FileName;
                    _searchProfileManager.SearchProfile.ProfileName = GeneralConverters.GetFileNameFromPath(saveFileDialog1.FileName);

                    SetProfileSettings();
                    _searchProfileManager.SaveSearchProfile(saveFileDialog1.FileName);
                    UpdateMenuItemState();
                    lblSearchProfileName.Text = _searchProfileManager.SearchProfile.ProfileName;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Generics.ErrorSavingFile, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public Task <int> FixBrokenLinksFromBaseDir(string selectedPath)
        {
            var task = Task <int> .Factory.StartNew(() =>
            {
                int filePathsCorrected = 0;
                var brokenLinksList    = GetAllBookmarksWithIncorrectPath(RootFolder);

                foreach (var bookmark in brokenLinksList)
                {
                    var fileMatches = Directory.EnumerateFiles(selectedPath, bookmark.FileName, SearchOption.AllDirectories).ToList();

                    if (fileMatches.Any())
                    {
                        foreach (string fileMatch in fileMatches)
                        {
                            FileInfo fileInfo = new FileInfo(fileMatch);
                            if (fileInfo.Length == bookmark.Size)
                            {
                                string dir      = GeneralConverters.GetDirectoryNameFromPath(fileMatch);
                                string fileName = GeneralConverters.GetFileNameFromPath(fileMatch);

                                bookmark.Directory      = dir;
                                bookmark.FileName       = fileName;
                                bookmark.CompletePath   = fileMatch;
                                bookmark.CreationTime   = fileInfo.CreationTime;
                                bookmark.LastAccessTime = fileInfo.LastAccessTime;
                                bookmark.LastWriteTime  = fileInfo.LastWriteTime;
                                filePathsCorrected++;
                                break;
                            }
                        }
                    }
                }

                return(filePathsCorrected);
            });

            return(task);
        }
示例#7
0
        public void GenrateSFVFile(StringCollection filePathCollection, string sfvFilename)
        {
            using (var fs = File.Create(sfvFilename))
            {
                var CRC32HashImplemenation = new CRC32();

                // Write Header
                var sw = new StreamWriter(fs);
                sw.WriteLine(CHECKSUM_FILE_HEADER, _applicationName, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString("HH:mm:ss"));

                _checksumProgress.FilesTotal = filePathCollection.Count;
                _checksumProgress.Text       = "Generating SFV file header";

                if (_progress != null)
                {
                    _progress.Report(_checksumProgress);
                }

                foreach (string filename in filePathCollection)
                {
                    var fileInfo = new FileInfo(filename);

                    if (!fileInfo.Exists)
                    {
                        _checksumProgress.FilesTotal = _checksumProgress.FilesTotal - 1;
                        continue;
                    }

                    sw.WriteLine(CHECKSUM_FILE_INFO, FormatFileSize(fileInfo.Length, 14), fileInfo.LastWriteTime.ToString("HH:mm:ss"), fileInfo.LastWriteTime.ToString("yyyy-MM-dd"), GeneralConverters.GetFileNameFromPath(filename));
                }

                foreach (string filename in filePathCollection)
                {
                    _checksumProgress.Text = "Processing file: " + filename;

                    if (_progress != null)
                    {
                        _progress.Report(_checksumProgress);
                    }

                    var fileInfo = new FileInfo(filename);

                    if (!fileInfo.Exists)
                    {
                        continue;
                    }
                    try
                    {
                        string hexChecksum = GeneralConverters.ByteArrayToHexString(CRC32HashImplemenation.ComputeHash(fileInfo.OpenRead()));
                        sw.WriteLine(GeneralConverters.GetFileNameFromPath(filename) + " " + hexChecksum);
                        _checksumProgress.DataRead = _checksumProgress.DataRead + fileInfo.Length;
                    }
                    catch (Exception ex)
                    {
                        _checksumProgress.Text = ex.Message;
                    }


                    _checksumProgress.FilesCompleted = _checksumProgress.FilesCompleted + 1;
                    _checksumProgress.TotalProgress  = _checksumProgress.FilesCompleted * 100 / _checksumProgress.FilesTotal;

                    if (_progress != null)
                    {
                        _progress.Report(_checksumProgress);
                    }
                }

                fs.Flush();
                fs.Close();

                if (_progress != null)
                {
                    _checksumProgress.Text          = "SFV file generation completed";
                    _checksumProgress.TotalProgress = 100;
                    _checksumProgress.Completed     = true;
                    _progress.Report(_checksumProgress);
                }
            }
        }
示例#8
0
        public bool LoadConfigFile(string path)
        {
            bool       readSuccessful = false;
            FileStream fs             = null;

            try
            {
                if (!GeneralConverters.GetFileNameFromPath(path).EndsWith(".ini") || !File.Exists(path))
                {
                    throw new ArgumentException("File does not exist!");
                }

                fs = File.OpenRead(path);
                TextReader tr = new StreamReader(fs);

                Regex sectionMachRegex    = new Regex(ConfigFileSectionPattern);
                Regex sectionCleanerRegex = new Regex(ConfigSectionNamePattern);
                Regex configItemPattern   = new Regex(ConfigFileItemPattern);

                _iniFileData = new IniConfigFile();
                IniConfigFileSection configSection = new IniConfigFileSection();


                while (fs.Position <= fs.Length)
                {
                    string lineData = tr.ReadLine();

                    if (lineData == null || lineData.Length > 4096)
                    {
                        break;
                    }

                    if (sectionMachRegex.IsMatch(lineData))
                    {
                        string sectionName = sectionCleanerRegex.Replace(lineData, "");
                        if (!_iniFileData.ConfigSections.ContainsKey(sectionName))
                        {
                            _iniFileData.ConfigSections.Add(sectionName, new IniConfigFileSection());
                        }

                        configSection = _iniFileData.ConfigSections[sectionName];
                    }
                    else if (configSection != null && configItemPattern.IsMatch(lineData))
                    {
                        string[] confArr = lineData.Split('=');
                        configSection.ConfigItems[confArr[0].Trim()] = confArr[1].Trim();
                    }
                }
                fs.Close();
                readSuccessful = true;
            }
            catch (Exception ex)
            {
                Log.Error(ex, "IniConfigFileManager->LoadConfigFile");
            }
            finally
            {
                fs?.Close();
            }

            return(readSuccessful);
        }
        private int PerformThumbnailScan(string path, IProgress <ThumbnailScanProgress> progress)
        {
            var files = Directory.GetFiles(path);

            if (!Directory.Exists(path))
            {
                return(0);
            }

            if (!path.EndsWith("\\"))
            {
                path += "\\";
            }

            int filesToScan  = files.Length;
            int scannedFiles = 0;

            if (_abortScan)
            {
                return(0);
            }

            foreach (string fullPath in files)
            {
                string fileName = GeneralConverters.GetFileNameFromPath(fullPath);
                if (_abortScan)
                {
                    break;
                }

                if (!_fileNameRegExp.IsMatch(fileName) || _thumbnailRepository.IsCached(fullPath))
                {
                    continue;
                }
                Image img = null;

                try
                {
                    img = _thumbnailRepository.GetThumbnailImage(fullPath);
                }
                catch (Exception exception)
                {
                    Log.Error(exception, "Error loading file: " + fullPath);
                }

                if (img == null)
                {
                    continue;
                }

                var fileInfo = new FileInfo(fullPath);

                var thumbnail = new ThumbnailEntryModel
                {
                    Date              = DateTime.Now,
                    SourceImageDate   = fileInfo.LastWriteTime,
                    FileName          = fileName,
                    Directory         = path,
                    SourceImageLength = fileInfo.Length,
                };



                IsModified = true;

                // Update progress
                scannedFiles++;
                progress?.Report(new ThumbnailScanProgress {
                    TotalAmountOfFiles = filesToScan, ScannedFiles = scannedFiles
                });
            }

            return(scannedFiles);
        }