public void ScanPackage(ScannerItem si, SimPe.Cache.PackageState ps, System.Windows.Forms.ListViewItem lvi) { this.LoadThumbnail(si, ps); if (si.PackageCacheItem.Type == PackageType.Neighborhood) { Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(Data.MetaData.IDNO); if (pfds.Length > 0) { Idno idno = new Idno(); idno.ProcessData(pfds[0], si.Package); ps.Data = new uint[2]; ps.Data[0] = (uint)idno.Type; ps.Data[1] = idno.Uid; //check for duplicates if (ids.Contains(idno.Uid)) { ps.State = TriState.False; } else { ps.State = TriState.True; } } } if (si.PackageCacheItem.Thumbnail != null && WaitingScreen.Running) { WaitingScreen.UpdateImage(si.PackageCacheItem.Thumbnail); } UpdateState(si, ps, lvi); }
/// <summary> /// Is called by SimPe (through the Wrapper) when the Panel is going to be displayed, so /// you should updatet the Data displayed by the Panel with the Attributes stored in the /// passed Wrapper. /// </summary> /// <param name="wrapper">The Attributes of this Wrapper have to be displayed</param> public void UpdateGUI(IFileWrapper wrapper) { Idno wrp = (Idno)wrapper; form.wrapper = null; form.Tag = true; try { form.cbtype.SelectedIndex = 0; for (int i = 0; i < form.cbtype.Items.Count; i++) { NeighborhoodType lt = (NeighborhoodType)form.cbtype.Items[i]; if (lt == wrp.Type) { form.cbtype.SelectedIndex = i; break; } } form.tbtype.Text = "0x" + Helper.HexString((byte)wrp.Type); form.tbversion.Text = "0x" + Helper.HexString((uint)wrp.Version); form.lbVer.Text = wrp.Version.ToString().Replace("_", " "); form.tbid.Text = wrp.Uid.ToString(); form.tbname.Text = wrp.OwnerName; form.tbsubname.Text = wrp.SubName; form.wrapper = wrp; } finally { form.Tag = null; } }
/// <summary> /// Returns a Idno Object based on the Informations gathered from a FileName /// </summary> /// <param name="filename">The name of the Neighborhood File</param> /// <returns> /// null if the filename was not a valid Neighborhood name or an instance of the Idno Class /// </returns> /// <remarks> /// This Method will not assign a uid to the Idno. You can assign a unique uid /// by calling Idno::MakeUnique /// </remarks> public static Idno FromName(string filename) { Idno idno = new Idno(); filename = System.IO.Path.GetFileNameWithoutExtension(filename.Trim()); string[] parts = filename.Split("_".ToCharArray(), 2); if (parts.Length != 2) { return(null); } if (!parts[0].StartsWith("N")) { return(null); } idno.OwnerName = parts[0]; parts[1] = parts[1].ToLower(); if (parts[1].StartsWith("university")) { idno.Type = NeighborhoodType.University; parts[1] = "U" + parts[1].Replace("university", ""); idno.SubName = parts[1]; } return(idno); }
private static string LoadLabel(SimPe.Packages.File pk, out NeighborhoodType type) { string name = SimPe.Localization.GetString("Unknown"); type = NeighborhoodType.Unknown; try { SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pk.FindFile(0x43545353, 0, 0xffffffff, 1); if (pfd != null) { SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str(); str.ProcessData(pfd, pk); name = str.LanguageItems(new SimPe.PackedFiles.Wrapper.StrLanguage((byte)Data.MetaData.Languages.English))[0].Title; } pfd = pk.FindFile(0xAC8A7A2E, 0, 0xffffffff, 1); if (pfd != null) { SimPe.Plugin.Idno idno = new Idno(); idno.ProcessData(pfd, pk); type = idno.Type; } //pk.Reader.Close(); } finally { //pk.Reader.Close(); } return(name); }
/// <summary> /// Scan the passed Folder for Neighborhood Files and collect the assigned IDs /// </summary> /// <param name="folder">The Folder to scan (recursive)</param> /// <param name="ids">A Map for ids (key=filename, value=id)</param> /// <param name="scanall"> /// true, if you want to scan all package Files in the Folder /// (otherwise only Neighborhood Files are scanned!) /// </param> static void FindUids(string folder, Hashtable ids, bool scanall) { Wait.Message = (folder); ArrayList names = new ArrayList(); if (!scanall) { string[] a = System.IO.Directory.GetFiles(folder, "N???_Neighborhood.package"); foreach (string s in a) { names.Add(s); } a = System.IO.Directory.GetFiles(folder, "N???_University???.package"); foreach (string s in a) { names.Add(s); } } else { string[] a = System.IO.Directory.GetFiles(folder, "*.package"); foreach (string s in a) { names.Add(s); } } foreach (string name in names) { SimPe.Packages.File fl = SimPe.Packages.File.LoadFromFile(name); SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = fl.FindFiles(Data.MetaData.IDNO); foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds) { Idno idno = new Idno(); idno.ProcessData(pfd, fl); ids[name.Trim().ToLower()] = idno.Uid; } } string[] d = System.IO.Directory.GetDirectories(folder, "*"); foreach (string dir in d) { FindUids(dir, ids, scanall); } }
/// <summary> /// Load the IdNo stored in the passed package /// </summary> /// <param name="pkg"></param> /// <returns></returns> public static Idno FromPackage(SimPe.Interfaces.Files.IPackageFile pkg) { if (pkg == null) { return(null); } Interfaces.Files.IPackedFileDescriptor idno = pkg.FindFile(Data.MetaData.IDNO, 0, Data.MetaData.LOCAL_GROUP, 1); if (idno != null) { SimPe.Plugin.Idno wrp = new Idno(); wrp.ProcessData(idno, pkg); return(wrp); } return(null); }
/// <summary> /// Assigns a unique uid to the idno /// </summary> /// <param name="idno">the idno object</param> /// <param name="filename">the Filename</param> /// <param name="ids">a Map of all available Group Ids (can be obtained by calling Idno::FindUids())</param> /// <remarks> /// </remarks> public static void MakeUnique(Idno idno, string filename, Hashtable ids) { if (idno == null) { return; } if (filename == null) { return; } filename = filename.Trim().ToLower(); if (ids.ContainsKey(filename)) { idno.Uid = (uint)ids[filename]; } else { idno.Uid = 1; } uint max = 0; foreach (string flname in ids.Keys) { uint id = (uint)ids[flname]; if (id > max) { max = id; } if (flname == filename) { continue; } if (idno.Uid == id) { idno.Uid = max + 1; } } }
public Interfaces.Plugin.IToolResult ShowDialog(ref SimPe.Interfaces.Files.IPackedFileDescriptor pfd, ref SimPe.Interfaces.Files.IPackageFile package) { System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show("Using this Tool can serioulsy mess up all of your Neighborhoods. However if some of your Neighborhoods are missing in the Neighborhood Selection of the Game, this Tool might help fixing it.\n\nMake sure you have a Backup of ALL your Neighborhoods befor starting this Tool!\n\nDo you want to start this Tool?", "Confirmation", System.Windows.Forms.MessageBoxButtons.YesNo); if (dr == System.Windows.Forms.DialogResult.Yes) { Wait.SubStop(); try { System.Collections.Hashtable ht = Idno.FindUids(PathProvider.SimSavegameFolder, true); foreach (string file in ht.Keys) { Wait.Message = file; SimPe.Packages.GeneratableFile fl = SimPe.Packages.GeneratableFile.LoadFromFile(file); SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = fl.FindFiles(Data.MetaData.IDNO); foreach (SimPe.Interfaces.Files.IPackedFileDescriptor spfd in pfds) { Idno idno = new Idno(); idno.ProcessData(spfd, fl); idno.MakeUnique(ht); idno.SynchronizeUserData(); } fl.Save(); } } catch (Exception ex) { Helper.ExceptionMessage("", ex); } finally { Wait.SubStop(); } } return(new ToolResult(false, false)); }
/// <summary> /// Make sure this contains a Unique ID! /// </summary> /// <param name="ids">a Map of all available Group Ids (can be obtained by calling Idno::FindUids())</param> public void MakeUnique(Hashtable ids) { Wait.SubStart(); Idno.MakeUnique(this, this.Package.FileName, ids); Wait.SubStop(); }
/// <summary> /// Make sure this contains a Unique ID! /// </summary> public void MakeUnique() { Wait.SubStart(); Idno.MakeUnique(this, this.Package.FileName, true); Wait.SubStop(); }
/// <summary> /// Assigns a unique uid to the idno /// </summary> /// <param name="idno">the idno object</param> /// <param name="filename">the Filename</param> /// <param name="folder">The folder you want to scan (recursive)</param> /// <param name="scanall"> /// true, if you want to scan all package Files in the Folder /// (otherwise only Neighborhood Files are scanned!) /// </param> /// <remarks> /// </remarks> public static void MakeUnique(Idno idno, string filename, string folder, bool scanall) { Hashtable ids = FindUids(PathProvider.SimSavegameFolder, scanall); MakeUnique(idno, filename, ids); }
/// <summary> /// Assigns a unique uid to the idno /// </summary> /// <param name="idno">the idno object</param> /// <param name="filename">the Filename</param> /// <param name="scanall"> /// true, if you want to scan all package Files in the Folder /// (otherwise only Neighborhood Files are scanned!) /// </param> /// <remarks> /// </remarks> public static void MakeUnique(Idno idno, string filename, bool scanall) { MakeUnique(idno, filename, PathProvider.SimSavegameFolder, scanall); }
private void MakeUnique(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { if (selection == null) { return; } WaitingScreen.Wait(); bool chg = false; try { Hashtable ids = Idno.FindUids(PathProvider.SimSavegameFolder, true); foreach (ScannerItem si in selection) { if (si.PackageCacheItem.Thumbnail != null) { WaitingScreen.Update(si.PackageCacheItem.Thumbnail, si.FileName); } else { WaitingScreen.UpdateMessage(si.FileName); } SimPe.Cache.PackageState ps = si.PackageCacheItem.FindState(this.Uid, true); if (si.PackageCacheItem.Type == PackageType.Neighborhood) { Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(Data.MetaData.IDNO); if (pfds.Length > 0) { Idno idno = new Idno(); idno.ProcessData(pfds[0], si.Package); idno.MakeUnique(ids); if (ps.Data.Length < 2) { ps.Data = new uint[2]; } if (idno.Uid != ps.Data[1]) { idno.SynchronizeUserData(); si.Package.Save(); chg = true; ps.Data[1] = idno.Uid; ps.State = TriState.True; } } } } if (chg && this.CallbackFinish != null) { this.CallbackFinish(false, false); } } #if !DEBUG catch (Exception ex) { Helper.ExceptionMessage("", ex); } #endif finally { WaitingScreen.Stop(); } }