/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ public void Save(PaProject project) { if (project != null) { InternalSkipList skipList = new InternalSkipList(); foreach (KeyValuePair <string, bool> kvp in this) { if (kvp.Value) { skipList.Add(kvp.Key); } } string filename = project.ProjectPathFilePrefix + kDataSourceInfoFilePrefix; STUtils.SerializeData(filename, skipList); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Read the data sources from the restored project file. /// </summary> /// ------------------------------------------------------------------------------------ private void GetDataSourcePathsFromPap() { string dummy = string.Empty; PaProject prj = PaProject.LoadProjectFileOnly(m_papPath, true, ref dummy); if (prj == null || prj.DataSources == null || prj.DataSources.Count == 0) { MessageBox.Show(this, Properties.Resources.kstidPrjIsEmptyMsg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } m_progressDlg.prgressBar.Value = 0; m_progressDlg.prgressBar.Maximum = prj.DataSources.Count; foreach (PaDataSource dataSource in prj.DataSources) { m_progressDlg.prgressBar.Value++; // Skip FieldWorks data source since we don't backup those. if (dataSource.DataSourceType != DataSourceType.FW) { int i = ProcessDataSourceFromPap(dataSource); dataSource.DataSourceFile = (i < 0 ? "X" : i.ToString()); } } // This should never happen, but just in case, remove all data // sources whose file couldn't be found for some reason. for (int i = prj.DataSources.Count - 1; i >= 0; i--) { if (prj.DataSources[i].DataSourceFile == "X") { prj.DataSources.RemoveAt(i); } } m_progressDlg.prgressBar.Value = m_progressDlg.prgressBar.Maximum; m_prjName = prj.ProjectName; STUtils.SerializeData(m_papPath, prj); prj.Dispose(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Goes through the data sources in the project just restored and changes the data /// source file paths to the path where the data sources were restored. /// </summary> /// ------------------------------------------------------------------------------------ private void ModifyDataSourcePathsInRestoredProject() { m_papPath = Path.Combine(txtPrjLocation.Text, Path.GetFileName(m_papPath)); PaProject prj = STUtils.DeserializeData(m_papPath, typeof(PaProject)) as PaProject; if (prj == null) { return; } foreach (PaDataSource dataSource in prj.DataSources) { int i; if (int.TryParse(dataSource.DataSourceFile, out i)) { string path = grid[1, i].Value as string; string file = grid[0, i].Value as string; dataSource.DataSourceFile = Path.Combine(path, file); } } STUtils.SerializeData(m_papPath, prj); prj.Dispose(); }