Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        /// <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);
            }
        }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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(); }
        }