private void mnuExportCopy_Click(object sender, RoutedEventArgs e) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Package Files|*.package"; dlg.DefaultExt = "package"; if (dlg.ShowDialog().GetValueOrDefault(false)) { List <DatabaseIndex> indices = new List <DatabaseIndex>(); foreach (var selectedItem in dataGridInstances.SelectedItems) { DatabaseIndex element = selectedItem as DatabaseIndex; indices.Add(element); } try { DatabasePackedFile.SaveAs(dlg.FileName, indices); } catch { System.Windows.Forms.MessageBox.Show("File is readonly", "Error"); } } }
private void mnuSave_Click(object sender, RoutedEventArgs e) { //Save As to a temp file, delete the old one and move the new one DatabasePackedFile PackageFile = (DatabasePackedFile)packageDataGrid.SelectedItem; if (PackageFile != null) { string tempFileName = string.Format("{0}\\{1}.temp", PackageFile.packageFileInfo.Directory.FullName, Guid.NewGuid()); string originalFileName = PackageFile.packageFileInfo.FullName; PackageFile.SaveAs(tempFileName); File.Delete(originalFileName); File.Move(tempFileName, originalFileName); } }
void worker_DoWork(object sender, DoWorkEventArgs e) { string gameFolder = e.Argument.ToString(); string ecoGamePath = gameFolder + @"\SimCityUserData\EcoGame\"; DirectoryInfo folderEcoGame = new DirectoryInfo(ecoGamePath); FileInfo[] scriptsFiles = folderEcoGame.GetFiles("SimCity-Scripts_*.package", SearchOption.TopDirectoryOnly); FileInfo scriptsFile = scriptsFiles.First(sf => sf.LastWriteTime == scriptsFiles.Max(sf2 => sf2.LastWriteTime)); DatabasePackedFile ScriptsPackage = DatabasePackedFile.LoadFromFile(scriptsFile.FullName); //get all scripts mods DirectoryInfo folderMods = new DirectoryInfo(gameFolder + @"\Mods\"); FileInfo[] packageFiles = folderMods.GetFiles("*.package"); int i = 0; foreach (FileInfo modPackageFile in packageFiles) { worker.ReportProgress((i * 100) / packageFiles.Length); DatabasePackedFile modPackage = DatabasePackedFile.LoadFromFile(modPackageFile.FullName); foreach (DatabaseIndex index in modPackage.Indices) { DatabaseIndex existingIndex = ScriptsPackage.Indices.FirstOrDefault(d => d.TypeId == index.TypeId && d.GroupId == index.GroupId && d.InstanceId == index.InstanceId); if (existingIndex != null) { existingIndex.IsModified = true; ModifiedGenericFile data = new ModifiedGenericFile(); data.FileData = index.GetIndexData(true); existingIndex.ModifiedData = data; existingIndex.Compressed = false; } else { ScriptsPackage.Indices.Add(index); } } i++; } string tempFileName = string.Format("{0}\\{1}.temp", ScriptsPackage.packageFileInfo.Directory.FullName, Guid.NewGuid()); string originalFileName = ScriptsPackage.packageFileInfo.FullName; ScriptsPackage.SaveAs(tempFileName); File.Delete(originalFileName); File.Move(tempFileName, originalFileName); }
private void mnuSaveAs_Click(object sender, RoutedEventArgs e) { DatabasePackedFile PackageFile = (DatabasePackedFile)packageDataGrid.SelectedItem; if (PackageFile != null) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Package Files|*.package"; dlg.DefaultExt = "package"; if (dlg.ShowDialog().GetValueOrDefault(false)) { PackageFile.SaveAs(dlg.FileName); } } }
private void mnuCopy_Click(object sender, RoutedEventArgs e) { //check if current index is a valid menu item if (this.DataContext.GetType() == typeof(DatabaseIndexData)) { DatabaseIndexData menuItemIndex = (DatabaseIndexData)this.DataContext; menuItemIndex.Index.IsModified = true; if (menuItemIndex.Index.InstanceType == (uint)PropertyFileTypeIds.Menu2) { SaveFileDialog dialog = new SaveFileDialog(); if (dialog.ShowDialog().GetValueOrDefault(false)) { List <DatabaseIndex> indices = new List <DatabaseIndex>(); menuItemIndex.Index.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(menuItemIndex.Index); PropertyFile menuFile = new PropertyFile(menuItemIndex.Index); #region Extract Icon if (menuFile.Values.ContainsKey(PropertyConstants.menuIcon)) { KeyProperty iconProperty = (KeyProperty)menuFile.Values[PropertyConstants.menuIcon]; DatabaseIndex iconIndex = DatabaseIndex.FindIndex(iconProperty.TypeId, null, null, iconProperty.InstanceId, true, false); iconIndex.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(iconIndex); iconProperty.InstanceId = iconIndex.ModifiedInstanceId.Value; menuItemIndex.Index.ModifiedData = new ModifiedPropertyFile() { PropertyFile = menuFile }; menuFile.Values[PropertyConstants.menuIcon] = iconProperty; } #endregion #region Extract Marquee Image if (menuFile.Values.ContainsKey(PropertyConstants.menuMarqueeImage)) { KeyProperty marqueeProperty = (KeyProperty)menuFile.Values[PropertyConstants.menuMarqueeImage]; DatabaseIndex marqueeIndex = DatabaseIndex.FindIndex(marqueeProperty.TypeId, null, null, marqueeProperty.InstanceId, true, false); marqueeIndex.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(marqueeIndex); marqueeProperty.InstanceId = marqueeIndex.ModifiedInstanceId.Value; menuItemIndex.Index.ModifiedData = new ModifiedPropertyFile() { PropertyFile = menuFile }; menuFile.Values[PropertyConstants.menuMarqueeImage] = marqueeProperty; } #endregion #region Extract Ecogame Unit if (menuFile.Values.ContainsKey(PropertyConstants.menuUnit)) { KeyProperty unitProperty = (KeyProperty)menuFile.Values[PropertyConstants.menuUnit]; DatabaseIndex unitIndex = DatabaseIndex.FindIndex((uint)TypeIds.PropertyFile, null, 0xe0, unitProperty.InstanceId, false, true); PropertyFile unitFile = new PropertyFile(unitIndex); unitFile.FlattenParentInheritance(); #region Extract Unit Display if (unitFile.Values.ContainsKey(PropertyConstants.ecoGameUnitDisplayModel)) { KeyProperty unitDisplayProperty = (KeyProperty)unitFile.Values[PropertyConstants.ecoGameUnitDisplayModel]; DatabaseIndex unitDisplayIndex = DatabaseIndex.FindIndex((uint)TypeIds.PropertyFile, null, 0xe1, unitDisplayProperty.InstanceId, false, true); unitDisplayIndex.ModifiedInstanceId = TGIRandomGenerator.GetNext(); unitDisplayProperty.InstanceId = unitDisplayIndex.ModifiedInstanceId.Value; unitFile.Values[PropertyConstants.ecoGameUnitDisplayModel] = unitDisplayProperty; PropertyFile unitDisplayFile = new PropertyFile(unitDisplayIndex); #region Extract LODs if (unitDisplayFile.Values.ContainsKey(PropertyConstants.UnitLOD1)) { KeyProperty LOD1Property = (KeyProperty)unitDisplayFile.Values[PropertyConstants.UnitLOD1]; DatabaseIndex LOD1Index = DatabaseIndex.FindIndex(LOD1Property.TypeId, null, null, LOD1Property.InstanceId, true, false); LOD1Index.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(LOD1Index); LOD1Property.InstanceId = LOD1Index.ModifiedInstanceId.Value; unitDisplayFile.Values[PropertyConstants.UnitLOD1] = LOD1Property; } if (unitDisplayFile.Values.ContainsKey(PropertyConstants.UnitLOD2)) { KeyProperty LOD2Property = (KeyProperty)unitDisplayFile.Values[PropertyConstants.UnitLOD2]; DatabaseIndex LOD2Index = DatabaseIndex.FindIndex(LOD2Property.TypeId, null, null, LOD2Property.InstanceId, true, false); LOD2Index.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(LOD2Index); LOD2Property.InstanceId = LOD2Index.ModifiedInstanceId.Value; unitDisplayFile.Values[PropertyConstants.UnitLOD2] = LOD2Property; } if (unitDisplayFile.Values.ContainsKey(PropertyConstants.UnitLOD3)) { KeyProperty LOD3Property = (KeyProperty)unitDisplayFile.Values[PropertyConstants.UnitLOD3]; DatabaseIndex LOD3Index = DatabaseIndex.FindIndex(LOD3Property.TypeId, null, null, LOD3Property.InstanceId, true, false); LOD3Index.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(LOD3Index); LOD3Property.InstanceId = LOD3Index.ModifiedInstanceId.Value; unitDisplayFile.Values[PropertyConstants.UnitLOD3] = LOD3Property; } if (unitDisplayFile.Values.ContainsKey(PropertyConstants.UnitLOD4)) { KeyProperty LOD4Property = (KeyProperty)unitDisplayFile.Values[PropertyConstants.UnitLOD4]; DatabaseIndex LOD4Index = DatabaseIndex.FindIndex(LOD4Property.TypeId, null, null, LOD4Property.InstanceId, true, false); LOD4Index.ModifiedInstanceId = TGIRandomGenerator.GetNext(); indices.Add(LOD4Index); LOD4Property.InstanceId = LOD4Index.ModifiedInstanceId.Value; unitDisplayFile.Values[PropertyConstants.UnitLOD4] = LOD4Property; } #endregion unitDisplayIndex.ModifiedData = new ModifiedPropertyFile() { PropertyFile = unitDisplayFile }; unitDisplayIndex.IsModified = true; indices.Add(unitDisplayIndex); } #endregion unitIndex.ModifiedInstanceId = TGIRandomGenerator.GetNext(); unitIndex.ModifiedData = new ModifiedPropertyFile() { PropertyFile = unitFile }; unitIndex.IsModified = true; indices.Add(unitIndex); unitProperty.InstanceId = unitIndex.ModifiedInstanceId.Value; menuItemIndex.Index.ModifiedData = new ModifiedPropertyFile() { PropertyFile = menuFile }; menuFile.Values[PropertyConstants.menuUnit] = unitProperty; } #endregion DatabasePackedFile.SaveAs(dialog.FileName, indices); } } else { MessageBox.Show("This only works for menu items..."); } } }