public void ImportLastExported() { CLogfile.Instance.LogInfo("[Source tracker import] Importing last exported file(s)..."); string sLastExport = CApplicationSettings.Instance.GetValue(ESettingsStrings.LastExportFiles).GetValueString(); char[] splitter = { ';' }; string[] dirs = sLastExport.Split(splitter, StringSplitOptions.RemoveEmptyEntries); if (dirs.Length == 0) { CLogfile.Instance.LogWarning("[Source tracker import] Can't import last export, because there was none"); } foreach (string file in dirs) { if (!File.Exists(file)) { CLogfile.Instance.LogWarning(String.Format("[Source tracker import] File: {0} doesn't exist anymore! Skipping...", file)); continue; } EFileRoot root = GetTrackingFileAffection(file); ImportTrackingList(file, root); } CLogfile.Instance.LogInfo("[Source tracker import] Importing last exported file(s) done!"); }
public void LoadFileTrackingList(string sFilePath, EFileRoot root) { try { List <string> listToAddTo; switch (root) { case EFileRoot.eFR_CERoot: listToAddTo = m_trackedCERootFiles; break; case EFileRoot.eFR_GameFolder: listToAddTo = m_trackedGameFolderFiles; break; default: throw new Exception("Invalid value for EFileRoot"); } FileStream stream = File.Open(sFilePath, FileMode.Open); StreamReader reader = new StreamReader(stream); while (!reader.EndOfStream) { string line = reader.ReadLine(); if (!listToAddTo.Contains(line) && !String.IsNullOrWhiteSpace(line) && !line.StartsWith("#")) { listToAddTo.Add(line); } } } catch (Exception) { } }
public void RemoveFileFromTracking(string sFilePath, EFileRoot root) { if (root == EFileRoot.eFR_CERoot) { // if we can extract the gamefolder from the root folder, add to game folder tracking // this means that the game folder is inside the root folder and doing // so avoid tracking one file with both lists if (CPathUtils.ExtractRelativeToGameFolder(sFilePath) != sFilePath) { root = EFileRoot.eFR_GameFolder; } } switch (root) { case EFileRoot.eFR_CERoot: { m_trackedCERootFiles.Remove(CPathUtils.ExtractRelativeToRoot(sFilePath)); DumpFilesToDisk(m_sCurrentRootTrackingListPath, EFileRoot.eFR_CERoot); } break; case EFileRoot.eFR_GameFolder: { m_trackedGameFolderFiles.Remove(CPathUtils.ExtractRelativeToGameFolder(sFilePath)); DumpFilesToDisk(m_sCurrentGameTrackingListPath, EFileRoot.eFR_GameFolder); } break; default: throw new Exception("Invalid value for EFileRoot"); } }
public bool IsFileTracked(string sFilePath, out EFileRoot root) { if (CPathUtils.ExtractRelativeToGameFolder(sFilePath) != sFilePath) { root = EFileRoot.eFR_GameFolder; return(m_trackedGameFolderFiles.Contains(CPathUtils.ExtractRelativeToGameFolder(sFilePath))); } else { root = EFileRoot.eFR_CERoot; return(m_trackedCERootFiles.Contains(CPathUtils.ExtractRelativeToRoot(sFilePath))); } }
public void ClearCurrentTrackingList(EFileRoot root) { switch (root) { case EFileRoot.eFR_CERoot: { if (File.Exists(m_sCurrentRootTrackingListPath)) { File.Delete(m_sCurrentRootTrackingListPath); } } break; case EFileRoot.eFR_GameFolder: { if (File.Exists(m_sCurrentGameTrackingListPath)) { File.Delete(m_sCurrentGameTrackingListPath); } } break; } }
public void ExportCurrentToLastExported() { CLogfile.Instance.LogInfo("[Source tracker export] Exporting current to last exported file(s)..."); string sLastExport = CApplicationSettings.Instance.GetValue(ESettingsStrings.LastExportFiles).GetValueString(); char[] splitter = { ';' }; string[] dirs = sLastExport.Split(splitter, StringSplitOptions.RemoveEmptyEntries); if (dirs.Length == 0) { CLogfile.Instance.LogWarning("[Source tracker export] Can't export to last export, because there was none"); } foreach (string file in dirs) { EFileRoot root = GetTrackingFileAffection(file); ExportTrackingFile(file, root); } CLogfile.Instance.LogInfo("[Source tracker export] Exporting current to last exported file(s) done!"); }
public void Reset(EFileRoot root, bool bSaveCurrent, string sSaveFilePath = "") { if (bSaveCurrent) { switch (root) { case EFileRoot.eFR_CERoot: DumpFilesToDisk(sSaveFilePath, EFileRoot.eFR_CERoot); break; case EFileRoot.eFR_GameFolder: DumpFilesToDisk(sSaveFilePath, EFileRoot.eFR_GameFolder); break; default: break; } } switch (root) { case EFileRoot.eFR_CERoot: if (m_trackedCERootFiles != null) { m_trackedCERootFiles.Clear(); } break; case EFileRoot.eFR_GameFolder: if (m_trackedGameFolderFiles != null) { m_trackedGameFolderFiles.Clear(); } break; default: break; } }
void OnOKClicked(object sender, RoutedEventArgs e) { string path = fileTextBox.Text; string[] paths = path.Split(';'); foreach (string filePath in paths) { if (String.IsNullOrWhiteSpace(filePath)) { continue; } string finalPath = filePath; if (!finalPath.Contains(".")) { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.CommonNoFileNameSpecified); return; } FileInfo info = new FileInfo(finalPath); if (info.Extension != CSourceTracker.FileExtension) { finalPath = CPathUtils.ChangeExtension(finalPath, CSourceTracker.FileExtension); } if (!info.Directory.Exists) { Directory.CreateDirectory(info.DirectoryName); } EFileRoot root; bool bDoBoth = false; if (affectionComboBox.SelectedIndex == 0) { root = EFileRoot.eFR_CERoot; } else if (affectionComboBox.SelectedIndex == 1) { root = EFileRoot.eFR_GameFolder; } else { root = EFileRoot.eFR_CERoot; bDoBoth = true; } switch (m_mode) { case EMode.eMO_Import: { EFileRoot targetRoot = CSourceTracker.Instance.GetTrackingFileAffection(finalPath); if (!bDoBoth && targetRoot != root) { CUserInteractionUtils.ShowErrorMessageBox(Properties.ImportExportResources.AffectionMissmatch); return; } CSourceTracker.Instance.ImportTrackingList(finalPath, CSourceTracker.Instance.GetTrackingFileAffection(finalPath)); } break; case EMode.eMO_Export: { if (!bDoBoth) { CSourceTracker.Instance.ExportTrackingFile(finalPath, root); } else { string name = finalPath; string noExtension = CPathUtils.RemoveExtension(name); string rootFile = noExtension; string gameFile = noExtension; if (!rootFile.Contains("_Root")) { rootFile += "_Root"; } if (!gameFile.Contains("_Game")) { gameFile += "_Game"; } CSourceTracker.Instance.ExportTrackingFile(rootFile + CSourceTracker.FileExtension, EFileRoot.eFR_CERoot); CSourceTracker.Instance.ExportTrackingFile(gameFile + CSourceTracker.FileExtension, EFileRoot.eFR_GameFolder); } } break; case EMode.eMO_Move: { if (!bDoBoth) { CSourceTracker.Instance.MoveTrackedFiles(finalPath, root); } else { CSourceTracker.Instance.MoveTrackedFiles(finalPath, EFileRoot.eFR_CERoot); CSourceTracker.Instance.MoveTrackedFiles(finalPath, EFileRoot.eFR_GameFolder); } } break; default: throw new Exception("Invalid value for EMode"); } } Close(); }
public void MoveTrackedFiles(string sDestinationPath, EFileRoot root) { }
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)); }
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)); }
public void DumpFilesToDisk(string sSaveFilePath, EFileRoot root) { lock (m_lockingObject) { List <string> listToDump; switch (root) { case EFileRoot.eFR_CERoot: listToDump = m_trackedCERootFiles; break; case EFileRoot.eFR_GameFolder: listToDump = m_trackedGameFolderFiles; break; default: throw new Exception("Invalid value for EFileRoot"); } if (!File.Exists(sSaveFilePath)) { FileInfo info = new FileInfo(sSaveFilePath); try { if (!Directory.Exists(info.DirectoryName)) { Directory.CreateDirectory(info.DirectoryName); } } catch (Exception e) { CUserInteractionUtils.ShowErrorMessageBox(e.Message); } } else { try { File.Delete(sSaveFilePath); } catch (Exception e) { if (e is IOException) { // Rescedule... System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 0, 100); timer.Tick += delegate { timer.Stop(); DumpFilesToDisk(sSaveFilePath, root); }; timer.Start(); return; } else { CUserInteractionUtils.ShowErrorMessageBox(e.Message); return; } } } FileStream stream = new FileStream(sSaveFilePath, FileMode.Create); StreamWriter writer = new StreamWriter(stream); if (writer != null) { switch (root) { case EFileRoot.eFR_CERoot: writer.WriteLine(m_sRootTrackingListSignature); break; case EFileRoot.eFR_GameFolder: writer.WriteLine(m_sGameTrackingListSignature); break; } foreach (string entry in listToDump) { writer.WriteLine(entry); } writer.Close(); } } }
public bool AddFileToTracking(string sFilePath, EFileRoot root, bool bBypassIgnoreList = false) { bool bIsAdded = false; lock (m_trackedCERootFiles) { if (root == EFileRoot.eFR_CERoot) { // if we can extract the gamefolder from the root folder, add to game folder tracking // this means that the game folder is inside the root folder and doing // so avoid tracking one file with both lists if (CPathUtils.ExtractRelativeToGameFolder(sFilePath) != sFilePath) { root = EFileRoot.eFR_GameFolder; } } switch (root) { case EFileRoot.eFR_CERoot: { string relativePath = CPathUtils.ExtractRelativeToRoot(sFilePath); if (!m_trackedCERootFiles.Contains(relativePath) && (bBypassIgnoreList || !ShouldIgnorePath(sFilePath))) { m_trackedCERootFiles.Add(relativePath); bIsAdded = true; } } break; case EFileRoot.eFR_GameFolder: { string relativePath = CPathUtils.ExtractRelativeToGameFolder(sFilePath); if (!m_trackedGameFolderFiles.Contains(relativePath) && (bBypassIgnoreList || !ShouldIgnorePath(sFilePath))) { m_trackedGameFolderFiles.Add(relativePath); bIsAdded = true; } } break; default: throw new Exception("Invalid value for EFileRoot"); } } if (bIsAdded) { switch (root) { case EFileRoot.eFR_CERoot: { DumpFilesToDisk(m_sCurrentRootTrackingListPath, EFileRoot.eFR_CERoot); } break; case EFileRoot.eFR_GameFolder: { DumpFilesToDisk(m_sCurrentGameTrackingListPath, EFileRoot.eFR_GameFolder); } break; } } return(bIsAdded); }