Exemplo n.º 1
0
        public bool SaveHouse(int houseID, IffFile file)
        {
            using (var stream = new FileStream(GetHousePath(houseID), FileMode.Create, FileAccess.Write, FileShare.None))
                file.Write(stream);

            return(true);
        }
Exemplo n.º 2
0
        public void SaveChange(IffFile file)
        {
            lock (this)
            {
                if (file.RuntimeInfo.State == IffRuntimeState.Standalone)
                {
                    //just save out iff
                    var filename = file.RuntimeInfo.Path;
                    Directory.CreateDirectory(Path.GetDirectoryName(filename));
                    using (var stream = new FileStream(filename, FileMode.Create))
                        file.Write(stream);

                    foreach (var chunk in file.ListAll())
                    {
                        chunk.RuntimeInfo = ChunkRuntimeState.Normal;
                    }
                }
                else
                {
                    string dest = (file.RuntimeInfo.State == IffRuntimeState.PIFFClone) ? "Content/Objects/" : "Content/Patch/User/";
                    Directory.CreateDirectory(dest);
                    if (file.RuntimeInfo.State == IffRuntimeState.ReadOnly)
                    {
                        file.RuntimeInfo.State = IffRuntimeState.PIFFPatch;
                    }

                    var stringResources = new HashSet <Type> {
                        typeof(STR), typeof(CTSS), typeof(TTAs)
                    };
                    var sprites = (file.RuntimeInfo.UseCase == IffUseCase.ObjectSprites);
                    file.RuntimeInfo.Patches.Clear();

                    var piff = FSO.Files.Formats.PiffEncoder.GeneratePiff(file, null, stringResources);

                    string name = file.Filename.Substring(0, file.Filename.Length - 4); //get without extension

                    if (piff != null)
                    {
                        var filename = dest + name + (sprites ? ".spf" : "") + ".piff";
                        using (var stream = new FileStream(filename, FileMode.Create)) piff.Write(stream);
                        file.RuntimeInfo.Patches.Add(piff);
                    }

                    if (!sprites)
                    {
                        piff = FSO.Files.Formats.PiffEncoder.GeneratePiff(file, stringResources, null);
                        if (piff != null)
                        {
                            var filename = dest + name + ".str.piff";
                            using (var stream = new FileStream(filename, FileMode.Create)) piff.Write(stream);
                            file.RuntimeInfo.Patches.Add(piff);
                        }
                    }
                }

                file.RuntimeInfo.Dirty = false;
                ChangedFiles.Remove(file);
            }
        }
        public bool SaveNeighbourhood(bool withSims)
        {
            //todo: save iffs for dirty avatars.
            DirtyAvatars.Clear();

            using (var stream = new FileStream(Path.Combine(UserPath, "Neighborhood.iff"), FileMode.Create, FileAccess.Write, FileShare.None))
                MainResource.Write(stream);

            return(true);
        }
Exemplo n.º 4
0
        private void TrySaveIff(IffFile file)
        {
            var dialog = new SaveFileDialog();

            dialog.FileName = file.Filename;
            dialog.Title    = "Saving full IFF " + file.Filename + "...";
            FolderSave(dialog);

            Stream str;

            if ((str = dialog.OpenFile()) != null)
            {
                file.Write(str);
                str.Close();
            }
        }
Exemplo n.º 5
0
        public bool SaveNeighbourhood(bool withSims)
        {
            //todo: save iffs for dirty avatars.
            if (withSims)
            {
                foreach (var ava in DirtyAvatars)
                {
                    var obj = ContentManager.WorldObjects.Get(ava);
                    if (obj != null)
                    {
                        using (var stream = new FileStream(obj.Resource.Name, FileMode.Create))
                            obj.Resource.MainIff.Write(stream);
                    }
                }
                DirtyAvatars.Clear();
            }

            using (var stream = new FileStream(Path.Combine(UserPath, "Neighborhood.iff"), FileMode.Create, FileAccess.Write, FileShare.None))
                MainResource.Write(stream);

            return(true);
        }
Exemplo n.º 6
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            var  name  = ChunkLabelEntry.Text;
            var  guidT = GUIDEntry.Text;
            uint guid;
            var  objProvider = Content.Content.Get().WorldObjects;

            if (name == "")
            {
                MessageBox.Show("Name cannot be empty!", "Invalid Object Name");
            }
            else if (guidT == "")
            {
                MessageBox.Show("GUID cannot be empty!", "Invalid GUID");
            }
            else if (!uint.TryParse(guidT, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out guid))
            {
                MessageBox.Show("GUID is invalid! Make sure it is a hex string of size 8. (eg. 6789ABCD)", "Invalid GUID");
            }
            else
            {
                lock (objProvider.Entries)
                {
                    if (objProvider.Entries.ContainsKey(guid))
                    {
                        MessageBox.Show("This GUID is already being used!", "GUID is Taken!");
                        return;
                    }

                    //OK, it's valid. Now to add it to the objects system...
                    //This is a little tricky because we want to add an object that does not exist yet.
                    //There's a special function just for this! But first, we need an OBJD...

                    var obj = new OBJD()
                    {
                        GUID             = guid,
                        ObjectType       = OBJDType.Normal,
                        ChunkLabel       = name,
                        ChunkID          = 1,
                        ChunkProcessed   = true,
                        ChunkType        = "OBJD",
                        ChunkParent      = TargetIff,
                        AnimationTableID = 128,
                        AddedByPatch     = true
                    };

                    Content.Content.Get().Changes.BlockingResMod(new ResAction(() =>
                    {
                        //find a free space to place the object
                        ushort id = 16807; //todo: why???
                        var list  = TargetIff.List <OBJD>();
                        if (list != null)
                        {
                            foreach (var chk in list.OrderBy(x => x.ChunkID))
                            {
                                if (chk.ChunkID == id)
                                {
                                    id++;
                                }
                            }
                        }
                        obj.ChunkID = id;
                        //add it to the iff file
                        TargetIff.AddChunk(obj);
                    }, obj));

                    if (IsNew)
                    {
                        //add a default animation table, for quality of life reasons

                        var anim = new STR()
                        {
                            ChunkLabel     = name,
                            ChunkID        = 128,
                            ChunkProcessed = true,
                            ChunkType      = "STR#",
                            ChunkParent    = TargetIff,
                        };

                        anim.InsertString(0, new STRItem {
                            Value = "", Comment = ""
                        });
                        TargetIff.AddChunk(anim);

                        var filename = TargetIff.RuntimeInfo.Path;
                        Directory.CreateDirectory(Path.GetDirectoryName(filename));
                        using (var stream = new FileStream(filename, FileMode.Create))
                            TargetIff.Write(stream);
                    }

                    //add it to the provider
                    objProvider.AddObject(TargetIff, obj);

                    DialogResult = DialogResult.OK;
                    ResultGUID   = guid;
                    Close();
                }
            }
        }
Exemplo n.º 7
0
        public void SaveChange(IffFile file)
        {
            lock (this)
            {
                if (file.RuntimeInfo.State == IffRuntimeState.Standalone)
                {
                    //just save out iff
                    var filename = file.RuntimeInfo.Path;
                    Directory.CreateDirectory(Path.GetDirectoryName(filename));
                    using (var stream = new FileStream(filename, FileMode.Create))
                        file.Write(stream);

                    foreach (var chunk in file.ListAll())
                    {
                        chunk.RuntimeInfo = ChunkRuntimeState.Normal;
                    }
                }
                else
                {
                    string dest = Path.Combine(FSOEnvironment.ContentDir, ((file.RuntimeInfo.State == IffRuntimeState.PIFFClone) ? "Objects/" : "Patch/User/"));
                    Directory.CreateDirectory(dest);
                    if (file.RuntimeInfo.State == IffRuntimeState.ReadOnly)
                    {
                        file.RuntimeInfo.State = IffRuntimeState.PIFFPatch;
                    }

                    var stringResources = new HashSet<Type> { typeof(STR), typeof(CTSS), typeof(TTAs) };
                    var sprites = (file.RuntimeInfo.UseCase == IffUseCase.ObjectSprites);
                    file.RuntimeInfo.Patches.Clear();

                    var piff = FSO.Files.Formats.PiffEncoder.GeneratePiff(file, null, stringResources);

                    string name = file.Filename.Substring(0, file.Filename.Length - 4); //get without extension

                    if (piff != null)
                    {
                        var filename = dest + name + (sprites ? ".spf" : "") + ".piff";
                        using (var stream = new FileStream(filename, FileMode.Create)) piff.Write(stream);
                        file.RuntimeInfo.Patches.Add(piff);
                    }

                    if (!sprites)
                    {
                        piff = FSO.Files.Formats.PiffEncoder.GeneratePiff(file, stringResources, null);
                        if (piff != null)
                        {
                            var filename = dest + name + ".str.piff";
                            using (var stream = new FileStream(filename, FileMode.Create)) piff.Write(stream);
                            file.RuntimeInfo.Patches.Add(piff);
                        }
                    }
                }

                file.RuntimeInfo.Dirty = false;
                ChangedFiles.Remove(file);
            }
        }
Exemplo n.º 8
0
        public void SaveChange(IffFile file)
        {
            lock (this)
            {
                if (file.RuntimeInfo.State == IffRuntimeState.Standalone)
                {
                    //just save out iff
                    var filename = file.RuntimeInfo.Path;
                    Directory.CreateDirectory(Path.GetDirectoryName(filename));
                    using (var stream = new FileStream(filename, FileMode.Create))
                        file.Write(stream);

                    foreach (var chunk in file.ListAll())
                    {
                        chunk.RuntimeInfo = ChunkRuntimeState.Normal;
                    }
                }
                else
                {
                    string dest = Path.Combine(FSOEnvironment.ContentDir, ((file.RuntimeInfo.State == IffRuntimeState.PIFFClone) ? "Objects/" : "Patch/User/"));
                    Directory.CreateDirectory(dest);
                    if (file.RuntimeInfo.State == IffRuntimeState.ReadOnly)
                    {
                        file.RuntimeInfo.State = IffRuntimeState.PIFFPatch;
                    }

                    var stringResources = new HashSet <Type> {
                        typeof(STR), typeof(CTSS), typeof(TTAs)
                    };
                    var sprites    = (file.RuntimeInfo.UseCase == IffUseCase.ObjectSprites);
                    var oldPatches = file.RuntimeInfo.Patches.ToList();
                    file.RuntimeInfo.Patches.Clear();

                    //find the old piff. should be the piff that doesn't end in .str.piff
                    var oldPIFF = oldPatches.FirstOrDefault(x => !x.Filename.EndsWith(".str.piff"))?.List <PIFF>()?.ElementAt(0);

                    var piff = FSO.Files.Formats.PiffEncoder.GeneratePiff(file, null, stringResources, oldPIFF);

                    string name = file.Filename.Substring(0, file.Filename.Length - 4); //get without extension

                    if (piff != null)
                    {
                        if (piff.Filename == null)
                        {
                            piff.Filename = name + (sprites ? ".spf" : "") + ".piff";
                        }
                        var filename = dest + piff.Filename;
                        using (var stream = new FileStream(filename, FileMode.Create)) piff.Write(stream);
                        file.RuntimeInfo.Patches.Add(piff);
                    }

                    if (!sprites)
                    {
                        oldPIFF = oldPatches.FirstOrDefault(x => x.Filename.EndsWith(".str.piff"))?.List <PIFF>()?.ElementAt(0);
                        piff    = FSO.Files.Formats.PiffEncoder.GeneratePiff(file, stringResources, null, oldPIFF);
                        if (piff != null)
                        {
                            if (piff.Filename == null)
                            {
                                piff.Filename = name + ".str.piff";
                            }
                            var filename = dest + piff.Filename;
                            using (var stream = new FileStream(filename, FileMode.Create)) piff.Write(stream);
                            file.RuntimeInfo.Patches.Add(piff);
                        }
                    }
                }

                file.RuntimeInfo.Dirty = false;
                ChangedFiles.Remove(file);
            }
        }