Пример #1
0
        /// <summary>
        /// Checks if the converted files need to be kept in sync with source files. It deletes the converted file if the source file is deleted.
        /// This function is thread safe
        /// </summary>
        /// <param name="useRecycleBin">True to use Recycle Bin while deleting</param>
        public void SyncConvertedFiles(bool useRecycleBin)
        {
            try
            {
                Monitor.Enter(_monitorSyncFiles); // Make this thread safe

                // Build a list of files to be monitored from the History file to sync source with converted files
                Ini historyIni = new Ini(GlobalDefs.HistoryFile);

                try
                {
                    List<string> convertedFiles = historyIni.GetSectionNames(); // Get list of all files (includes converted and source)

                    foreach (string foundFile in convertedFiles)
                    {
                        if (!_monitorSyncFiles.Contains(foundFile)) // We just keep building the list here and check if they are deleted later
                        {
                            _monitorSyncFiles.Add(foundFile); // add to the list
                            Log.AppLog.WriteEntry(this, "File " + foundFile + " is being monitored for syncing with output file", Log.LogEntryType.Debug);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.AppLog.WriteEntry(this, "Unable to get History section names", Log.LogEntryType.Error, true);
                    Log.AppLog.WriteEntry(this, "Error -> " + e.ToString(), Log.LogEntryType.Error, true);
                }

                // Check if the sources files are deleted and delete the converted files
                foreach (string sourceFile in new List<string>(_monitorSyncFiles)) // Create a new list to iterate through else it throws an exception when we modify it
                {
                    if (File.Exists(sourceFile))
                        continue; // Source file still exists, nothing to do

                    // Source file no longer, exists, it has been deleted
                    // Check if the file has been converted and if so then get the location of the converted file from the history file
                    int convCount = 0;
                    string convFile = "";
                    while ((convFile = historyIni.ReadString(sourceFile, "ConvertedTo" + convCount.ToString(System.Globalization.CultureInfo.InvariantCulture), "")) != "")
                    {
                        // Delete the EDL, SRT, XML, NFO etc files also along with the original file if present
                        foreach (string supportFileExt in GlobalDefs.supportFilesExt)
                        {
                            string extFile = Path.Combine(Path.GetDirectoryName(convFile), Path.GetFileNameWithoutExtension(convFile) + supportFileExt); // support file

                            if (File.Exists(extFile)) // don't overburden the log
                                Log.AppLog.WriteEntry(this, "Source File " + sourceFile + " deleted, deleting converted support file " + extFile, Log.LogEntryType.Debug);

                            FileIO.TryFileDelete(extFile, useRecycleBin); // Delete support file
                        }

                        if (File.Exists(convFile)) // don't overburden the log
                            Log.AppLog.WriteEntry(this, "Source File " + sourceFile + " deleted, deleting converted file " + convFile, Log.LogEntryType.Debug);

                        FileIO.TryFileDelete(convFile, useRecycleBin); // Try to delete the converted file since the source file is deleted
                        DeleteParentDirectoryChainIfEmpty(convFile); // Delete the parent directory chain if empty for the converted file

                        convCount++;
                    }
                }

                Monitor.Exit(_monitorSyncFiles);
            }
            catch (Exception e) // Incase the thread terminates, release the lock and exit gracefully
            {
                // Release the queue lock if taken
                try { Monitor.Exit(_monitorSyncFiles); } // Incase it's taken release it, if not taken it will throw an exception
                catch { }

                Log.AppLog.WriteEntry(this, "Sync Converted Files terminated", Log.LogEntryType.Warning, true);
                Log.AppLog.WriteEntry(this, "Error -> " + e.ToString(), Log.LogEntryType.Warning, true);
            }
        }
Пример #2
0
        public List<string[]> GetProfilesSummary()
        {
            List<string[]> profileSummary = new List<string[]>();

            // Open and read all profiles
            Ini profileIni = new Ini(GlobalDefs.ProfileFile);
            foreach (string profile in profileIni.GetSectionNames())
                profileSummary.Add(new String[] { profile, profileIni.ReadString(profile, "Description", "") }); // 2 array string -> Profile Name, Description

            return profileSummary;
        }
Пример #3
0
        /// <summary>
        /// Check the History if the file has been converted (check output/converted filename and path).
        /// This function is thread safe
        /// </summary>
        /// <param name="convertedFile">Output Filename and path to check</param>
        /// <returns>True of the output filename and path exists in the history file</returns>
        public static bool DoesConvertedFileExistCheckHistory(string convertedFile)
        {
            // TODO: A very very large history file can cause the computer to "hang" and have high CPU utilization, how does one handle this situation?
            try
            {
                // Check if the file has been converted in the past
                Ini historyIni = new Ini(GlobalDefs.HistoryFile);
                List<string> fileNames = historyIni.GetSectionNames();
                foreach (string filePath in fileNames)
                {
                    if (filePath.ToLower() == convertedFile.ToLower()) // Check if the converted file exists in the History list, ignore case
                        if (historyIni.GetSectionKeyValuePairs(filePath)["Status"] == "OutputFromConversion") // Double check that this file is an output from the conversion
                            return true;
                }
            }
            catch (Exception e)
            {
                Log.AppLog.WriteEntry("Unable to check History file entries", Log.LogEntryType.Error, true);
                Log.AppLog.WriteEntry("Error -> " + e.ToString(), Log.LogEntryType.Error, true);
            }

            return false;
        }
Пример #4
0
        public Dictionary<string, SortedList<string, string>> GetConversionHistory()
        {
            Ini historyIni = new Ini(GlobalDefs.HistoryFile);
            Dictionary<string, SortedList<string, string>> retVal = new Dictionary<string,SortedList<string,string>>();

            try
            {
                List<string> fileNames = historyIni.GetSectionNames();
                foreach (string filePath in fileNames)
                {
                    try
                    {
                        SortedList<string, string> entries = historyIni.GetSectionKeyValuePairs(filePath);
                        retVal.Add(filePath, entries); // Add the file and the entries for the file
                    }
                    catch (Exception e1)
                    {
                        Log.AppLog.WriteEntry(this, "Error processing history file section entry -> " + filePath + "\r\nError -> " + e1.ToString(), Log.LogEntryType.Error, true);
                    }
                }
            }
            catch (Exception e)
            {
                Log.AppLog.WriteEntry(this, "Unable to get History file entries.\r\nError -> " + e.ToString(), Log.LogEntryType.Error, true);
            }

            return retVal;
        }