예제 #1
0
        public void ExportTrackingFile(string sSaveFilePath, EFileRoot root)
        {
            FileInfo dirinfo = new FileInfo(sSaveFilePath);

            /*if (Directory.Exists(dirinfo.DirectoryName))
             * {
             *      Directory.Delete(dirinfo.DirectoryName, true);
             *      Directory.CreateDirectory(dirinfo.DirectoryName);
             * }*/

            DumpFilesToDisk(sSaveFilePath, root);
            FileInfo trackingFile = new FileInfo(sSaveFilePath);


            string        sDestinationDir = trackingFile.DirectoryName;
            string        sSourceDir      = "";
            List <string> exportList;

            switch (root)
            {
            case EFileRoot.eFR_CERoot:
            {
                sSourceDir = CApplicationSettings.Instance.GetValue(ESettingsStrings.RootPath).GetValueString();
                exportList = m_trackedCERootFiles;
            }
            break;

            case EFileRoot.eFR_GameFolder:
            {
                sSourceDir = CApplicationSettings.Instance.GetValue(ESettingsStrings.GameFolderPath).GetValueString();
                exportList = m_trackedGameFolderFiles;
            }
            break;

            default:
                throw new Exception("Invalid value for EFileRoot");
            }

            bool bVerboseExport = CApplicationSettings.Instance.GetValue(ESettingsStrings.VerboseImportExport).GetValueBool();

            foreach (string relativePath in exportList)
            {
                string sTargetFilePath = sDestinationDir + relativePath;
                string sSourceFilePath = sSourceDir + relativePath;
                if (File.Exists(sTargetFilePath))
                {
                    FileInfo destinationInfo = new FileInfo(sTargetFilePath);
                    FileInfo sourceInfo      = new FileInfo(sSourceFilePath);

                    int compareResult = destinationInfo.LastWriteTime.CompareTo(sourceInfo.LastWriteTime);

                    if (compareResult > 0)
                    {
                        string message = String.Format("Destination file {0} is more recent than " +
                                                       "source file {1}, skipping export for it", sTargetFilePath,
                                                       sSourceFilePath);                                        // LOCALIZE
                        if (bVerboseExport)
                        {
                            CUserInteractionUtils.ShowInfoMessageBox(message);
                        }

                        message = String.Format("Destination file {0} is more recent than " +
                                                "source file {1}, skipping export for it", sTargetFilePath,
                                                sSourceFilePath);                                         // DONOTLOCALIZE

                        CLogfile.Instance.LogWarning("[Source tracker]" + message);
                        continue;
                    }
                    else if (compareResult == 0)
                    {
                        string message = String.Format("Source file {1} is not different " +
                                                       "from destination file {0}, skipping export for it", sTargetFilePath,
                                                       sSourceFilePath);                                         // LOCALIZE
                        if (bVerboseExport)
                        {
                            CUserInteractionUtils.ShowInfoMessageBox(message);
                        }

                        message = String.Format("Source file {1} is not different " +
                                                "from destination file {0}, skipping export for it", sTargetFilePath,
                                                sSourceFilePath);                                                // DONOTLOCALIZE
                        // Always log to file...
                        CLogfile.Instance.LogWarning("[Source tracker]" + message);
                        continue;
                    }
                }

                try
                {
                    FileInfo info = new FileInfo(sTargetFilePath);

                    if (!Directory.Exists(info.DirectoryName))
                    {
                        Directory.CreateDirectory(info.DirectoryName);
                    }
                    CProcessUtils.CopyFile(sSourceFilePath, sTargetFilePath);
                }
                catch (Exception e)
                {
                    string message = "Failed to export file! Error: " + e.Message;                     // LOCALIZE

                    CUserInteractionUtils.ShowErrorMessageBox(message);

                    message = "Failed to export file! Error: " + e.Message;                     // DONOTLOCALIZE
                    CLogfile.Instance.LogError(message);
                    return;
                }
            }

            string sLastExportFiles    = CApplicationSettings.Instance.GetValue(ESettingsStrings.LastExportFiles).GetValueString();
            string sNewLastExportFiles = "";

            char[] splitter = { ';' };

            string[] singleFiles = sLastExportFiles.Split(splitter, StringSplitOptions.RemoveEmptyEntries);

            // If there are two files then look for the obsolete one

            foreach (string lastSave in singleFiles)
            {
                if (sSaveFilePath != lastSave)
                {
                    sNewLastExportFiles += lastSave + ";";
                }
            }



            sNewLastExportFiles += sSaveFilePath + ";";

            CApplicationSettings.Instance.SetValue(new CSetting(ESettingsStrings.LastExportFiles,
                                                                sNewLastExportFiles));
        }
예제 #2
0
        public void LoadIgnoredFilesList(bool bCheckForSanity = true)
        {
            m_ignoredFilesWacher.EnableRaisingEvents = false;
            try
            {
                m_ignoredFiles.Clear();
                m_ignoredNegatedRegexList.Clear();
                m_ignoredRegexList.Clear();
                FileStream   stream = File.Open(m_sIgnoredFilesListPath, FileMode.Open);
                StreamReader reader = new StreamReader(stream);

                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    line = line.Trim();

                    if (line.StartsWith("#") || String.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    if (line.IndexOf('#') != -1)
                    {
                        line = line.Substring(0, line.IndexOf('#'));
                        line = line.Trim();
                    }

                    m_ignoredFiles.Add(line);
                }

                reader.Close();
            }
            catch (FileNotFoundException)
            {
                File.Create(m_sIgnoredFilesListPath);

                try
                {
                    LoadIgnoredFilesList();
                }
                catch (Exception)
                {
                }
            }

            m_ignoredFiles.Add(Window1.m_sGameTempDirName);

            foreach (string ignoredPath in m_ignoredFiles)
            {
                try
                {
                    if (!ignoredPath.StartsWith("!"))
                    {
                        m_ignoredRegexList.Add(new Regex(ignoredPath));
                    }
                    else
                    {
                        m_ignoredNegatedRegexList.Add(new Regex(ignoredPath.TrimStart('!')));
                    }
                }
                catch (ArgumentException e)
                {
                    CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.IgnoredRegexWrong + '\n'
                                                              + e.Message);
                    continue;
                }
            }


            if (bCheckForSanity)
            {
                if (!CheckIgnoredFilesSanity())
                {
                    CUserInteractionUtils.ShowInfoMessageBox(Properties.Resources.IngoredRegexDoesntExist);
                }
            }
            else
            {
                CLogfile.Instance.LogWarning("[Source tracker] Loading ignored files file without sanity check! Performance and logic issues inbound!");
            }

            m_ignoredFilesWacher.EnableRaisingEvents = true;
        }
예제 #3
0
        public void ImportTrackingList(string sFilePath, EFileRoot root)
        {
            Reset(root, false);

            LoadFileTrackingList(sFilePath, root);

            FileInfo trackingFileInfo = new FileInfo(sFilePath);

            string        sTrackingDir     = trackingFileInfo.DirectoryName;
            string        sDestinationRoot = "";
            List <string> importList;

            switch (root)
            {
            case EFileRoot.eFR_CERoot:
            {
                sDestinationRoot = CApplicationSettings.Instance.GetValue(ESettingsStrings.RootPath).GetValueString();
                importList       = m_trackedCERootFiles;
            } break;

            case EFileRoot.eFR_GameFolder:
            {
                sDestinationRoot = CApplicationSettings.Instance.GetValue(ESettingsStrings.GameFolderPath).GetValueString();
                importList       = m_trackedGameFolderFiles;
            } break;

            default:
                throw new Exception("Invalid value for EFileRoot");
            }

            CSetting verboseImport  = CApplicationSettings.Instance.GetValue(ESettingsStrings.VerboseImportExport);
            bool     bVerboseImport = verboseImport.GetValueBool();


            foreach (string relativePath in importList)
            {
                string sDestinationPath = sDestinationRoot + relativePath;
                string sSourcePath      = sTrackingDir + relativePath;

                FileInfo sourceFile = new FileInfo(sSourcePath);
                FileInfo targetFile = new FileInfo(sDestinationPath);


                int compareResult = sourceFile.LastWriteTime.CompareTo(targetFile.LastWriteTime);

                if (compareResult > 0)
                {
                    try
                    {
                        // Using CopyFile here too in case of large files
                        // DONE_TODO: see if this gets troublesome if file already exists
                        // Using custom function instead
                        CProcessUtils.CopyFile(sSourcePath, sDestinationPath, true);
                    }
                    catch (Exception)
                    {
                    }
                }
                else if (compareResult == 0)
                {
                    string message = String.Format("Source file {1} is not different " +
                                                   "from destination file {0}, skipping import for it", sDestinationPath,
                                                   sSourcePath);                                             // LOCALIZE
                    if (bVerboseImport)
                    {
                        CUserInteractionUtils.ShowInfoMessageBox(message);
                    }

                    message = String.Format("Source file {1} is not different " +
                                            "from destination file {0}, skipping import for it", sDestinationPath,
                                            sSourcePath);                                                    // DONOTLOCALIZE
                    // Always log to file...
                    CLogfile.Instance.LogWarning("[Source tracker]" + message);
                }
                else
                {
                    string message = String.Format("Destination file {0} is more recent than " +
                                                   "source file {1}, skipping import for it", sDestinationPath,
                                                   sSourcePath);                                             // LOCALIZE
                    if (bVerboseImport)
                    {
                        CUserInteractionUtils.ShowInfoMessageBox(message);
                    }
                    message = String.Format("Destination file {0} is more recent than " +
                                            "source file {1}, skipping import for it", sDestinationPath,
                                            sSourcePath);                                                     // DONOTLOCALIZE
                    // Always log to file...
                    CLogfile.Instance.LogWarning("[Source tracker]" + message);
                }
            }


            string sLastImportFiles    = CApplicationSettings.Instance.GetValue(ESettingsStrings.LastImportFiles).GetValueString();
            string sNewLastImportFiles = "";

            char[] splitter = { ';' };

            string[] singleFiles = sLastImportFiles.Split(splitter, StringSplitOptions.RemoveEmptyEntries);

            // If there are two files then look for the obsolete one

            foreach (string lastSave in singleFiles)
            {
                if (lastSave != m_sCurrentTrackingList)
                {
                    sNewLastImportFiles += lastSave + ";";
                }
            }


            m_sCurrentTrackingList = sFilePath;
            sNewLastImportFiles   += sFilePath;

            CApplicationSettings.Instance.SetValue(new CSetting(ESettingsStrings.LastImportFiles,
                                                                sNewLastImportFiles));
        }