Ejemplo n.º 1
0
        public static void Execute(SimPe.Plugin.Anim.AnimResourceConst anim)
        {
            AnimPreview f = new AnimPreview();

            WaitingScreen.Wait();
            Wait.SubStart(anim.MeshBlock.Length);
            try
            {
                WaitingScreen.UpdateMessage(SimPe.Localization.GetString("Loading Meshes"));
                int ct = 0;
                foreach (SimPe.Plugin.Anim.AnimationMeshBlock amb in anim.MeshBlock)
                {
                    f.lb.Items.Add(new ListedMeshBlocks(amb));
                    Wait.Progress = ct++;
                }
            }
            finally
            {
                Wait.SubStop();
                WaitingScreen.Stop();
            }

            f.ShowDialog();

            f.timer1.Enabled = false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Show the Graph
        /// </summary>
        /// <param name="pkg"></param>
        /// <param name="fileindex"></param>
        /// <remarks>Do not run twice</remarks>
        public void BuildGraph(SimPe.Interfaces.Files.IPackageFile pkg, SimPe.Interfaces.Scenegraph.IScenegraphFileIndex fileindex)
        {
            gc.BeginUpdate();
            gc.Clear();
            gc.SaveBounds = false;
            gc.AutoSize   = true;
            this.coords.Clear();
            this.names.Clear();
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Scaning MMAT Tree");
            }
            SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFiles(Data.MetaData.MMAT);
            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                AddItem(pfd, pkg, null, fileindex);
            }

            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Scaning CRES Tree");
            }
            pfds = pkg.FindFiles(Data.MetaData.CRES);
            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                AddItem(pfd, pkg, null, fileindex);
            }

            gc.AutoSize   = false;
            gc.SaveBounds = true;
            gc.EndUpdate();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add all Files that could be borrowed from the current package by the passed one, to the passed package
        /// </summary>
        /// <param name="orgmodelnames">List of available modelnames in this package</param>
        /// <param name="pkg">The package that should receive the Files</param>
        /// <remarks>Simply Copies MMAT, LIFO, TXTR and TXMT Files</remarks>
        public void AddParentFiles(string[] orgmodelnames, SimPe.Interfaces.Files.IPackageFile pkg)
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Loading Parent Files");
            }
            ArrayList names = new ArrayList();

            foreach (string s in orgmodelnames)
            {
                names.Add(s);
            }

            ArrayList types = new ArrayList();

            types.Add(Data.MetaData.MMAT);
            types.Add(Data.MetaData.TXMT);
            types.Add(Data.MetaData.TXTR);
            types.Add(Data.MetaData.LIFO);

            foreach (uint type in types)
            {
                SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(type);
                foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    if (pkg.FindFile(pfd) != null)
                    {
                        continue;
                    }

                    SimPe.Interfaces.Files.IPackedFile file = package.Read(pfd);
                    pfd.UserData = file.UncompressedData;

                    //Update the modeName in the MMAT
                    if ((pfd.Type == Data.MetaData.MMAT) && (names.Count > 0))
                    {
                        SimPe.Plugin.MmatWrapper mmat = new MmatWrapper();
                        mmat.ProcessData(pfd, package);

                        string n = mmat.ModelName.Trim().ToLower();
                        if (!n.EndsWith("_cres"))
                        {
                            n += "_cres";
                        }

                        if (!names.Contains(n))
                        {
                            n = names[0].ToString();
                            //n = n.Substring(0, n.Length-5);
                            mmat.ModelName = n;
                            mmat.SynchronizeUserData();
                        }
                    }

                    pkg.Add(pfd);
                }
            }             //foreach type
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Doanload A File from the Internet
        /// </summary>
        /// <param name="URL"></param>
        /// <param name="Filename"></param>
        /// <param name="progress"></param>
        public static void DownloadFile(string URL, string Filename)
        {
            WebClient cli = new WebClient();
            Stream    fDnld = null, fOut = null;

            if (Helper.StartedGui == Executable.Classic)
            {
                WaitingScreen.Wait();
            }
            else
            {
                Wait.SubStart();
            }
            int total = 0;

            try
            {
                fDnld = cli.OpenRead(URL);
                string sTotal = cli.ResponseHeaders["Content-Length"];
                int    nTotal = (sTotal == null || sTotal.Length == 0) ? 0 : Convert.ToInt32(sTotal);

                fOut = File.Create(Filename);
                byte[] buf = new byte[4096];
                int    nBytesRead;
                while ((nBytesRead = fDnld.Read(buf, 0, buf.Length)) > 0)
                {
                    total += nBytesRead;
                    WaitingScreen.UpdateMessage(total.ToString() + " of " + nTotal.ToString());
                    Wait.Message = total.ToString() + " of " + nTotal.ToString();
                    fOut.Write(buf, 0, nBytesRead);
                }
            }
            catch { throw; }
            finally
            {
                if (Helper.StartedGui == Executable.Classic)
                {
                    WaitingScreen.Stop();
                }
                else
                {
                    Wait.SubStop();
                }
                if (fDnld != null)
                {
                    fDnld.Close();
                }
                if (fOut != null)
                {
                    fOut.Close(); fOut.Dispose(); fOut = null;
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Load all MATDs referenced by the passed MMATs
 /// </summary>
 /// <param name="pfds">List of MMAT Descriptors from the current Package</param>
 protected void LoadReferencedMATDs(Interfaces.Files.IPackedFileDescriptor[] pfds)
 {
     //WaitingScreen.Wait();
     if (WaitingScreen.Running)
     {
         WaitingScreen.UpdateMessage("Loading Material Overrides");
     }
     foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
     {
         SimPe.PackedFiles.Wrapper.Cpf mmat = new SimPe.PackedFiles.Wrapper.Cpf();
         mmat.ProcessData(pfd, package);
         AddMATD(mmat);
     }
     //WaitingScreen.Stop();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads the ModelNames of the Objects referenced in all tsMaterialsMeshName Block
        /// </summary>
        /// <param name="pkg"></param>
        /// <param name="delete">true, if the tsMaterialsMeshName Blocks should get cleared</param>
        /// <returns>A List of Modelnames</returns>
        public static string[] LoadParentModelNames(SimPe.Interfaces.Files.IPackageFile pkg, bool delete)
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Loading Parent Modelnames");
            }
            ArrayList list = new ArrayList();

            Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFiles(Data.MetaData.GMND);
            foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                Rcol rcol = new GenericRcol(null, false);
                rcol.ProcessData(pfd, pkg);

                foreach (IRcolBlock irb in rcol.Blocks)
                {
                    if (irb.BlockName.Trim().ToLower() == "cdatalistextension")
                    {
                        DataListExtension dle = (DataListExtension)irb;
                        if (dle.Extension.VarName.Trim().ToLower() == "tsmaterialsmeshname")
                        {
                            foreach (ExtensionItem ei in dle.Extension.Items)
                            {
                                string mname = ei.String.Trim().ToLower();
                                if (mname.EndsWith("_cres"))
                                {
                                    mname += "_cres";
                                }

                                if (!list.Contains(mname))
                                {
                                    list.Add(mname);
                                }
                            }

                            dle.Extension.Items = new ExtensionItem[0];
                            rcol.SynchronizeUserData();
                            break;
                        }
                    }
                }
            }

            string[] ret = new string[list.Count];
            list.CopyTo(ret);

            return(ret);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create a new Color Options package
        /// </summary>
        /// <param name="newpkg">The Package the color Option should be added to</param>
        /// <param name="ask">if ask is true, a Dialog will be displayed that lets the
        /// user decide which Subsets to recolor</param>
        public void Create(IPackageFile newpkg)
        {
            WaitingScreen.Wait();
            try
            {
                //this.newpkg = newpkg;

                WaitingScreen.UpdateMessage("Loading available Color Options");
                Hashtable fullmap        = Scenegraph.GetMMATMap(package);
                Hashtable map            = fullmap;
                ArrayList allowedSubsets = Scenegraph.GetRecolorableSubsets(package);

                //Check if the User can select a Subset
                bool userselect = false;
                if (map.Count > 1)
                {
                    userselect = true;
                }
                else
                {
                    if (map.Count == 1)
                    {
                        foreach (string s in map.Keys)
                        {
                            Hashtable ht = (Hashtable)map[s];
                            if (ht.Count > 1)
                            {
                                userselect = true;
                            }
                        }
                    }
                }

                //let the user Select now
                if (userselect)
                {
                    map = SubsetSelectForm.Execute(map, allowedSubsets);
                }



                ProcessMmatMap(newpkg, map, fullmap);
            }
            finally
            {
                WaitingScreen.Stop();
            }
        }
Ejemplo n.º 8
0
        protected static SimPe.Packages.GeneratableFile ReColorXObject(CloneSettings.BaseResourceType br, SimPe.Packages.GeneratableFile pkg, Interfaces.Files.IPackedFileDescriptor pfd, uint localgroup, ObjectWorkshopSettings settings)
        {
            settings.KeepOriginalMesh = true;
            SimPe.Packages.GeneratableFile package = pkg;
            // we need packages in the Gmaes and the Download Folder

            if (((!System.IO.File.Exists(ScenegraphHelper.GMND_PACKAGE)) || (!System.IO.File.Exists(ScenegraphHelper.MMAT_PACKAGE))) && (settings is OWCloneSettings))
            {
                if (Message.Show(Localization.Manager.GetString("OW_Warning"), "Warning", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return(package);
                }
            }

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = ExtensionProvider.BuildFilterString(
                new SimPe.ExtensionType[] {
                SimPe.ExtensionType.Package,
                SimPe.ExtensionType.AllFiles
            }
                );
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return(package);
            }

            //create a Cloned Object to get all needed Files for the Process
            WaitingScreen.Wait();
            try
            {
                WaitingScreen.UpdateMessage("Collecting needed Files");

                if ((package == null) && (pfd != null))
                {
                    package = RecolorClone(br, package, pfd, localgroup, settings, false);
                }
            }
            finally { WaitingScreen.Stop(); }

            package.FileName = sfd.FileName;
            package.Save();

            return(package);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Setup the Form
        /// </summary>
        /// <param name="map">The subset map</param>
        /// <param name="subsets">the subsets you want to present</param>
        /// <returns>Returns a New Instance of the selection Form</returns>
        public static SubsetSelectForm Prepare(Hashtable map, ArrayList subsets)
        {
            SubsetSelectForm ssf = new SubsetSelectForm();

            ssf.listviews = new ArrayList();
            ssf.txmtnames = new Hashtable();
            WaitingScreen.Wait();
            try
            {
                WaitingScreen.UpdateMessage("Show Subset Selection");
                ssf.button1.Enabled = false;

                int top = 0;
                foreach (string subset in map.Keys)
                {
                    if (!subsets.Contains(subset))
                    {
                        continue;
                    }

                    ListView  lv       = ssf.AddSelection(ssf, subset, ref top);
                    Hashtable families = (Hashtable)map[subset];
                    foreach (string family in families.Keys)
                    {
                        ArrayList mmats = (ArrayList)families[family];
                        mmats.Sort(new MmatListCompare());
                        ssf.AddItem(lv, mmats);
                    }

                    if (lv.Items.Count > 0)
                    {
                        lv.Items[0].Selected = true;
                    }
                }
            }
            finally
            {
                WaitingScreen.Stop();
            }

            return(ssf);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Remove some unreferenced and useless Files
        /// </summary>
        public void CleanUp()
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Cleaning up");
            }
            Interfaces.Files.IPackedFileDescriptor[] mpfds = package.FindFiles(Data.MetaData.MMAT);             //MMAT
            ArrayList mmats = new ArrayList();

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds)
            {
                SimPe.PackedFiles.Wrapper.Cpf mmat = new SimPe.PackedFiles.Wrapper.Cpf();
                mmat.ProcessData(pfd, package);

                string content = Scenegraph.MmatContent(mmat);

                if (!mmats.Contains(content))
                {
                    string txmtname = (string)Hashes.StripHashFromName(mmat.GetSaveItem("name").StringValue.Trim().ToLower()) + "_txmt";
                    string cresname = (string)Hashes.StripHashFromName(mmat.GetSaveItem("modelName").StringValue.Trim().ToLower());

                    if (package.FindFile(Hashes.StripHashFromName(txmtname), 0x49596978).Length < 0)
                    {
                        pfd.MarkForDelete = true;
                    }
                    if (package.FindFile(Hashes.StripHashFromName(cresname), 0xE519C933).Length < 0)
                    {
                        pfd.MarkForDelete = true;
                    }

                    if (!pfd.MarkForDelete)
                    {
                        mmats.Add(content);
                    }
                }
                else
                {
                    pfd.MarkForDelete = true;
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Make sure the fixes for OBJd Resources are considered
        /// </summary>
        /// <remarks>
        /// Currently this implements the Fixes needed for Rugs
        /// </remarks>
        void FixOBJd()
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Updating Object Descriuptions");
            }
            Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(Data.MetaData.OBJD_FILE);                 //OBJd

            bool updaterugs = false;

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                SimPe.PackedFiles.Wrapper.ExtObjd objd = new SimPe.PackedFiles.Wrapper.ExtObjd();
                objd.ProcessData(pfd, package);

                //is one of the objd's a rug?
                if (objd.FunctionSubSort == SimPe.Data.ObjFunctionSubSort.Decorative_Rugs)
                {
                    updaterugs = true;
                    break;
                }
            }

            //found at least one OBJd describing a Rug
            if (updaterugs)
            {
                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    SimPe.PackedFiles.Wrapper.ExtObjd objd = new SimPe.PackedFiles.Wrapper.ExtObjd();
                    objd.ProcessData(pfd, package);

                    //make sure the Type of a Rug is not a Tile, but Normal
                    if (objd.Type == SimPe.Data.ObjectTypes.Tiles)
                    {
                        objd.Type = SimPe.Data.ObjectTypes.Normal;
                        objd.SynchronizeUserData(true, true);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Adds the MMAT Files specified in the map to the new package
        /// </summary>
        /// <param name="newpkg"></param>
        /// <param name="map">Contains the MMATs that should be added</param>
        /// <param name="fullmap">Contains a List of all available MMATs</param>
        public void ProcessMmatMap(IPackageFile newpkg, Hashtable map, Hashtable fullmap)
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Loading Slave Subsets");
            }
            AddSlavesSubsets(map, fullmap);
            Hashtable slaves = Scenegraph.GetSlaveSubsets(package);

            uint   inst   = 0x6000;
            string unique = RenameForm.GetUniqueName(true);

            foreach (Hashtable ht in map.Values)
            {
                foreach (ArrayList list in ht.Values)
                {
                    string family = System.Guid.NewGuid().ToString();
                    if (unique == null)
                    {
                        unique = family;
                    }

                    foreach (SimPe.Plugin.MmatWrapper mmat in list)
                    {
                        mmat.FileDescriptor          = Scenegraph.Clone(mmat.FileDescriptor);
                        mmat.FileDescriptor.Instance = inst++;
                        mmat.FileDescriptor.Group    = Data.MetaData.LOCAL_GROUP;
                        mmat.Family          = family;
                        mmat.DefaultMaterial = false;

                        GenericRcol txmt = mmat.TXMT;
                        GenericRcol txtr = mmat.TXTR;
                        this.AddTxmt(newpkg, mmat, txmt, txtr, unique, slaves);

                        mmat.SynchronizeUserData();
                        newpkg.Add(mmat.FileDescriptor);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Runs the Fix Operation
        /// </summary>
        /// <param name="map">the map we have to use for name Replacements</param>
        /// <param name="uniquefamily">change the family values in the MMAT Files</param>
        public void Fix(Hashtable map, bool uniquefamily)
        {
            string grouphash = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!";        //"#0x"+Helper.HexString(package.FileGroupHash)+"!";


            Hashtable refmap         = new Hashtable();
            Hashtable completerefmap = new Hashtable();

            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Fixing Names");
            }
            FixNames(map);

            foreach (uint type in Data.MetaData.RcolList)
            {
                Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(type);

                //build a List of RefItems
                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    SimPe.Plugin.Rcol rcol = new GenericRcol(null, false);
                    rcol.ProcessData(pfd, package);

                    //rcol.FileName = Hashes.StripHashFromName(rcol.);

                    /*if (types.Contains(pfd.Type)) rcol. = Hashes.StripHashFromName(rcol.);
                     * else rcol.FileName = grouphash + Hashes.StripHashFromName(rcol.FileName);*/

                    foreach (Interfaces.Files.IPackedFileDescriptor rpfd in rcol.ReferencedFiles)
                    {
                        string refstr = BuildRefString(rpfd);
                        if (!refmap.Contains(refstr))
                        {
                            refmap.Add(refstr, null);
                        }
                    }
                    //rcol.SynchronizeUserData();
                }
            }

            //Updated TGI Values and update the refmap
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Updating TGI Values");
            }
            foreach (uint type in Data.MetaData.RcolList)
            {
                Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(type);

                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    string            refstr = BuildRefString(pfd);
                    SimPe.Plugin.Rcol rcol   = new GenericRcol(null, false);
                    rcol.ProcessData(pfd, package);

                    //rcol.FileName = grouphash + Hashes.StripHashFromName(rcol.);
                    rcol.FileDescriptor.Instance = Hashes.InstanceHash(Hashes.StripHashFromName(rcol.FileName));
                    rcol.FileDescriptor.SubType  = Hashes.SubTypeHash(Hashes.StripHashFromName(rcol.FileName));

                    if (refmap.Contains(refstr))
                    {
                        refmap[refstr] = rcol.FileDescriptor;
                    }
                    completerefmap[refstr] = rcol.FileDescriptor;
                }
            }

            //Update the References
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Updating TGI References");
            }
            foreach (uint type in Data.MetaData.RcolList)
            {
                Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(type);

                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    SimPe.Plugin.Rcol rcol = new GenericRcol(null, false);
                    rcol.ProcessData(pfd, package);

                    foreach (Interfaces.Files.IPackedFileDescriptor rpfd in rcol.ReferencedFiles)
                    {
                        string refstr = Helper.HexString(rpfd.Group) + Helper.HexString(rpfd.Type) + Helper.HexString(rpfd.Instance) + Helper.HexString(rpfd.SubType);

                        if (ver == FixVersion.UniversityReady2)
                        {
                            if (types.Contains(rpfd.Type))
                            {
                                rpfd.Group = Data.MetaData.CUSTOM_GROUP;
                            }
                            else
                            {
                                rpfd.Group = Data.MetaData.LOCAL_GROUP;
                            }
                        }
                        else
                        {
                            if (rpfd.Type != Data.MetaData.ANIM)
                            {
                                rpfd.Group = Data.MetaData.CUSTOM_GROUP;
                            }
                            else
                            {
                                rpfd.Group = Data.MetaData.GLOBAL_GROUP;
                            }
                        }

                        if (refmap.Contains(refstr))
                        {
                            Interfaces.Files.IPackedFileDescriptor npfd = (Interfaces.Files.IPackedFileDescriptor)refmap[refstr];
                            if (npfd != null)
                            {
                                rpfd.Instance = npfd.Instance;
                                rpfd.SubType  = npfd.SubType;
                            }
                        }
                    }                     //foreach

                    rcol.SynchronizeUserData();
                }
            }

            //Make sure XObjects and Skins get Fixed Too
            FixXObject(map, completerefmap, grouphash);
            FixSkin(map, completerefmap, grouphash);

            //Make sure MMATs get fixed
            FixMMAT(map, uniquefamily, grouphash);

            //Make sure OBJd's get fixed too
            FixOBJd();

            //And finally the Root String
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Updating Root");
            }
            SimPe.Interfaces.Files.IPackedFileDescriptor[] mpfds = package.FindFiles(Data.MetaData.STRING_FILE);
            string modelname = null;

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds)
            {
                SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str();
                str.ProcessData(pfd, package);

                foreach (SimPe.PackedFiles.Wrapper.StrToken i in str.Items)
                {
                    string name = Hashes.StripHashFromName(i.Title.Trim().ToLower());

                    if (name == "")
                    {
                        continue;
                    }
                    if (pfd.Instance == 0x88)
                    {
                        if (!name.EndsWith("_txmt"))
                        {
                            name += "_txmt";
                        }
                    }
                    else if (pfd.Instance == 0x85)
                    {
                        if (!name.EndsWith("_cres"))
                        {
                            name += "_cres";
                        }
                    }
                    else if ((pfd.Instance == 0x81) || (pfd.Instance == 0x82) || (pfd.Instance == 0x86) || (pfd.Instance == 0x192))
                    {
                        if (!name.EndsWith("_anim"))
                        {
                            name += "_anim";
                        }
                    }
                    else
                    {
                        continue;
                    }


                    string newref = (string)map[name];
                    if (newref != null)
                    {
                        i.Title = Hashes.StripHashFromName(newref.Substring(0, newref.Length - 5));
                    }
                    else
                    {
                        i.Title = Hashes.StripHashFromName(i.Title);
                    }

                    if (((ver == FixVersion.UniversityReady) || (pfd.Instance == 0x88)) && (newref != null))
                    {
                        i.Title = Hashes.StripHashFromName(i.Title);

                        if (!((pfd.Instance == 0x81) || (pfd.Instance == 0x82) || (pfd.Instance == 0x86) || (pfd.Instance == 0x192)))
                        {
                            i.Title = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + i.Title;
                        }
                    }
                    else
                    {
                        uint tp = Data.MetaData.ANIM;
                        if (pfd.Instance == 0x88)
                        {
                            tp = Data.MetaData.TXMT;
                        }
                        else if (pfd.Instance == 0x85)
                        {
                            tp = Data.MetaData.CRES;
                        }

                        SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem fii = FileTable.FileIndex.FindFileByName(i.Title, tp, Data.MetaData.LOCAL_GROUP, true);
                        if (fii != null)
                        {
                            if (fii.FileDescriptor.Group == Data.MetaData.CUSTOM_GROUP)
                            {
                                i.Title = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + Hashes.StripHashFromName(i.Title);
                            }
                        }
                    }

                    if ((modelname == null) && (i.Language.Id == 1) && (pfd.Instance == 0x85))
                    {
                        modelname = name.ToUpper().Replace("-", "_");
                    }
                }

                if (RemoveNonDefaultTextReferences)
                {
                    if (pfd.Instance == 0x88 || pfd.Instance == 0x85 || (pfd.Instance == 0x81) || (pfd.Instance == 0x82) || (pfd.Instance == 0x86) || (pfd.Instance == 0x192))
                    {
                        str.ClearNonDefault();
                    }
                }


                str.SynchronizeUserData();
            }

            //Now change the NREF

            if (modelname != null)
            {
                mpfds = package.FindFiles(0x4E524546);
                foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds)
                {
                    SimPe.PackedFiles.Wrapper.Nref nref = new SimPe.PackedFiles.Wrapper.Nref();
                    nref.ProcessData(pfd, package);
                    if (ver == FixVersion.UniversityReady)
                    {
                        nref.FileName = "SIMPE_" + modelname;
                    }
                    else
                    {
                        nref.FileName = "SIMPE_v2_" + modelname;
                    }

                    nref.SynchronizeUserData();
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Clone a InGane Object based on the relations of the RCOL Files
        /// </summary>
        /// <param name="onlydefault">true if you only want default MMAT Files</param>
        /// <param name="exclude">List of ReferenceNames that should be excluded</param>
        public void RcolModelClone(string[] modelnames, ArrayList exclude)
        {
            if (modelnames == null)
            {
                return;
            }

            Scenegraph.FileExcludeList = Scenegraph.DefaultFileExcludeList;

            SimPe.FileTable.FileIndex.Load();
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Walking Scenegraph");
            }
            Scenegraph sg = new Scenegraph(modelnames, exclude, this.setup);

            if ((Setup.BaseResource & CloneSettings.BaseResourceType.Ref) == CloneSettings.BaseResourceType.Ref)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateMessage("Reading 3IDR References");
                }
                sg.AddFrom3IDR(package);
            }
            if ((Setup.BaseResource & CloneSettings.BaseResourceType.Xml) == CloneSettings.BaseResourceType.Xml)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateMessage("Reading XObject Definition");
                }
                sg.AddFromXml(package);
            }
            if (Setup.IncludeWallmask)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateMessage("Scanning for Wallmasks");
                }
                sg.AddWallmasks(modelnames);
            }
            if (Setup.PullResourcesByStr)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateMessage("Scanning for #Str-linked Resources");
                }
                sg.AddStrLinked(package, Setup.StrInstances);
            }
            if (Setup.IncludeAnimationResources)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateMessage("Scanning for Animations");
                }
                sg.AddAnims(this.GetAnimNames());
            }
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Collect Slave TXMTs");
            }
            sg.AddSlaveTxmts(sg.GetSlaveSubsets());

            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Building Package");
            }
            sg.BuildPackage(package);
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Collect MMAT Files");
            }
            sg.AddMaterialOverrides(package, setup.OnlyDefaultMmats, true, setup.ThrowExceptions);
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Collect Slave TXMTs");
            }
            Scenegraph.AddSlaveTxmts(package, Scenegraph.GetSlaveSubsets(package));


            if (setup.UpdateMmatGuids)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateMessage("Fixing MMAT Files");
                }
                this.UpdateMMATGuids(this.GetGuidList(), this.GetPrimaryGuid());
            }
        }
Ejemplo n.º 15
0
        public static void Execute(SimPe.Events.ResourceContainers es)
        {
            //Select the Type
            if (Helper.WindowsRegistry.ReportFormat == Registry.ReportFormats.CSV)
            {
                Serializer.Formater = new CsvSerializer();
            }

            System.Collections.Hashtable map = new System.Collections.Hashtable();

            foreach (SimPe.Events.ResourceContainer e in es)
            {
                uint t = e.Resource.FileDescriptor.Type;
                SimPe.Events.ResourceContainers o = map[t] as SimPe.Events.ResourceContainers;
                if (o == null)
                {
                    o      = new SimPe.Events.ResourceContainers();
                    map[t] = o;
                }

                o.Add(e);
            }

            System.IO.StreamWriter sw = new System.IO.StreamWriter(new System.IO.MemoryStream());
            string error = "";
            int    ct    = 0;
            string max   = "/ " + es.Count.ToString();


            WaitingScreen.Wait();
            try
            {
                foreach (uint type in map.Keys)
                {
                    SimPe.Events.ResourceContainers rc = map[type] as SimPe.Events.ResourceContainers;
                    bool first = true;

                    foreach (SimPe.Events.ResourceContainer e in rc)
                    {
                        error += ProcessItem(sw, e, first);
                        WaitingScreen.UpdateMessage((ct++).ToString() + " / " + max.ToString());
                        first = false;
                    }
                }
                WaitingScreen.Stop();

                if (error != "")
                {
                    throw new Warning("Not all Selected Files were processed.", error);
                }

                if (f == null)
                {
                    f = new Report();
                }
                f.Execute(sw);
            }
#if !DEBUG
            catch (Exception ex)
            {
                Helper.ExceptionMessage(ex);
            }
#endif
            finally
            {
                sw.Close();
                Serializer.ResetFormater();
                WaitingScreen.Stop();
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Create a new Color Options package
        /// </summary>
        /// <param name="newpkg">The Package the color Option should be added to</param>
        /// <param name="fkt">The function that ahs to be called wne the Selection should be displayed</param>
        public void Create(IPackageFile newpkg, CreateSelectionCallback fkt)
        {
            WaitingScreen.Wait();
            try
            {
                //this.newpkg = newpkg;

                WaitingScreen.UpdateMessage("Loading available Color Options");
                Hashtable fullmap        = Scenegraph.GetMMATMap(package);
                Hashtable map            = fullmap;
                ArrayList allowedSubsets = Scenegraph.GetRecolorableSubsets(package);

                //Check if the User can select a Subset
                bool userselect = false;
                if (map.Count > 1)
                {
                    userselect = true;
                }
                else
                {
                    if (map.Count == 1)
                    {
                        foreach (string s in map.Keys)
                        {
                            Hashtable ht = (Hashtable)map[s];
                            if (ht.Count > 1)
                            {
                                userselect = true;
                            }
                        }
                    }
                }

                SubsetSelectForm ssf = SubsetSelectForm.Prepare(map, allowedSubsets);
                fkt(ssf, userselect, fullmap);
            }
            finally
            {
                WaitingScreen.Stop();
            }
            return;

            /*string[] subsets = GetSubsets();
             *
             * //let the user Select
             * if ((subsets.Length>1) && (ask))
             * {
             *      Listing l = new Listing();
             *      subsets = l.Execute(subsets);
             * }
             *
             * WaitingScreen.Wait();
             * WaitingScreen.UpdateMessage("Getting slave Subsets");
             * SubsetItem[] subsetsi = GetSlaveSubsets(subsets);
             *
             * WaitingScreen.UpdateMessage("Getting Resource Nodes");
             * ArrayList cres = GetCresNames(subsetsi);
             *
             * WaitingScreen.UpdateMessage("Getting Material Overrides");
             * Hashtable mmats = GetMMATs(subsetsi, cres);
             * ArrayList guids = GetGUIDs();
             *
             * LoadSubSetList(mmats, guids, subsetsi);
             *
             * WaitingScreen.UpdateMessage("Load LIFO Files");
             * GetLifoFiles();
             *
             * WaitingScreen.Stop();*/
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Set the Age of the Files
        /// </summary>
        /// <param name="name"></param>
        /// <param name="cbs"></param>
        /// <param name="yacheck">true, if you want to perform a check for YoungAdulst and add apropriate Filds to the cpf</param>
        void SetProperty(string name, CheckBox[] cbs, bool yacheck)
        {
            if (selection == null)
            {
                return;
            }

            WaitingScreen.Wait();
            try
            {
                bool chg = false;
                foreach (ScannerItem si in selection)
                {
                    if (si.PackageCacheItem.Type == SimPe.Cache.PackageType.Cloth ||
                        si.PackageCacheItem.Type == SimPe.Cache.PackageType.Skin ||
                        ((uint)si.PackageCacheItem.Type & (uint)SimPe.Cache.PackageType.Makeup) == (uint)SimPe.Cache.PackageType.Makeup ||
                        ((uint)si.PackageCacheItem.Type & (uint)SimPe.Cache.PackageType.Accessory) == (uint)SimPe.Cache.PackageType.Accessory ||
                        si.PackageCacheItem.Type == SimPe.Cache.PackageType.Hair
                        )
                    {
                        if (si.PackageCacheItem.Thumbnail != null)
                        {
                            WaitingScreen.Update(si.PackageCacheItem.Thumbnail, si.FileName);
                        }
                        else
                        {
                            WaitingScreen.UpdateMessage(si.FileName);
                        }

                        //make sure, the file is rescanned on the next Cache Update
                        SimPe.Cache.PackageState ps = si.PackageCacheItem.FindState(this.Uid, true);
                        ps.State = TriState.Null;

                        Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(Data.MetaData.GZPS);
                        if (pfds.Length == 0)
                        {
                            pfds = si.Package.FindFiles(0xCCA8E925);                                         //Object XML
                        }
                        if (pfds.Length == 0)
                        {
                            pfds = si.Package.FindFiles(0x2C1FD8A1);                                         //TextureOverlay XML
                        }
                        if (pfds.Length == 0)
                        {
                            pfds = si.Package.FindFiles(0x8C1580B5);                                         //Hairtone XML
                        }
                        if (pfds.Length == 0)
                        {
                            pfds = si.Package.FindFiles(0x0C1FE246);                                         //Mesh Overlay XML
                        }
                        ArrayList data = new ArrayList();
                        foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                        {
                            SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                            cpf.ProcessData(pfd, si.Package, false);

                            uint age = cpf.GetSaveItem(name).UIntegerValue;
                            foreach (CheckBox cb in cbs)
                            {
                                if (cb.CheckState == CheckState.Indeterminate)
                                {
                                    continue;
                                }

                                age |= (uint)cb.Tag;
                                if (cb.CheckState == CheckState.Unchecked)
                                {
                                    age ^= (uint)cb.Tag;
                                }
                            }

                            if (yacheck)
                            {
                                //when Young Adult is set, we need to make sure that the Version is updated accordingly!
                                if ((age & (uint)Data.Ages.YoungAdult) != 0)
                                {
                                    AddUniversityFields(cpf);
                                }
                            }

                            if (cpf.GetSaveItem(name).UIntegerValue != age)
                            {
                                chg = true;
                            }
                            cpf.GetSaveItem(name).UIntegerValue = age;

                            cpf.SynchronizeUserData();
                        }

                        si.Package.Save();
                    }
                }                //foreach
                if (chg && this.CallbackFinish != null)
                {
                    this.CallbackFinish(false, false);
                }
            }
            catch (Exception ex)
            {
                Helper.ExceptionMessage("", ex);
            }
            finally
            {
                WaitingScreen.Stop();
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// this Operation is fixing selected Packages that wer marked as problematic
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Set(SimPe.PackedFiles.Wrapper.ShelveDimension sd)
        {
            if (selection == null)
            {
                return;
            }

            WaitingScreen.Wait();
            bool chg = false;

            try
            {
                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 (ps.Data.Length < 1)
                    {
                        continue;
                    }
                    if (ps.State == TriState.True && selection.Length > 1)
                    {
                        continue;
                    }


                    ps.State = TriState.Null;
                    try
                    {
                        SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(Data.MetaData.OBJD_FILE);

                        foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                        {
                            SimPe.PackedFiles.Wrapper.ExtObjd objd = new ExtObjd();
                            objd.ProcessData(pfd, si.Package);
                            objd.ShelveDimension = sd;
                            objd.SynchronizeUserData();
                        }

                        si.Package.Save();
                    }
                    catch (Exception ex)
                    {
                        Helper.ExceptionMessage("", ex);
                    }
                }

                if (chg && this.CallbackFinish != null)
                {
                    this.CallbackFinish(false, false);
                }
            }
            catch (Exception ex)
            {
                Helper.ExceptionMessage("", ex);
            }
            finally
            {
                WaitingScreen.Stop();
            }
        }
Ejemplo n.º 19
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(); }
        }
Ejemplo n.º 20
0
        protected static SimPe.Packages.GeneratableFile ReColor(CloneSettings.BaseResourceType br, SimPe.Packages.GeneratableFile pkg, Interfaces.Files.IPackedFileDescriptor pfd, uint localgroup, ObjectWorkshopSettings settings, bool pkgcontainsonlybase)
        {
            SimPe.Packages.GeneratableFile package = pkg;
            // we need packages in the Gmaes and the Download Folder

            if (((!System.IO.File.Exists(ScenegraphHelper.GMND_PACKAGE)) || (!System.IO.File.Exists(ScenegraphHelper.MMAT_PACKAGE))) && (settings is OWCloneSettings))
            {
                if (Message.Show(Localization.Manager.GetString("OW_Warning"), "Warning", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return(package);
                }
            }

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = ExtensionProvider.BuildFilterString(
                new SimPe.ExtensionType[] {
                SimPe.ExtensionType.Package,
                SimPe.ExtensionType.AllFiles
            }
                );
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return(package);
            }

            //create a Cloned Object to get all needed Files for the Process
            WaitingScreen.Wait();
            try
            {
                WaitingScreen.UpdateMessage("Collecting needed Files");

                if ((package == null) && (pfd != null))
                {
                    package = RecolorClone(br, package, pfd, localgroup, settings, pkgcontainsonlybase);
                }
            }
            finally { WaitingScreen.Stop(); }


            /*if (settings is OWRecolorSettings)
             * {
             *      ObjectRecolor or = new ObjectRecolor(package);
             *      or.EnableColorOptions();
             *      or.LoadReferencedMATDs();
             *
             *      //load all Pending Textures
             *      ObjectCloner oc = new ObjectCloner(package);
             * }*/

            /*SimPe.Packages.GeneratableFile dn_pkg = null;
             * if (System.IO.File.Exists(ScenegraphHelper.GMND_PACKAGE)) dn_pkg = SimPe.Packages.GeneratableFile.LoadFromFile(ScenegraphHelper.GMND_PACKAGE);
             * else dn_pkg = SimPe.Packages.GeneratableFile.LoadFromStream((System.IO.BinaryReader)null);
             *
             * SimPe.Packages.GeneratableFile gm_pkg = null;
             * if (System.IO.File.Exists(ScenegraphHelper.MMAT_PACKAGE)) gm_pkg = SimPe.Packages.GeneratableFile.LoadFromFile(ScenegraphHelper.MMAT_PACKAGE);
             * else gm_pkg = SimPe.Packages.GeneratableFile.LoadFromStream((System.IO.BinaryReader)null);*/

            SimPe.Packages.GeneratableFile npackage = SimPe.Packages.GeneratableFile.CreateNew();            //.LoadFromStream((System.IO.BinaryReader)null);

            //Create the Templae for an additional MMAT
            npackage.FileName = sfd.FileName;

            ColorOptions cs = new ColorOptions(package);

            cs.Create(npackage);

            npackage.Save();
            package = npackage;


            WaitingScreen.Stop();
#if DEBUG
#else
            if (package != npackage)
            {
                package = null;
            }
#endif

            return(package);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Check for SimPE Updates
        /// </summary>
        /// <returns>true if success</returns>
        public static UpdateState CheckUpdate(ref long version, ref long qaversion)
        {
            if (!IsConnectedToInternet())
            {
                return(new UpdateState(UpdateStates.Nothing));
            }
            Helper.WindowsRegistry.LastUpdateCheck = DateTime.Now;

            WebClient Client = new WebClient();
            bool      run    = true;

            if (Helper.StartedGui == Executable.Classic)
            {
                run = WaitingScreen.Running;
                WaitingScreen.Wait();
            }
            else
            {
                Wait.SubStart();
            }
            try
            {
                WaitingScreen.UpdateMessage("Check for new Updates");
                Wait.Message = "Check for new Updates";

                string content = DownloadContent("http://sims.ambertation.de/downloadnfo.txt?&browser=simpe");

                //extract the Version String
                WaitingScreen.UpdateMessage("read latest Version");
                Wait.Message = "Reciving latest Version";
                UpdateState res = new UpdateState(UpdateStates.Nothing);
                try
                {
                    version   = GetVersion(content, "lversion");
                    qaversion = GetVersion(content, "qaversion");

                    if (version > Helper.SimPeVersionLong)
                    {
                        res.AddSimPeState(UpdateStates.NewRelease);
                    }

                    if (Helper.QARelease || Helper.WindowsRegistry.WasQAUser)
                    {
                        if (qaversion > Helper.SimPeVersionLong)
                        {
                            res.AddSimPeState(UpdateStates.NewQARelease);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (!run)
                    {
                        WaitingScreen.Stop(); run = false;
                    }
                    Helper.ExceptionMessage("", ex);
                }

                try
                {
                    bool first = true;
                    System.Collections.Generic.List <string> urls = new System.Collections.Generic.List <string>();
                    foreach (IUpdatablePlugin pl in UpdateState.UpdateablePluginList)
                    {
                        string url = pl.GetUpdateInformation().VersionCheckUrl;
                        if (urls.Contains(url.ToLower()))
                        {
                            continue;
                        }
                        urls.Add(url.ToLower());

                        content = DownloadContent(url);
                        res.CheckPluginUpdates(content, first);

                        first = false;
                    }
                }
                catch (Exception ex)
                {
                    if (!run)
                    {
                        WaitingScreen.Stop(); run = false;
                    }
                    Helper.ExceptionMessage("", ex);
                }

                if (Helper.StartedGui == Executable.Classic)
                {
                    if (!run)
                    {
                        WaitingScreen.Stop();
                    }
                }
                else
                {
                    Wait.SubStop();
                }


                return(res);
            }
            catch (Exception ex)
            {
                Helper.ExceptionMessage(new Warning("SimPE was unable to connect to the Internet. It cannot lookup the latest Version.", "You can deactivate the Version Check in Extras->Preferences... .", ex));
            }
            finally
            {
                if (Helper.StartedGui == Executable.Classic)
                {
                    if (!run)
                    {
                        WaitingScreen.Stop();
                    }
                }
                else
                {
                    Wait.SubStop();
                }
            }

            return(new UpdateState(UpdateStates.Nothing));
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Returns the Offset of the ResourceIndex in the current package
        /// </summary>
        /// <returns></returns>
        public HeaderIndex FindIndexOffset()
        {
            HeaderIndex hi = new HeaderIndex(pkg.Header);

            if (pkg is File)
            {
                ((File)pkg).ReloadReader();
            }
            BinaryReader br   = pkg.Reader;
            int          step = 0x18;

            if (pkg.Header.IndexType == SimPe.Data.MetaData.IndexTypes.ptShortFileIndex)
            {
                step = 0x14;
            }
            long pos = br.BaseStream.Length - (4 * step + 1);

            long lastitem  = -1;
            long firstitem = -1;

            SimPe.WaitingScreen.Wait();

            try
            {
                while (pos > 0x04)
                {
                    WaitingScreen.UpdateMessage("0x" + Helper.HexString(pos) + " / 0x" + Helper.HexString(br.BaseStream.Length));

                    bool hit = CouldBeIndexItem(br, pos, step, lastitem == -1);
                    if (hit && lastitem == -1)
                    {
                        lastitem = br.BaseStream.Position;
                    }

                    if (!hit && lastitem != -1)
                    {
                        firstitem = pos + step;
                        break;
                    }

                    if (lastitem == -1)
                    {
                        pos--;
                    }
                    else
                    {
                        pos -= step;
                    }
                }
            }
            finally
            {
                WaitingScreen.Stop();
            }

            hi.offset = (uint)firstitem;
            hi.size   = (int)(lastitem - firstitem);
            hi.count  = hi.size / step;

            if (firstitem == -1)
            {
                hi = pkg.Header.Index as HeaderIndex;
            }

            return(hi);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// This will build a SkinTone Replacement for the passed Skintone
        /// </summary>
        /// <param name="skintone">the skintone string</param>
        /// <param name="addtxtr">true, if you want to replace the default TXTR Files</param>
        /// <param name="addtxmt">true if you want to replace the default TXMT Files</param>
        /// <param name="sitem"></param>
        /// <param name="src"></param>
        /// <returns>the replacement package</returns>
        public SimPe.Packages.GeneratableFile BuildOverride(ScannerItem sitem, string skintone, string family, SimPe.Interfaces.Files.IPackageFile src, bool addtxmt, bool addtxtr, bool addref)
        {
            FileTable.FileIndex.Load();
            SimPe.Packages.GeneratableFile pkg = SimPe.Packages.GeneratableFile.LoadFromStream((System.IO.BinaryReader)null);

            WaitingScreen.Wait();
            //Save the old FileTable and the source File
            FileTable.FileIndex.Load();
            FileTable.FileIndex.StoreCurrentState();
            FileTable.FileIndex.AddIndexFromPackage(src);

            bool usefam = (skintone == "00000000-0000-0000-0000-000000000000");

            try
            {
                //find al description Files that belong to the Skintone that should be replaced
                ArrayList basecpf = new ArrayList();

                SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = FileTable.FileIndex.FindFile(Data.MetaData.GZPS, true);
                foreach (SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item in items)
                {
                    SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                    cpf.ProcessData(item);

                    if (cpf.GetSaveItem("skintone").StringValue != skintone)
                    {
                        continue;
                    }
                    //if (usefam)
                    if (cpf.GetSaveItem("family").StringValue != family)
                    {
                        continue;
                    }
                    if (cpf.GetSaveItem("type").StringValue != "skin")
                    {
                        continue;
                    }

                    SimPe.Plugin.SkinChain sc = new SkinChain(cpf);
                    basecpf.Add(sc);
                    WaitingScreen.UpdateMessage(cpf.GetSaveItem("name").StringValue);
                }

                ArrayList compare = new ArrayList();
                compare.Add("age");
                //compare.Add("category");
                compare.Add("fitness");
                compare.Add("gender");
                //compare.Add("outfit");
                compare.Add("override0subset");
                //compare.Add("override0resourcekeyidx");
                //compare.Add("shapekeyidx");

                //now select matching Files
                Interfaces.Files.IPackedFileDescriptor[] pfds = src.FindFiles(Data.MetaData.GZPS);

#if DEBUG
                //we could add Debug Code here to see which cpfs were pulled :)

                /*SimPe.Packages.GeneratableFile f = SimPe.Packages.GeneratableFile.CreateNew();
                 *
                 * foreach (SimPe.Plugin.SkinChain sc in basecpf)
                 * {
                 *      sc.Cpf.SynchronizeUserData();
                 *      f.Add(sc.Cpf.FileDescriptor);
                 *
                 *      RefFile r = sc.ReferenceFile;
                 *      if (r!=null)
                 *      {
                 *              r.SynchronizeUserData();
                 *              f.Add(r.FileDescriptor);
                 *      }
                 *
                 *      //foreach (GenericRcol rcol in sc.TXTRs)
                 *      GenericRcol rcol = sc.TXTR;
                 *              if (rcol!=null)
                 *              {
                 *                      rcol.SynchronizeUserData();
                 *                      f.Add(rcol.FileDescriptor);
                 *              }
                 *
                 *      //foreach (GenericRcol rcol in sc.TXMTs)
                 *      rcol = sc.TXMT;
                 *              if (rcol!=null)
                 *              {
                 *                      rcol.SynchronizeUserData();
                 *                      f.Add(rcol.FileDescriptor);
                 *              }
                 * }
                 *
                 * f.Save(@"G:\skinbase.package");
                 * return f;*/
#endif
                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    //load a description File for the new Skintone
                    SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                    cpf.ProcessData(pfd, src);

                    int index    = -1;
                    int maxpoint = 0;
                    //check if File is a match
                    for (int i = 0; i < basecpf.Count; i++)
                    {
                        SimPe.Plugin.SkinChain sc = (SimPe.Plugin.SkinChain)basecpf[i];
                        int point = compare.Count;
                        //scan for valid CPF Files
                        foreach (string s in compare)
                        {
                            if (s == "age" || s == "category" || s == "outfit")
                            {
                                if ((sc.Cpf.GetSaveItem(s).UIntegerValue & cpf.GetSaveItem(s).UIntegerValue) == 0)
                                {
                                    point--;
                                }
                            }
                            else if (s == "override0subset")
                            {
                                string s1 = sc.Cpf.GetSaveItem(s).StringValue.Trim().ToLower();
                                string s2 = cpf.GetSaveItem(s).StringValue.Trim().ToLower();

                                if (s1 == "bottom")
                                {
                                    s1 = "body";
                                }
                                else if (s1 == "top")
                                {
                                    s1 = "body";
                                }
                                if (s2 == "bottom")
                                {
                                    s2 = "body";
                                }
                                else if (s2 == "top")
                                {
                                    s2 = "body";
                                }

                                if (s1 != s2)
                                {
                                    point--;
                                }
                            }
                            else if (sc.Cpf.GetSaveItem(s).UIntegerValue != cpf.GetSaveItem(s).UIntegerValue)
                            {
                                point--;
                            }
                        }

                        if (point > maxpoint)
                        {
                            index    = i;
                            maxpoint = point;
                        }
                    }



                    //yes, yes :D this is a match
                    if (index >= 0 && maxpoint == compare.Count)
                    {
                        SimPe.Plugin.SkinChain sc = (SimPe.Plugin.SkinChain)basecpf[index];

                        SkinChain newsc = new SkinChain(cpf);

                        if (sc.ReferenceFile != null && newsc.ReferenceFile != null && addref)
                        {
                            RefFile r = newsc.ReferenceFile;
                            r.FileDescriptor = sc.ReferenceFile.FileDescriptor.Clone();

                            r.SynchronizeUserData();
                            if (pkg.FindFile(r.FileDescriptor) == null)
                            {
                                pkg.Add(r.FileDescriptor);
                            }
                        }

                        if (sc.TXTR != null && newsc.TXTR != null && addtxtr)
                        {
                            SimPe.Plugin.GenericRcol txtr = newsc.TXTR;
                            txtr.FileDescriptor = sc.TXTR.FileDescriptor.Clone();
#if DEBUG
#else
                            txtr.FileDescriptor.MarkForReCompress = true;
#endif

                            txtr.FileName = sc.TXTR.FileName;

                            txtr.SynchronizeUserData();
                            if (pkg.FindFile(txtr.FileDescriptor) == null)
                            {
                                pkg.Add(txtr.FileDescriptor);
                            }
                        }

                        if (sc.TXMT != null && newsc.TXMT != null && addtxmt)
                        {
                            SimPe.Plugin.GenericRcol txmt = newsc.TXMT;
                            txmt.FileDescriptor = sc.TXMT.FileDescriptor.Clone();
#if DEBUG
#else
                            txmt.FileDescriptor.MarkForReCompress = true;
#endif

                            MaterialDefinition md    = (MaterialDefinition)txmt.Blocks[0];
                            MaterialDefinition mdorg = (MaterialDefinition)sc.TXMT.Blocks[0];
                            txmt.FileName      = sc.TXMT.FileName;
                            md.FileDescription = mdorg.FileDescription;

                            txmt.SynchronizeUserData();
                            if (pkg.FindFile(txmt.FileDescriptor) == null)
                            {
                                pkg.Add(txmt.FileDescriptor);
                            }
                        }
                    }
                }

                SimPe.PackedFiles.Wrapper.Str str = new Str();
                str.Add(new StrToken(0, 0, "SimPE Skin Override: " + skintone + " (from " + sitem.PackageCacheItem.Name + ")", ""));

                str.FileDescriptor              = new SimPe.Packages.PackedFileDescriptor();
                str.FileDescriptor.Type         = Data.MetaData.STRING_FILE;
                str.FileDescriptor.Group        = Data.MetaData.LOCAL_GROUP;
                str.FileDescriptor.LongInstance = 0;

                str.SynchronizeUserData();
                pkg.Add(str.FileDescriptor);
            }
            finally
            {
                //restore the Previous FileTable
                FileTable.FileIndex.RestoreLastState();
                WaitingScreen.Stop();
            }

            return(pkg);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// This takes care of the MMAT Resources
        /// </summary>
        /// <param name="map"></param>
        /// <param name="uniquefamily"></param>
        /// <param name="grouphash"></param>
        void FixMMAT(Hashtable map, bool uniquefamily, string grouphash)
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Updating Material Overrides");
            }
            Interfaces.Files.IPackedFileDescriptor[] mpfds = package.FindFiles(Data.MetaData.MMAT);             //MMAT
            Hashtable familymap = new Hashtable();
            uint      mininst   = 0x5000;

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds)
            {
                SimPe.Plugin.MmatWrapper mmat = new SimPe.Plugin.MmatWrapper();
                mmat.ProcessData(pfd, package);
                //make the MMAT Instance number unique
                pfd.Instance = mininst++;

                //get unique family value
                if (uniquefamily)
                {
                    string family  = mmat.GetSaveItem("family").StringValue;
                    string nfamily = (string)familymap[family];

                    if (nfamily == null)
                    {
                        nfamily           = System.Guid.NewGuid().ToString();
                        familymap[family] = nfamily;
                    }

                    mmat.Family = nfamily;
                }


                string newref = (string)map[Hashes.StripHashFromName(mmat.GetSaveItem("name").StringValue.Trim().ToLower()) + "_txmt"];
                if (newref != null)
                {
                    newref    = Hashes.StripHashFromName(newref);
                    newref    = newref.Substring(0, newref.Length - 5);
                    mmat.Name = grouphash + newref;
                }
                else
                {
                    mmat.Name = grouphash + Hashes.StripHashFromName(mmat.GetSaveItem("name").StringValue);
                }

                newref = (string)map[Hashes.StripHashFromName(mmat.ModelName.Trim().ToLower())];
                if (newref != null)
                {
                    newref         = Hashes.StripHashFromName(newref);
                    mmat.ModelName = newref;
                }
                else
                {
                    mmat.ModelName = Hashes.StripHashFromName(mmat.ModelName);
                }

                if (ver == FixVersion.UniversityReady)
                {
                    SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item = FileTable.FileIndex.FindFileByName(mmat.ModelName, Data.MetaData.CRES, Data.MetaData.GLOBAL_GROUP, true);

                    bool addfl = true;
                    if (item != null)
                    {
                        if (item.FileDescriptor.Group == Data.MetaData.GLOBAL_GROUP)
                        {
                            addfl = false;
                        }
                    }

                    if (addfl)
                    {
                        mmat.ModelName = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + mmat.ModelName;
                    }
                }

                //mmat.FileDescriptor.Group = Data.MetaData.LOCAL_GROUP;
                mmat.SynchronizeUserData();
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Remove all Files that are referenced by a SHPE and belong to a subset as named in the esclude List
        /// </summary>
        /// <param name="exclude">List of subset names</param>
        /// <param name="modelnames">null or a List of allowed Modelnames. If a List is passed, only references to files
        /// starting with one of the passed Modelnames will be keept</param>
        public void RemoveSubsetReferences(ArrayList exclude, string[] modelnames)
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Removing unwanted Subsets");
            }
            //Build the ModelName List
            ArrayList mn = new ArrayList();

            if (modelnames != null)
            {
                foreach (string s in modelnames)
                {
                    string n = s;
                    if (s.EndsWith("_cres"))
                    {
                        n = s.Substring(0, s.Length - 5);
                    }
                    mn.Add(n);
                }
            }

            bool deleted = false;

            Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(Data.MetaData.SHPE);
            foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                Rcol rcol = new GenericRcol(null, false);
                rcol.ProcessData(pfd, package);

                foreach (ShapePart p in ((Shape)rcol.Blocks[0]).Parts)
                {
                    string s      = p.Subset.Trim().ToLower();
                    bool   remove = exclude.Contains(s);

                    if ((modelnames != null) && !remove)
                    {
                        remove = true;
                        string fl = p.FileName.Trim().ToLower();
                        foreach (string n in mn)
                        {
                            if (fl.StartsWith(n))
                            {
                                remove = false;
                                continue;
                            }
                        }
                    }

                    if (remove)
                    {
                        string n = p.FileName.Trim().ToLower();
                        if (!n.EndsWith("_txmt"))
                        {
                            n += "_txmt";
                        }

                        ArrayList names = new ArrayList();
                        Interfaces.Files.IPackedFileDescriptor[] rpfds = package.FindFile(n, Data.MetaData.TXMT);
                        foreach (Interfaces.Files.IPackedFileDescriptor rpfd in rpfds)
                        {
                            names.Add(rpfd);
                        }
                        int pos = 0;
                        while (pos < names.Count)
                        {
                            Interfaces.Files.IPackedFileDescriptor rpfd = (Interfaces.Files.IPackedFileDescriptor)names[pos++];
                            rpfd = package.FindFile(rpfd);

                            if (rpfd != null)
                            {
                                rpfd.MarkForDelete = true;
                                deleted            = true;
                                GenericRcol fl = new GenericRcol(null, false);
                                fl.ProcessData(rpfd, package);

                                Hashtable ht = fl.ReferenceChains;
                                foreach (string k in ht.Keys)
                                {
                                    foreach (Interfaces.Files.IPackedFileDescriptor lpfd in (ArrayList)ht[k])
                                    {
                                        if (!names.Contains(lpfd))
                                        {
                                            names.Add(lpfd);
                                        }
                                    }
                                }
                            }
                        } //while
                    }
                }         //foreach p
            }             //foreach SHPE

            //now remova all deleted Files from the Index
            if (deleted)
            {
                package.RemoveMarked();
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Fixes the Global Group
        /// </summary>
        public void FixGroup()
        {
            uint[] RCOLs =
            {
                0xFB00791E,                                                 //ANIM
                0x4D51F042,                                                 //CINE
                0xE519C933,                                                 //CRES
                0xAC4F8687,                                                 //GMDC
                0x7BA3838C,                                                 //GMND
                0xC9C81B9B,                                                 //LGHT
                0xC9C81BA3,                                                 //LGHT
                0xC9C81BA9,                                                 //LGHT
                0xC9C81BAD,                                                 //LGHT
                0xED534136,                                                 //LIFO
                0xFC6EB1F7,                                                 //SHPE
                0x49596978,                                                 //TXMT, MATD
                0x1C4A276C                                                  //TXTR
            };

            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Fixing Groups");
            }
            foreach (Interfaces.Files.IPackedFileDescriptor pfd in package.Index)
            {
                bool RCOLcheck = types.Contains(pfd.Type);
                if (ver == FixVersion.UniversityReady)
                {
                    RCOLcheck = Data.MetaData.RcolList.Contains(pfd.Type);
                }
                //foreach (uint tp in RCOLs) if (tp==pfd.Type) { RCOLcheck=true; break; }

                if (Data.MetaData.RcolList.Contains(pfd.Type))
                {
                    SimPe.Plugin.GenericRcol rcol = new GenericRcol(null, false);
                    rcol.ProcessData(pfd, package);

                    foreach (Interfaces.Files.IPackedFileDescriptor p in rcol.ReferencedFiles)
                    {
                        if (ver == FixVersion.UniversityReady2)
                        {
                            if (types.Contains(p.Type))
                            {
                                p.Group = Data.MetaData.CUSTOM_GROUP;
                            }
                            else
                            {
                                p.Group = Data.MetaData.LOCAL_GROUP;
                            }
                        }
                        else
                        {
                            if (Data.MetaData.RcolList.Contains(p.Type))
                            {
                                if (p.Type != Data.MetaData.ANIM)
                                {
                                    p.Group = Data.MetaData.CUSTOM_GROUP;
                                }
                                else
                                {
                                    p.Group = Data.MetaData.GLOBAL_GROUP;
                                }
                            }
                            else
                            {
                                p.Group = Data.MetaData.LOCAL_GROUP;
                            }
                        }
                    }
                    rcol.SynchronizeUserData();
                }

                if (RCOLcheck)
                {
                    if (pfd.Type != Data.MetaData.ANIM)
                    {
                        pfd.Group = Data.MetaData.CUSTOM_GROUP;
                    }
                    else
                    {
                        pfd.Group = Data.MetaData.GLOBAL_GROUP;
                    }
                }
                else
                {
                    pfd.Group = Data.MetaData.LOCAL_GROUP;
                }
            }

            //is this a Fence package? If so, do special FenceFixes
            if (package.FindFiles(Data.MetaData.XFNC).Length > 0 /*|| package.FindFiles(Data.MetaData.XNGB).Length>0*/)
            {
                this.FixFence();
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Loads Memory Files form the Object Package
        /// </summary>
        public void LoadMemories()
        {
            memories = new Hashtable();
            //if (BasePackage==null) return;

            Registry  reg  = Helper.WindowsRegistry;
            ArrayList list = new ArrayList();

            Interfaces.Files.IPackedFileDescriptor pfd;

            SimPe.PackedFiles.Wrapper.ExtObjd objd = new SimPe.PackedFiles.Wrapper.ExtObjd();
            SimPe.PackedFiles.Wrapper.Str     str  = new SimPe.PackedFiles.Wrapper.Str();

            FileTable.FileIndex.Load();
            Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = FileTable.FileIndex.FindFileDiscardingGroup(Data.MetaData.OBJD_FILE, 0x00000000000041A7);

            string max = " / " + items.Length.ToString();
            int    ct  = 0;

            if (items.Length != 0)           //found anything?
            {
                bool wasrunning = WaitingScreen.Running;
                WaitingScreen.Wait();
                try
                {
                    foreach (Interfaces.Scenegraph.IScenegraphFileIndexItem item in items)
                    {
                        ct++;
                        if (ct % 137 == 1)
                        {
                            WaitingScreen.UpdateMessage(ct.ToString() + max);
                        }
                        pfd = item.FileDescriptor;

                        string name = "";
                        objd.ProcessData(item);

                        if (memories.Contains(objd.Guid))
                        {
                            continue;
                        }
                        try
                        {
                            Interfaces.Scenegraph.IScenegraphFileIndexItem[] sitems = FileTable.FileIndex.FindFile(Data.MetaData.CTSS_FILE, pfd.Group, objd.CTSSInstance, null);
                            if (sitems.Length > 0)
                            {
                                str.ProcessData(sitems[0]);
                                SimPe.PackedFiles.Wrapper.StrItemList strs = str.LanguageItems(Helper.WindowsRegistry.LanguageCode);
                                if (strs.Length > 0)
                                {
                                    name = strs[0].Title;
                                }


                                //not found?
                                if (name == "")
                                {
                                    strs = str.LanguageItems(1);
                                    if (strs.Length > 0)
                                    {
                                        name = strs[0].Title;
                                    }
                                }
                            }
                        }
                        catch (Exception) { }
                        //still no name?
                        if (name == "")
                        {
                            name = objd.FileName;
                        }

#if DEBUG
                        IAlias a = new Alias(objd.Guid, name, "{1}: {name} (0x{id})");
#else
                        IAlias a = new Alias(objd.Guid, name, "{1}: {name}");
#endif

                        object[] o = new object[3];

                        o[0] = pfd;
                        o[1] = (Data.ObjectTypes)objd.Type;
                        o[2] = null;
                        SimPe.PackedFiles.Wrapper.Picture pic = new SimPe.PackedFiles.Wrapper.Picture();
                        Interfaces.Scenegraph.IScenegraphFileIndexItem[] iitems = FileTable.FileIndex.FindFile(Data.MetaData.SIM_IMAGE_FILE, pfd.Group, 1, null);
                        if (iitems.Length > 0)
                        {
                            pic.ProcessData(iitems[0]);
                            System.Drawing.Image img = pic.Image;
                            o[2] = img;

                            WaitingScreen.Update(img, ct.ToString() + max);
                        }
                        a.Tag = o;
                        if (!memories.Contains(objd.Guid))
                        {
                            memories.Add(objd.Guid, a);
                        }
                    } //foreach item
                }
                finally { if (!wasrunning)
                          {
                              WaitingScreen.Stop();
                          }
                }
            }             // if items>0
                          //System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Normal;
        }
Ejemplo n.º 28
0
        /// <summary>
        /// this Operation is fixing selected Packages that wer marked as problematic
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FixCompression(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
        {
            if (selection == null)
            {
                return;
            }

            WaitingScreen.Wait();
            bool chg = false;

            try
            {
                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 ((ps.State != TriState.Null) && (ps.Data.Length > 0))
                    {
                        if ((HealthState)ps.Data[0] != HealthState.Ok)
                        {
                            ps.State   = TriState.True;
                            ps.Data[0] = (uint)HealthState.Ok;
                            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in si.Package.Index)
                            {
                                SimPe.Interfaces.Files.IPackedFile file = si.Package.Read(pfd);
                                pfd.UserData          = file.UncompressedData;
                                pfd.MarkForReCompress = (file.IsCompressed || Data.MetaData.CompressionCandidates.Contains(pfd.Type));

                                if (pfd.Type == Data.MetaData.OBJD_FILE)
                                {
                                    SimPe.PackedFiles.Wrapper.ExtObjd objd = new ExtObjd();
                                    objd.ProcessData(pfd, si.Package);

                                    if (objd.Ok != SimPe.PackedFiles.Wrapper.ObjdHealth.Ok)
                                    {
                                        objd.SynchronizeUserData();
                                        objd.ProcessData(pfd, si.Package);

                                        if (objd.Ok != ObjdHealth.Ok)
                                        {
                                            ps.State   = TriState.False;
                                            ps.Data[0] = (uint)HealthState.NonDefaultObjd;
                                            if (objd.Ok == SimPe.PackedFiles.Wrapper.ObjdHealth.UnmatchingFilenames && Helper.WindowsRegistry.HiddenMode)
                                            {
                                                ps.Data[0] = (uint)HealthState.FaultyNamedObjd;
                                            }
                                            if (objd.Ok == ObjdHealth.OverLength)
                                            {
                                                ps.Data[0] = (uint)HealthState.FaultySizedObjd;
                                            }
                                        }
                                    }
                                }
                            }

                            si.Package.Save();
                            chg = true;
                            si.ListViewItem.ForeColor = System.Drawing.Color.Black;
                            this.ScanPackage(si, ps, si.ListViewItem);
                        }
                    }
                }

                if (chg && this.CallbackFinish != null)
                {
                    this.CallbackFinish(false, false);
                }
            }
            catch (Exception ex)
            {
                Helper.ExceptionMessage("", ex);
            }
            finally
            {
                WaitingScreen.Stop();
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// this Operation is fixing selected Packages that wer marked as problematic
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Fix(string name)
        {
            if (selection == null)
            {
                return;
            }

            WaitingScreen.Wait();
            bool chg = false;

            try
            {
                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 (ps.Data.Length < 1)
                    {
                        continue;
                    }
                    if ((ReadyState)ps.Data[0] == ReadyState.Yes)
                    {
                        continue;
                    }

                    string   mname = name;
                    DateTime now   = DateTime.Now;
                    mname += now.Date.ToShortDateString();
                    mname += "-" + now.Hour.ToString("x");
                    mname += now.Minute.ToString("x");
                    mname += now.Second.ToString("x");
                    mname += now.Millisecond.ToString("x");

                    ps.State = TriState.Null;
                    try
                    {
                        SimPe.Plugin.FixPackage.Fix(si.FileName, mname, FixVersion.UniversityReady);
                    }
                    catch (Exception ex)
                    {
                        Helper.ExceptionMessage("", ex);
                    }
                }

                if (chg && this.CallbackFinish != null)
                {
                    this.CallbackFinish(false, false);
                }
            }
            catch (Exception ex)
            {
                Helper.ExceptionMessage("", ex);
            }
            finally
            {
                WaitingScreen.Stop();
            }
        }