Example #1
0
        public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
        {
            ThingList TL = new ThingList();

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
            }
            if ((BR.BaseStream.Length % 0x400) != 0 || BR.BaseStream.Position != 0)
            {
                return(TL);
            }
            long EntryCount = BR.BaseStream.Length / 0x400;

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
            }
            for (int i = 0; i < EntryCount; ++i)
            {
                Things.SpellInfo SI = new Things.SpellInfo();
                if (!SI.Read(BR))
                {
                    TL.Clear();
                    break;
                }
                if (ProgressCallback != null)
                {
                    ProgressCallback(null, (double)(i + 1) / EntryCount);
                }
                TL.Add(SI);
            }
            return(TL);
        }
    internal void MoveNext()
    {
        var _CurrentIndex = ThingList.IndexOf(this.SelectedThing);

        try { SelectedThing = ThingList[++_CurrentIndex]; }
        catch { SelectedThing = ThingList.Last(); }
    }
Example #3
0
 public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
 {
     ThingList TL = new ThingList();
     if (ProgressCallback != null)
     {
         ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
     }
     if ((BR.BaseStream.Length % 0x20) != 0 || BR.BaseStream.Position != 0)
     {
         return TL;
     }
     long EntryCount = BR.BaseStream.Length / 0x20;
     if (ProgressCallback != null)
     {
         ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
     }
     try
     {
         int ZoneID = -1;
         for (int i = 0; i < EntryCount; ++i)
         {
             Things.MobListEntry MLE = new Things.MobListEntry();
             if (!MLE.Read(BR))
             {
                 TL.Clear();
                 break;
             }
             uint ThisID = (uint)MLE.GetFieldValue("id");
             if (i == 0 && (ThisID != 0 || MLE.GetFieldText("name") != "none"))
             {
                 TL.Clear();
                 break;
             }
             else if (i > 0)
             {
                 // Entire file should be for 1 specific zone
                 int ThisZone = (int)(ThisID & 0x000FF000);
                 if (ZoneID < 0)
                 {
                     ZoneID = ThisZone;
                 }
                 else if (ThisZone != ZoneID)
                 {
                     TL.Clear();
                     break;
                 }
             }
             if (ProgressCallback != null)
             {
                 ProgressCallback(null, (double)(i + 1) / EntryCount);
             }
             TL.Add(MLE);
         }
     }
     catch
     {
         TL.Clear();
     }
     return TL;
 }
Example #4
0
 public static ThingList LoadAll(string FileName, ProgressCallback ProgressCallback, bool FirstMatchOnly)
 {
     ThingList Results = new ThingList();
       if (ProgressCallback != null)
     ProgressCallback(I18N.GetText("FTM:OpeningFile"), 0);
     BinaryReader BR = null;
       try {
     BR = new BinaryReader(new FileStream(FileName, FileMode.Open, FileAccess.Read), Encoding.ASCII);
       } catch { }
       if (BR == null || BR.BaseStream == null)
     return Results;
       foreach (FileType FT in FileType.AllTypes) {
       ProgressCallback SubCallback = null;
     if (ProgressCallback != null) {
       SubCallback = new ProgressCallback(delegate (string Message, double PercentCompleted) {
       string SubMessage = null;
     if (Message != null)
       SubMessage = String.Format("[{0}] {1}", FT.Name, Message);
     ProgressCallback(SubMessage, PercentCompleted);
       });
     }
       ThingList SubResults = FT.Load(BR, SubCallback);
     if (SubResults != null) {
       Results.AddRange(SubResults);
       if (FirstMatchOnly && Results.Count > 0)
     break;
     }
     BR.BaseStream.Seek(0, SeekOrigin.Begin);
       }
       return Results;
 }
Example #5
0
        public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
        {
            ThingList TL = new ThingList();

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:ScanningFile"), 0);
            }
            Graphic G = new Graphic();

            while (BR.BaseStream.Position < BR.BaseStream.Length)
            {
                long Pos = BR.BaseStream.Position; // Save Position (G.Read() will advance it an unknown amount)
                if (G.Read(BR))
                {
                    TL.Add(G);
                    G = new Graphic();
                    if (ProgressCallback != null)
                    {
                        ProgressCallback(null, (double)(BR.BaseStream.Position + 1) / BR.BaseStream.Length);
                    }
                }
                else
                {
                    BR.BaseStream.Seek(Pos + 1, SeekOrigin.Begin);
                    if (ProgressCallback != null && (BR.BaseStream.Position == BR.BaseStream.Length || (BR.BaseStream.Position % 1024) == 0))
                    {
                        ProgressCallback(null, (double)(BR.BaseStream.Position + 1) / BR.BaseStream.Length);
                    }
                }
            }
            G = null;
            return(TL);
        }
Example #6
0
 public void ScanFile(IWin32Window ParentForm, string FileName)
 {
     lock (this.FSD) {
     if (FileName != null && File.Exists(FileName)) {
       this.FSD = new FileScanDialog();
       var T = new Thread(() => {
     try {
       Application.DoEvents();
       while (!this.FSD.Visible) {
         Thread.Sleep(0);
         Application.DoEvents();
       }
       this.FSD.Invoke(new AnonymousMethod(() => this.FSD.ResetProgress()));
       this.FileContents = FileType.LoadAll(FileName, (msg, pct) => this.FSD.Invoke(new AnonymousMethod(() => this.FSD.SetProgress(msg, pct))));
       this.FSD.Invoke(new AnonymousMethod(() => this.FSD.Finish()));
     } catch {
       this.FileContents = null;
     }
       });
       T.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
       T.Start();
       if (this.FSD.ShowDialog(ParentForm) == DialogResult.Abort) {
     this.FSD.Finish();
     this.FileContents = null;
       }
       if (T.IsAlive)
     T.Abort();
       this.FSD.Dispose();
       this.FSD = null;
     }
       }
 }
Example #7
0
 public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
 {
     ThingList TL = new ThingList();
     if (ProgressCallback != null)
     {
         ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
     }
     if ((BR.BaseStream.Length % 0x400) != 0 || BR.BaseStream.Position != 0)
     {
         return TL;
     }
     long EntryCount = BR.BaseStream.Length / 0x400;
     if (ProgressCallback != null)
     {
         ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
     }
     for (int i = 0; i < EntryCount; ++i)
     {
         Things.SpellInfo SI = new Things.SpellInfo();
         if (!SI.Read(BR))
         {
             TL.Clear();
             break;
         }
         if (ProgressCallback != null)
         {
             ProgressCallback(null, (double)(i + 1) / EntryCount);
         }
         TL.Add(SI);
     }
     return TL;
 }
    internal void MovePrevious()
    {
        var _CurrentIndex = ThingList.IndexOf(this.SelectedThing);

        try { SelectedThing = ThingList[--_CurrentIndex]; }
        catch { SelectedThing = ThingList.First(); }
    }
Example #9
0
 public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
 {
     ThingList TL = new ThingList();
       if (ProgressCallback != null)
     ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
       if (BR.BaseStream.Length < 0x40 || BR.BaseStream.Position != 0)
     return TL;
     FFXIEncoding E = new FFXIEncoding();
       if (E.GetString(BR.ReadBytes(8)) != "d_msg".PadRight(8, '\0'))
     return TL;
     ushort Flag1 = BR.ReadUInt16();
       if (Flag1 != 0 && Flag1 != 1)
     return TL;
     ushort Flag2 = BR.ReadUInt16();
       if (Flag2 != 0 && Flag2 != 1)
     return TL;
       if (BR.ReadUInt32() != 3 || BR.ReadUInt32() != 3)
     return TL;
     uint FileSize = BR.ReadUInt32();
       if (FileSize != BR.BaseStream.Length)
     return TL;
     uint HeaderBytes = BR.ReadUInt32();
       if (HeaderBytes != 0x40)
     return TL;
       if (BR.ReadUInt32() != 0)
     return TL;
     int BytesPerEntry = BR.ReadInt32();
       if (BytesPerEntry < 0)
     return TL;
     uint DataBytes = BR.ReadUInt32();
       if (FileSize != (HeaderBytes + DataBytes) || (DataBytes % BytesPerEntry) != 0)
     return TL;
     uint EntryCount = BR.ReadUInt32();
       if (EntryCount * BytesPerEntry != DataBytes)
     return TL;
       if (BR.ReadUInt32() != 1 || BR.ReadUInt64() != 0 || BR.ReadUInt64() != 0)
     return TL;
       if (ProgressCallback != null)
     ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
       for (uint i = 0; i < EntryCount; ++i) {
       BinaryReader EntryBR = new BinaryReader(new MemoryStream(BR.ReadBytes(BytesPerEntry)));
     EntryBR.BaseStream.Position = 0;
       bool ItemAdded = false;
     {
     Things.DMSGStringBlock SB = new Things.DMSGStringBlock();
       if (SB.Read(EntryBR, E, i)) {
     TL.Add(SB);
     ItemAdded = true;
       }
     }
     EntryBR.Close();
     if (!ItemAdded) {
       TL.Clear();
       break;
     }
     if (ProgressCallback != null)
       ProgressCallback(null, (double) (i + 1) / EntryCount);
       }
       return TL;
 }
Example #10
0
 public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
 {
     ThingList TL = new ThingList();
     if (ProgressCallback != null)
     {
         ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
     }
     if (BR.BaseStream.Length < 0x38 || BR.BaseStream.Position != 0)
     {
         return TL;
     }
     FFXIEncoding E = new FFXIEncoding();
     // Read past the marker (32 bytes)
     if ((E.GetString(BR.ReadBytes(10)) != "XISTRING".PadRight(10, '\0')) || BR.ReadUInt16() != 2)
     {
         return TL;
     }
     foreach (byte B in BR.ReadBytes(20))
     {
         if (B != 0)
         {
             return TL;
         }
     }
     // Read The Header
     uint FileSize = BR.ReadUInt32();
     if (FileSize != BR.BaseStream.Length)
     {
         return TL;
     }
     uint EntryCount = BR.ReadUInt32();
     uint EntryBytes = BR.ReadUInt32();
     uint DataBytes = BR.ReadUInt32();
     BR.ReadUInt32(); // Unknown
     BR.ReadUInt32(); // Unknown
     if (EntryBytes != EntryCount * 12 || FileSize != 0x38 + EntryBytes + DataBytes)
     {
         return TL;
     }
     if (ProgressCallback != null)
     {
         ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
     }
     for (uint i = 0; i < EntryCount; ++i)
     {
         Things.XIStringTableEntry XSTE = new Things.XIStringTableEntry();
         if (!XSTE.Read(BR, E, i, EntryBytes, DataBytes))
         {
             TL.Clear();
             break;
         }
         if (ProgressCallback != null)
         {
             ProgressCallback(null, (double)(i + 1) / EntryCount);
         }
         TL.Add(XSTE);
     }
     return TL;
 }
Example #11
0
 public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
 {
     ThingList TL = new ThingList();
       if (ProgressCallback != null)
     ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
       if (BR.BaseStream.Length < 0x40 || BR.BaseStream.Position != 0)
     return TL;
     FFXIEncoding E = new FFXIEncoding();
       // Skip (presumably) fixed portion of the header
       if ((E.GetString(BR.ReadBytes(8)) != "d_msg".PadRight(8, '\0')) || BR.ReadUInt16() != 1 || BR.ReadUInt16() != 1 || BR.ReadUInt32() != 3 || BR.ReadUInt32() != 3)
     return TL;
       // Read the useful header fields
     uint FileSize = BR.ReadUInt32();
       if (FileSize != BR.BaseStream.Length)
     return TL;
     uint HeaderBytes = BR.ReadUInt32();
       if (HeaderBytes != 0x40)
     return TL;
     uint EntryBytes = BR.ReadUInt32();
       if (BR.ReadUInt32() != 0)
     return TL;
     uint DataBytes  = BR.ReadUInt32();
       if (FileSize != HeaderBytes + EntryBytes + DataBytes)
     return TL;
     uint EntryCount = BR.ReadUInt32();
       if (EntryBytes != EntryCount * 8)
     return TL;
       if (BR.ReadUInt32() != 1 || BR.ReadUInt64() != 0 || BR.ReadUInt64() != 0)
     return TL;
       if (ProgressCallback != null)
     ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
       for (uint i = 0; i < EntryCount; ++i) {
     BR.BaseStream.Position = HeaderBytes + i * 8;
       int Offset = ~BR.ReadInt32();
       int Length = ~BR.ReadInt32();
     if (Length < 0 || Offset < 0 || Offset + Length > DataBytes) {
       TL.Clear();
       break;
     }
     BR.BaseStream.Position = HeaderBytes + EntryBytes + Offset;
       BinaryReader EntryBR = new BinaryReader(new MemoryStream(BR.ReadBytes(Length)));
       bool ItemAdded = false;
     {
     Things.DMSGStringBlock SB = new Things.DMSGStringBlock();
       if (SB.Read(EntryBR, E, i)) {
     TL.Add(SB);
     ItemAdded = true;
       }
     }
     EntryBR.Close();
     if (!ItemAdded) {
       TL.Clear();
       break;
     }
     if (ProgressCallback != null)
       ProgressCallback(null, (double) (i + 1) / EntryCount);
       }
       return TL;
 }
Example #12
0
 public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
 {
     ThingList TL = new ThingList();
     if (ProgressCallback != null)
     {
         ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
     }
     if (BR.BaseStream.Length < 4)
     {
         return TL;
     }
     uint FileSizeMaybe = BR.ReadUInt32();
     if (FileSizeMaybe != (0x10000000 + BR.BaseStream.Length - 4))
     {
         return TL;
     }
     uint FirstTextPos = (BR.ReadUInt32() ^ 0x80808080);
     if ((FirstTextPos % 4) != 0 || FirstTextPos > BR.BaseStream.Length || FirstTextPos < 8)
     {
         return TL;
     }
     if (ProgressCallback != null)
     {
         ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
     }
     uint EntryCount = FirstTextPos / 4;
     // The entries are usually, but not always, sequential in the file.
     // Because we need to know how long one entry is (no clear end-of-message marker), we need them in
     // sequential order.
     List<uint> Entries = new List<uint>((int)EntryCount + 1);
     Entries.Add(FirstTextPos);
     for (int i = 1; i < EntryCount; ++i)
     {
         Entries.Add(BR.ReadUInt32() ^ 0x80808080);
     }
     Entries.Add((uint)BR.BaseStream.Length - 4);
     Entries.Sort();
     for (uint i = 0; i < EntryCount; ++i)
     {
         if (Entries[(int)i] < 4 * EntryCount || 4 + Entries[(int)i] >= BR.BaseStream.Length)
         {
             TL.Clear();
             break;
         }
         Things.DialogTableEntry DTE = new Things.DialogTableEntry();
         if (!DTE.Read(BR, i, Entries[(int)i], Entries[(int)i + 1]))
         {
             TL.Clear();
             break;
         }
         if (ProgressCallback != null)
         {
             ProgressCallback(null, (double)(i + 1) / EntryCount);
         }
         TL.Add(DTE);
     }
     return TL;
 }
Example #13
0
        public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
        {
            ThingList TL = new ThingList();

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
            }
            if ((BR.BaseStream.Length % 0x20) != 0 || BR.BaseStream.Position != 0)
            {
                return(TL);
            }
            long EntryCount = BR.BaseStream.Length / 0x20;

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
            }
            try {
                int ZoneID = -1;
                for (int i = 0; i < EntryCount; ++i)
                {
                    Things.MobListEntry MLE = new Things.MobListEntry();
                    if (!MLE.Read(BR))
                    {
                        TL.Clear();
                        break;
                    }
                    uint ThisID = (uint)MLE.GetFieldValue("id");
                    if (i == 0 && (ThisID != 0 || MLE.GetFieldText("name") != "none"))
                    {
                        TL.Clear();
                        break;
                    }
                    else if (i > 0) // Entire file should be for 1 specific zone
                    {
                        int ThisZone = (int)(ThisID & 0x000FF000);
                        if (ZoneID < 0)
                        {
                            ZoneID = ThisZone;
                        }
                        else if (ThisZone != ZoneID)
                        {
                            TL.Clear();
                            break;
                        }
                    }
                    if (ProgressCallback != null)
                    {
                        ProgressCallback(null, (double)(i + 1) / EntryCount);
                    }
                    TL.Add(MLE);
                }
            } catch {
                TL.Clear();
            }
            return(TL);
        }
Example #14
0
        private void LoadItemsWorker(string FileName, ItemEditor IE)
        {
            ThingList <Item> TL = new ThingList <Item>();

            if (TL.Load(FileName))
            {
                if (IE == this.ieLeft)
                {
                    this.LeftItems = TL;
                }
                else
                {
                    this.RightItems = TL;
                }
            }
            this.LeftItemsShown  = null;
            this.RightItemsShown = null;
            if (this.RightItems == null && this.LeftItems == null)
            {
                this.CurrentItem = -1;
            }
            else
            {
                this.CurrentItem = 0;
            }
            // In general, this tool supports comparing heterogenic item sets (as useless as that may be).
            // However, the 2010-09-09 patch prepended a range of 1024 armor pieces to the previous range (so 0x2800-0x4000 instead of 0x2C00-0x4000).
            // So we detect that specific case and cope with it padding the shorter set at the front (with nulls); this also means we should drop leading null entries whenever
            // a new set is loaded.
            while (this.LeftItems != null && this.LeftItems.Count > 0 && this.LeftItems[0] == null)
            {
                this.LeftItems.RemoveAt(0);
            }
            while (this.RightItems != null && this.RightItems.Count > 0 && this.RightItems[0] == null)
            {
                this.RightItems.RemoveAt(0);
            }
            if (this.RightItems != null && this.LeftItems != null)
            {
                if (this.LeftItems.Count != this.RightItems.Count)
                {
                    uint LID = (uint)this.LeftItems [0].GetFieldValue("id");
                    uint RID = (uint)this.RightItems[0].GetFieldValue("id");
                    if (LID == 0x2800 && RID == 0x2c00)
                    {
                        this.RightItems.InsertRange(0, new Item[0x400]);
                    }
                    if (LID == 0x2c00 && RID == 0x2800)
                    {
                        this.LeftItems.InsertRange(0, new Item[0x400]);
                    }
                }
                this.btnRemoveUnchanged.Invoke(new AnonymousMethod(delegate() { this.btnRemoveUnchanged.Enabled = true; }));
            }
            this.PWD.Invoke(new AnonymousMethod(delegate() { this.PWD.Close(); }));
        }
Example #15
0
        private void mnuILCESelected_Click(object sender, EventArgs e)
        {
            ThingList <Item> Items = new ThingList <Item>();

            foreach (ListViewItem LVI in this.lstItems.SelectedItems)
            {
                Items.Add(LVI.Tag as Item);
            }
            this.DoExport(Items);
            Items.Clear();
        }
Example #16
0
        private static ThingList CreateModel()
        {
            var result = new ThingList();

            for (var i = 0; i < 20; i++)
            {
                result.Add(new Thing(i.ToString(), i));
            }

            return result;
        }
Example #17
0
 public void ScanFile(IWin32Window ParentForm, string FileName)
 {
     lock (this.FSD)
     {
         if (FileName != null && File.Exists(FileName))
         {
             this.FSD = new FileScanDialog();
             Thread T = new Thread(new ThreadStart(delegate()
             {
                 try
                 {
                     Application.DoEvents();
                     while (!this.FSD.Visible)
                     {
                         Thread.Sleep(0);
                         Application.DoEvents();
                     }
                     this.FSD.Invoke(new AnonymousMethod(delegate() { this.FSD.ResetProgress(); }));
                     this.FileContents = FileType.LoadAll(FileName,
                                                          new FileType.ProgressCallback(delegate(string Message, double PercentCompleted)
                     {
                         this.FSD.Invoke(new AnonymousMethod(delegate()
                         {
                             this.FSD.SetProgress(Message, PercentCompleted);
                         }));
                     }));
                 }
                 catch
                 {
                     this.FileContents = null;
                 }
                 finally
                 {
                     this.FSD.Invoke(new AnonymousMethod(delegate() { this.FSD.Finish(); }));
                 }
             }));
             T.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
             T.Start();
             if (this.FSD.ShowDialog(ParentForm) == DialogResult.Abort)
             {
                 this.FSD.Finish();
                 this.FileContents = null;
             }
             if (T.IsAlive)
             {
                 T.Abort();
             }
             this.FSD.Dispose();
             this.FSD = null;
         }
     }
 }
Example #18
0
 public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
 {
     ThingList TL = new ThingList();
       if (ProgressCallback != null)
     ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
       if (Encoding.ASCII.GetString(BR.ReadBytes(4)) != "menu")
     return TL;
       if (BR.ReadInt32() != 0x101)
     return TL;
       if (BR.ReadInt64() != 0x000)
     return TL;
       if (BR.ReadInt64() != 0)
     return TL;
       if (BR.ReadInt64() != 0)
     return TL;
       if (ProgressCallback != null)
     ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
       while (BR.BaseStream.Position + 0x10 <= BR.BaseStream.Length) {
     if (ProgressCallback != null)
       ProgressCallback(null, ((double) (BR.BaseStream.Position + 1) / BR.BaseStream.Length));
       long   Offset    = BR.BaseStream.Position;
       string ShortName = Encoding.ASCII.GetString(BR.ReadBytes(4));
       uint   SizeInfo  = BR.ReadUInt32();
     if (BR.ReadUInt64() != 0) {
       TL.Clear();
       return TL;
     }
     if (BR.BaseStream.Position < BR.BaseStream.Length) {
       if (Encoding.ASCII.GetString(BR.ReadBytes(8)) != "menu    ") {
     TL.Clear();
     return TL;
       }
     string MenuName = Encoding.ASCII.GetString(BR.ReadBytes(8));
       // Used to be a full match but the JP data of 20061218 had pr_sc vs pr_1
       if (BR.ReadUInt32() != 0 || MenuName.Substring(0, 3) != ShortName.Substring(0, 3)) {
     TL.Clear();
     return TL;
       }
     int EntryCount = BR.ReadInt32();
       for (int i = 0; i < EntryCount; ++i) {
       Things.QuestInfo QI = new Things.QuestInfo();
     if (!QI.Read(BR, MenuName, Offset + 0x10)) {
       TL.Clear();
       return TL;
     }
     TL.Add(QI);
       }
     }
     BR.BaseStream.Position = Offset + ((SizeInfo & 0xFFFFFF80) >> 3);
       }
       return TL;
 }
Example #19
0
        public override void TestInitialise()
        {
            base.TestInitialise();
            //Get bloody ms test to include the dll in test output
            MySql.Data.MySqlClient.MySqlCommand command = new MySql.Data.MySqlClient.MySqlCommand();

            // Delete all things
            ThingRepo.DeleteAll();

            // Should be no things. Check now
            ThingList things = ThingRepo.GetAll();

            Assert.AreEqual(0, things.Count, "Should be no things");
        }
Example #20
0
 public void ScanFile(IWin32Window ParentForm, string FileName)
 {
     lock (this.FSD)
     {
         if (FileName != null && File.Exists(FileName))
         {
             this.FSD = new FileScanDialog();
             Thread T = new Thread(new ThreadStart(delegate()
             {
                 try
                 {
                     Application.DoEvents();
                     while (!this.FSD.Visible)
                     {
                         Thread.Sleep(0);
                         Application.DoEvents();
                     }
                     this.FSD.Invoke(new AnonymousMethod(delegate() { this.FSD.ResetProgress(); }));
                     this.FileContents = FileType.LoadAll(FileName,
                         new FileType.ProgressCallback(delegate(string Message, double PercentCompleted)
                         {
                             this.FSD.Invoke(new AnonymousMethod(delegate()
                             {
                                 this.FSD.SetProgress(Message, PercentCompleted);
                             }));
                         }));
                     this.FSD.Invoke(new AnonymousMethod(delegate() { this.FSD.Finish(); }));
                 }
                 catch
                 {
                     this.FileContents = null;
                 }
             }));
             T.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
             T.Start();
             if (this.FSD.ShowDialog(ParentForm) == DialogResult.Abort)
             {
                 this.FSD.Finish();
                 this.FileContents = null;
             }
             if (T.IsAlive)
             {
                 T.Abort();
             }
             this.FSD.Dispose();
             this.FSD = null;
         }
     }
 }
Example #21
0
 public ItemFindDialog(ThingList<Item> Items)
 {
     InitializeComponent();
       this.Icon          = Icons.Search;
       this.Items_        = Items;
       this.SelectedItem_ = null;
       this.lstItems.Columns.Add(I18N.GetText("ColumnHeader:Index"), 40, HorizontalAlignment.Left);
       { // Add all item fields as columns for the result, and as entries on the "Copy" context menu
       Item I = new Item();
     foreach (string Field in I.GetAllFields()) {
       this.lstItems.Columns.Add(I.GetFieldName(Field), 100, HorizontalAlignment.Left);
       this.mnuILCCopy.MenuItems.Add(new MenuItem(I.GetFieldName(Field), new EventHandler(this.CopyContextMenu_Click)));
     }
       }
       this.lstItems.ColumnClick += new ColumnClickEventHandler(ListViewColumnSorter.ListView_ColumnClick);
       this.AddPredicate();
 }
Example #22
0
        public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
        {
            ThingList TL = new ThingList();

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
            }
            if ((BR.BaseStream.Length % 0xC00) != 0 || BR.BaseStream.Length < 0xc000 || BR.BaseStream.Position != 0)
            {
                return(TL);
            }
            // First deduce the type of item data is in the file.
            Item.Type T;
            Item.DeduceType(BR, out T);
            // Now read the items
            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
            }
            long ItemCount   = BR.BaseStream.Length / 0xC00;
            long CurrentItem = 0;

            while (BR.BaseStream.Position < BR.BaseStream.Length)
            {
                Item I = new Item();
                if (!I.Read(BR, T))
                {
                    TL.Clear();
                    break;
                }
                if (ProgressCallback != null)
                {
                    ProgressCallback(null, (double)++CurrentItem / ItemCount);
                }
                TL.Add(I);
                // A currency DAT currently has 1 "real" item and 15 dummy entries (all NULs); a better thing to do would be to break if such a dummy entry
                // is seen, but since we currently detect currency from its 0xFFFF ID, this is safe enough for now.
                if (BR.BaseStream.Length == 0xc000 && T == Item.Type.Currency)
                {
                    break;
                }
            }
            return(TL);
        }
Example #23
0
 public ItemFindDialog(ThingList <Item> Items)
 {
     InitializeComponent();
     this.Icon          = Icons.Search;
     this.Items_        = Items;
     this.SelectedItem_ = null;
     this.lstItems.Columns.Add(I18N.GetText("ColumnHeader:Index"), 40, HorizontalAlignment.Left);
     { // Add all item fields as columns for the result, and as entries on the "Copy" context menu
         Item I = new Item();
         foreach (string Field in I.GetAllFields())
         {
             this.lstItems.Columns.Add(I.GetFieldName(Field), 100, HorizontalAlignment.Left);
             this.mnuILCCopy.MenuItems.Add(new MenuItem(I.GetFieldName(Field), new EventHandler(this.CopyContextMenu_Click)));
         }
     }
     this.lstItems.ColumnClick += new ColumnClickEventHandler(ListViewColumnSorter.ListView_ColumnClick);
     this.AddPredicate();
 }
Example #24
0
 public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
 {
     ThingList TL = new ThingList();
       if (ProgressCallback != null)
     ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
       if (BR.BaseStream.Length < 0x38 || BR.BaseStream.Position != 0)
     return TL;
     FFXIEncoding E = new FFXIEncoding();
       // Skip (presumably) fixed portion of the header
       if ((E.GetString(BR.ReadBytes(8)) != "d_msg".PadRight(8, '\0')) || BR.ReadUInt16() != 1 || BR.ReadUInt32() != 0 || BR.ReadUInt16() != 2 || BR.ReadUInt32() != 3)
     return TL;
       // Read the useful header fields
     uint EntryCount = BR.ReadUInt32();
       if (BR.ReadUInt32() != 1)
     return TL;
     uint FileSize = BR.ReadUInt32();
       if (FileSize != BR.BaseStream.Length)
     return TL;
     uint HeaderSize = BR.ReadUInt32();
       if (HeaderSize != 0x38)
     return TL;
     uint EntryBytes = BR.ReadUInt32();
       if (EntryBytes != EntryCount * 36)
     return TL;
     uint DataBytes  = BR.ReadUInt32();
       if (FileSize != 0x38 + EntryBytes + DataBytes)
     return TL;
       // 12 NUL bytes
       if (BR.ReadUInt32() != 0 || BR.ReadUInt32() != 0 || BR.ReadUInt32() != 0)
     return TL;
       if (ProgressCallback != null)
     ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
       for (uint i = 0; i < EntryCount; ++i) {
       Things.DMSGStringTableEntry DSTE = new Things.DMSGStringTableEntry();
     if (!DSTE.Read(BR, E, i, EntryBytes, DataBytes)) {
       TL.Clear();
       break;
     }
     if (ProgressCallback != null)
       ProgressCallback(null, (double) (i + 1) / EntryCount);
     TL.Add(DSTE);
       }
       return TL;
 }
Example #25
0
 private static void ExtractFile(string ROMPath, string OutputFile)
 {
     try
     {
         Console.Write(I18N.GetText("Extracting"), Path.GetFileName(OutputFile));
         ThingList KnownData = FileType.LoadAll(ROMPath, null);
         Console.ForegroundColor = ConsoleColor.White;
         Console.Write(I18N.GetText("Load"));
         if (KnownData != null)
         {
             Console.ForegroundColor = ConsoleColor.Green;
             Console.Write(I18N.GetText("OK"));
             bool SaveOK = KnownData.Save(OutputFile);
             Console.ForegroundColor = ConsoleColor.White;
             Console.Write(I18N.GetText("Save"));
             if (SaveOK)
             {
                 Console.ForegroundColor = ConsoleColor.Green;
                 Console.WriteLine(I18N.GetText("OK"));
             }
             else
             {
                 Console.ForegroundColor = ConsoleColor.Red;
                 Console.WriteLine(I18N.GetText("FAILED"));
             }
             KnownData.Clear();
         }
         else
         {
             Console.ForegroundColor = ConsoleColor.Red;
             Console.WriteLine(I18N.GetText("FAILED"));
         }
     }
     catch (Exception E)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(I18N.GetText("Exception"), E.Message);
     }
     finally
     {
         Console.ForegroundColor = ConsoleColor.White;
     }
 }
Example #26
0
 public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
 {
     ThingList TL = new ThingList();
     if (ProgressCallback != null)
     {
         ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
     }
     if ((BR.BaseStream.Length % 0xC00) != 0 || BR.BaseStream.Length < 0xc000 || BR.BaseStream.Position != 0)
     {
         return TL;
     }
     // First deduce the type of item data is in the file.
     Item.Type T;
     Item.DeduceType(BR, out T);
     // Now read the items
     if (ProgressCallback != null)
     {
         ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
     }
     long ItemCount = BR.BaseStream.Length / 0xC00;
     long CurrentItem = 0;
     while (BR.BaseStream.Position < BR.BaseStream.Length)
     {
         Item I = new Item();
         if (!I.Read(BR, T))
         {
             TL.Clear();
             break;
         }
         if (ProgressCallback != null)
         {
             ProgressCallback(null, (double)++CurrentItem / ItemCount);
         }
         TL.Add(I);
         // A currency DAT currently has 1 "real" item and 15 dummy entries (all NULs); a better thing to do would be to break if such a dummy entry
         // is seen, but since we currently detect currency from its 0xFFFF ID, this is safe enough for now.
         if (BR.BaseStream.Length == 0xc000 && T == Item.Type.Currency)
         {
             break;
         }
     }
     return TL;
 }
Example #27
0
 private void DoExport(ThingList <Item> Items)
 {
     if (this.dlgExportFile.ShowDialog() == DialogResult.OK)
     {
         this.PWD = new PleaseWaitDialog(I18N.GetText("Dialog:ExportItems"));
         Thread T = new Thread(new ThreadStart(delegate() {
             Application.DoEvents();
             Items.Save(this.dlgExportFile.FileName);
             Application.DoEvents();
             this.PWD.Invoke(new AnonymousMethod(delegate() { this.PWD.Close(); }));
         }));
         T.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
         T.Start();
         this.PWD.ShowDialog(this);
         this.Activate();
         this.PWD.Dispose();
         this.PWD = null;
     }
 }
Example #28
0
        private void mnuELCESelected_Click(object sender, EventArgs e)
        {
            ListView LV = this.mnuEntryListContext.SourceControl as ListView;

            if (LV != null)
            {
                ThingList ThingsToExport = new ThingList();
                foreach (ListViewItem LVI in LV.SelectedItems)
                {
                    if (LVI.Tag is IThing)
                    {
                        ThingsToExport.Add(LVI.Tag as IThing);
                    }
                }
                if (ThingsToExport.Count > 0)
                {
                    this.ExportThings(ThingsToExport);
                }
            }
        }
Example #29
0
        public async Task <IActionResult> CreateThings([Bind("Id,Name,Owned,EventId")] Thing thing)
        {
            //Saving to ThingList table
            var thingname = new ThingList();

            thingname.Name = thing.Name;
            _context.Add(thingname);
            await _context.SaveChangesAsync();

            var eventname = await _context.Events.FirstOrDefaultAsync(i => i.Name == thing.EventId);

            thing.EventName = eventname.Id;

            if (ModelState.IsValid)
            {
                _context.Add(thing);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(thing));
        }
Example #30
0
 public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
 {
     ThingList TL = new ThingList();
       if (ProgressCallback != null)
     ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
       if ((BR.BaseStream.Length % 0x40) != 0 || BR.BaseStream.Position != 0)
     return TL;
     long EntryCount = BR.BaseStream.Length / 0x40;
       if (ProgressCallback != null)
     ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
       for (int i = 0; i < EntryCount; ++i) {
       Things.SimpleStringTableEntry SSTE = new Things.SimpleStringTableEntry();
     if (!SSTE.Read(BR)) {
       TL.Clear();
       break;
     }
     if (ProgressCallback != null)
       ProgressCallback(null, (double) (i + 1) / EntryCount);
     TL.Add(SSTE);
       }
       return TL;
 }
Example #31
0
 public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
 {
     ThingList TL = new ThingList();
       if (ProgressCallback != null)
     ProgressCallback(I18N.GetText("FTM:ScanningFile"), 0);
     Graphic G = new Graphic();
       while (BR.BaseStream.Position < BR.BaseStream.Length) {
       long Pos = BR.BaseStream.Position; // Save Position (G.Read() will advance it an unknown amount)
     if (G.Read(BR)) {
       TL.Add(G);
       G = new Graphic();
       if (ProgressCallback != null)
     ProgressCallback(null, (double) (BR.BaseStream.Position + 1) / BR.BaseStream.Length);
     }
     else {
       BR.BaseStream.Seek(Pos + 1, SeekOrigin.Begin);
       if (ProgressCallback != null && (BR.BaseStream.Position == BR.BaseStream.Length || (BR.BaseStream.Position % 1024) == 0))
     ProgressCallback(null, (double) (BR.BaseStream.Position + 1) / BR.BaseStream.Length);
     }
       }
       G = null;
       return TL;
 }
Example #32
0
 public void ScanFile(IWin32Window ParentForm, string FileName)
 {
     lock (this.FSD) {
         if (FileName != null && File.Exists(FileName))
         {
             this.FSD = new FileScanDialog();
             var T = new Thread(() => {
                 try {
                     Application.DoEvents();
                     while (!this.FSD.Visible)
                     {
                         Thread.Sleep(0);
                         Application.DoEvents();
                     }
                     this.FSD.Invoke(new AnonymousMethod(() => this.FSD.ResetProgress()));
                     this.FileContents = FileType.LoadAll(FileName, (msg, pct) => this.FSD.Invoke(new AnonymousMethod(() => this.FSD.SetProgress(msg, pct))));
                     this.FSD.Invoke(new AnonymousMethod(() => this.FSD.Finish()));
                 } catch {
                     this.FileContents = null;
                 }
             });
             T.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
             T.Start();
             if (this.FSD.ShowDialog(ParentForm) == DialogResult.Abort)
             {
                 this.FSD.Finish();
                 this.FileContents = null;
             }
             if (T.IsAlive)
             {
                 T.Abort();
             }
             this.FSD.Dispose();
             this.FSD = null;
         }
     }
 }
Example #33
0
        public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
        {
            ThingList TL = new ThingList();

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
            }
            if (BR.BaseStream.Length < 0x40 || BR.BaseStream.Position != 0)
            {
                return(TL);
            }
            FFXIEncoding E = new FFXIEncoding();

            if (E.GetString(BR.ReadBytes(8)) != "d_msg".PadRight(8, '\0'))
            {
                return(TL);
            }
            ushort Flag1 = BR.ReadUInt16();

            if (Flag1 != 0 && Flag1 != 1)
            {
                return(TL);
            }
            ushort Flag2 = BR.ReadUInt16();

            if (Flag2 != 0 && Flag2 != 1)
            {
                return(TL);
            }
            if (BR.ReadUInt32() != 3 || BR.ReadUInt32() != 3)
            {
                return(TL);
            }
            uint FileSize = BR.ReadUInt32();

            if (FileSize != BR.BaseStream.Length)
            {
                return(TL);
            }
            uint HeaderBytes = BR.ReadUInt32();

            if (HeaderBytes != 0x40)
            {
                return(TL);
            }
            if (BR.ReadUInt32() != 0)
            {
                return(TL);
            }
            int BytesPerEntry = BR.ReadInt32();

            if (BytesPerEntry < 0)
            {
                return(TL);
            }
            uint DataBytes = BR.ReadUInt32();

            if (FileSize != (HeaderBytes + DataBytes) || (DataBytes % BytesPerEntry) != 0)
            {
                return(TL);
            }
            uint EntryCount = BR.ReadUInt32();

            if (EntryCount * BytesPerEntry != DataBytes)
            {
                return(TL);
            }
            if (BR.ReadUInt32() != 1 || BR.ReadUInt64() != 0 || BR.ReadUInt64() != 0)
            {
                return(TL);
            }
            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
            }
            for (uint i = 0; i < EntryCount; ++i)
            {
                BinaryReader EntryBR = new BinaryReader(new MemoryStream(BR.ReadBytes(BytesPerEntry)));
                EntryBR.BaseStream.Position = 0;
                bool ItemAdded = false;
                {
                    Things.DMSGStringBlock SB = new Things.DMSGStringBlock();
                    if (SB.Read(EntryBR, E, i))
                    {
                        TL.Add(SB);
                        ItemAdded = true;
                    }
                }
                EntryBR.Close();
                if (!ItemAdded)
                {
                    TL.Clear();
                    break;
                }
                if (ProgressCallback != null)
                {
                    ProgressCallback(null, (double)(i + 1) / EntryCount);
                }
            }
            return(TL);
        }
Example #34
0
 public void SetUp()
 {
     _list = new ThingList
                 {
                     new Thing("A", 0),
                     new Thing("B", 1),
                     new Thing("C", 2),
                     new Thing("D", 3),
                 };
 }
Example #35
0
        public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
        {
            ThingList TL = new ThingList();

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
            }
            if (BR.BaseStream.Length < 4)
            {
                return(TL);
            }
            uint FileSizeMaybe = BR.ReadUInt32();

            if (FileSizeMaybe != (0x10000000 + BR.BaseStream.Length - 4))
            {
                return(TL);
            }
            uint FirstTextPos = (BR.ReadUInt32() ^ 0x80808080);

            if ((FirstTextPos % 4) != 0 || FirstTextPos > BR.BaseStream.Length || FirstTextPos < 8)
            {
                return(TL);
            }
            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
            }
            uint EntryCount = FirstTextPos / 4;
            // The entries are usually, but not always, sequential in the file.
            // Because we need to know how long one entry is (no clear end-of-message marker), we need them in
            // sequential order.
            List <uint> Entries = new List <uint>((int)EntryCount + 1);

            Entries.Add(FirstTextPos);
            for (int i = 1; i < EntryCount; ++i)
            {
                Entries.Add(BR.ReadUInt32() ^ 0x80808080);
            }
            Entries.Add((uint)BR.BaseStream.Length - 4);
            Entries.Sort();
            for (uint i = 0; i < EntryCount; ++i)
            {
                if (Entries[(int)i] < 4 * EntryCount || 4 + Entries[(int)i] >= BR.BaseStream.Length)
                {
                    TL.Clear();
                    break;
                }
                Things.DialogTableEntry DTE = new Things.DialogTableEntry();
                if (!DTE.Read(BR, i, Entries[(int)i], Entries[(int)i + 1]))
                {
                    TL.Clear();
                    break;
                }
                if (ProgressCallback != null)
                {
                    ProgressCallback(null, (double)(i + 1) / EntryCount);
                }
                TL.Add(DTE);
            }
            return(TL);
        }
 public static void Refresh(ThingList thingList, Flags toPopulate)
 {
     _instance.Refresh(thingList, toPopulate);
 }
Example #37
0
 private void LoadFile(string FileName)
 {
     this.ResetViewers();
     this.LoadedThings_ = null;
     if (FileName != null && File.Exists(FileName))
     {
         this.Enabled = false;
         FileScanner FS = new FileScanner();
         FS.ScanFile(this, FileName);
         this.LoadedThings_ = FS.FileContents;
         this.LoadedItems_  = new ThingList <Item>();
         if (FS.FileContents != null)
         {
             int LoadCount = 0;
             if (FS.FileContents.Count > 0)
             {
                 this.tabViewers.TabPages.Add(this.tabViewerGeneral);
                 this.tabViewers.Visible = true;
                 Application.DoEvents();
                 foreach (IThing T in FS.FileContents)
                 {
                     ListView LV        = this.MaybeAddListView(T.TypeName);
                     int      IconIndex = -1;
                     {
                         Image Icon = T.GetIcon();
                         if (Icon != null)
                         {
                             IconIndex = this.ListIcons_.Images.Count;
                             this.ListIcons_.Images.Add(Icon);
                         }
                     }
                     ListViewItem LVI = LV.Items.Add(T.TypeName, IconIndex);
                     LVI.Tag = T;
                     for (int i = 1; i < LV.Columns.Count; ++i)
                     {
                         LVI.SubItems.Add("");
                     }
                     foreach (string Field in T.GetFields())
                     {
                         if (!LV.Columns.ContainsKey(Field))
                         {
                             LV.Columns.Add(Field, T.GetFieldName(Field), 60, HorizontalAlignment.Left, -1);
                             LVI.SubItems.Add("");
                         }
                         LVI.SubItems[LV.Columns[Field].Index].Text = T.GetFieldText(Field);
                     }
                     if (T is Item)
                     {
                         if (this.cmbItems.Items.Count == 0)
                         {
                             this.tabViewers.TabPages.Add(this.tabViewerItems);
                         }
                         this.cmbItems.Items.Add(T);
                         this.LoadedItems_.Add(T as Item);
                     }
                     else if (T is Graphic)
                     {
                         if (this.cmbImageChooser.Items.Count == 0)
                         {
                             this.tabViewers.TabPages.Add(this.tabViewerImages);
                         }
                         this.cmbImageChooser.Items.Add(T);
                     }
                     if ((++LoadCount % 100) == 0)
                     {
                         Application.DoEvents();
                     }
                 }
                 this.btnThingListSaveImages.Enabled = (this.ListIcons_.Images.Count != 0);
                 this.chkShowIcons.Enabled           = (this.ListIcons_.Images.Count != 0);
                 Application.DoEvents();
                 foreach (ListView LV in this.ListViews_.Values)
                 {
                     if (this.ListIcons_.Images.Count == 0)
                     {
                         LV.SmallImageList = null;
                     }
                     LV.HeaderStyle = ColumnHeaderStyle.Clickable;
                 }
                 this.ResizeListColumns();
             }
             if (this.cmbImageChooser.Items.Count > 0)
             {
                 this.cmbImageChooser.SelectedItem = null;
                 this.tabViewers.SelectedTab       = this.tabViewerImages;
                 this.cmbImageChooser.Select();
                 this.cmbImageChooser.SelectedIndex = 0;
                 Application.DoEvents();
             }
             if (this.cmbItems.Items.Count > 0)
             {
                 this.cmbItems.SelectedItem  = null;
                 this.tabViewers.SelectedTab = this.tabViewerItems;
                 this.cmbItems.Select();
                 this.cmbItems.SelectedIndex = 0;
                 Application.DoEvents();
             }
         }
         if (!this.tabViewers.Visible)
         {
             this.pnlNoViewers.Visible = true;
         }
         this.Enabled = true;
     }
 }
Example #38
0
 private void mnuILCESelected_Click(object sender, EventArgs e)
 {
     ThingList<Item> Items = new ThingList<Item>();
       foreach (ListViewItem LVI in this.lstItems.SelectedItems)
     Items.Add(LVI.Tag as Item);
       this.DoExport(Items);
       Items.Clear();
 }
        public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
        {
            ThingList TL = new ThingList();

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
            }
            if (BR.BaseStream.Position != 0)
            {
                goto Failed;
            }
            if (Encoding.ASCII.GetString(BR.ReadBytes(4)) != "menu")
            {
                goto Failed;
            }
            if (BR.ReadInt32() != 0x101)
            {
                goto Failed;
            }
            if (BR.ReadInt64() != 0)
            {
                goto Failed;
            }
            if (BR.ReadInt64() != 0)
            {
                goto Failed;
            }
            if (BR.ReadInt64() != 0)
            {
                goto Failed;
            }
            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:LoadingData"), (double)BR.BaseStream.Position / BR.BaseStream.Length);
            }
            string firstFourBytes = Encoding.ASCII.GetString(BR.ReadBytes(4));

            { // Part 0: Monster?
                if (firstFourBytes != "mon_")
                {
                    goto Part1;
                }
                uint SizeInfo = BR.ReadUInt32();
                if (BR.ReadInt64() != 0)
                {
                    goto Failed;
                }
                uint BlockSize = (SizeInfo & 0xFFFFFF80) >> 3;
                if ((BlockSize - 0x10) % 0x40 != 0)
                {
                    goto Failed;
                }
                uint EntryCount = (BlockSize - 0x10) / 0x40;
                while (EntryCount-- > 0)
                {
                    Things.MonsterSpellInfo MSI2 = new Things.MonsterSpellInfo();
                    if (!MSI2.Read(BR))
                    {
                        goto Failed;
                    }
                    if (ProgressCallback != null)
                    {
                        ProgressCallback(null, (double)BR.BaseStream.Position / BR.BaseStream.Length);
                    }
                    TL.Add(MSI2);
                }
            }
            firstFourBytes = Encoding.ASCII.GetString(BR.ReadBytes(4));
Part1:
            { // Part 1: Spell Info
                if (firstFourBytes != "mgc_")
                {
                    goto Failed;
                }
                uint SizeInfo = BR.ReadUInt32();
                if (BR.ReadInt64() != 0)
                {
                    goto Failed;
                }
                uint BlockSize = (SizeInfo & 0xFFFFFF80) >> 3;
                if ((BlockSize - 0x10) % 0x40 != 0)
                {
                    goto Failed;
                }
                uint EntryCount = (BlockSize - 0x10) / 0x40;
                while (EntryCount-- > 0)
                {
                    Things.SpellInfo2 SI2 = new Things.SpellInfo2();
                    if (!SI2.Read(BR))
                    {
                        goto Failed;
                    }
                    if (ProgressCallback != null)
                    {
                        ProgressCallback(null, (double)BR.BaseStream.Position / BR.BaseStream.Length);
                    }
                    TL.Add(SI2);
                }
            }
            { // Part 2: Ability Info
                if (Encoding.ASCII.GetString(BR.ReadBytes(4)) != "comm")
                {
                    goto Failed;
                }
                uint SizeInfo = BR.ReadUInt32();
                if (BR.ReadInt64() != 0)
                {
                    goto Failed;
                }
                uint BlockSize = (SizeInfo & 0xFFFFFF80) >> 3;
                if ((BlockSize - 0x10) % 0x30 != 0)
                {
                    goto Failed;
                }
                uint EntryCount = (BlockSize - 0x10) / 0x30;
                while (EntryCount-- > 0)
                {
                    Things.AbilityInfo2 AI2 = new Things.AbilityInfo2();
                    if (!AI2.Read(BR))
                    {
                        goto Failed;
                    }
                    if (ProgressCallback != null)
                    {
                        ProgressCallback(null, (double)BR.BaseStream.Position / BR.BaseStream.Length);
                    }
                    TL.Add(AI2);
                }
            }
            { // Part 3: End Marker
                if (Encoding.ASCII.GetString(BR.ReadBytes(4)) != "end\0")
                {
                    goto Failed;
                }
                uint SizeInfo = BR.ReadUInt32();
                if (BR.ReadInt64() != 0)
                {
                    goto Failed;
                }
                uint BlockSize = (SizeInfo & 0xFFFFFF80) >> 3;
                if (BlockSize != 0x10) // Header only
                {
                    goto Failed;
                }
                if (ProgressCallback != null)
                {
                    ProgressCallback(null, (double)BR.BaseStream.Position / BR.BaseStream.Length);
                }
            }
            goto Done;
Failed:
            TL.Clear();
Done:
            return(TL);
        }
Example #40
0
 private void ExportThings(ThingList ThingsToExport)
 {
     this.dlgExportFile.FileName = "";
       if (this.dlgExportFile.ShowDialog() == DialogResult.OK) {
     this.PWD = new PleaseWaitDialog(I18N.GetText("Dialog:ExportFileContents"));
       Thread T = new Thread(new ThreadStart(delegate () {
       ThingsToExport.Save(this.dlgExportFile.FileName);
       Application.DoEvents();
       this.PWD.Invoke(new AnonymousMethod(delegate() { this.PWD.Close(); }));
     }));
     T.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
     T.Start();
     this.PWD.ShowDialog(this);
     this.Activate();
     this.PWD.Dispose();
     this.PWD = null;
       }
 }
Example #41
0
        public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
        {
            ThingList TL = new ThingList();

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
            }
            if (Encoding.ASCII.GetString(BR.ReadBytes(4)) != "menu")
            {
                return(TL);
            }
            if (BR.ReadInt32() != 0x101)
            {
                return(TL);
            }
            if (BR.ReadInt64() != 0x000)
            {
                return(TL);
            }
            if (BR.ReadInt64() != 0)
            {
                return(TL);
            }
            if (BR.ReadInt64() != 0)
            {
                return(TL);
            }
            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
            }
            while (BR.BaseStream.Position + 0x10 <= BR.BaseStream.Length)
            {
                if (ProgressCallback != null)
                {
                    ProgressCallback(null, ((double)(BR.BaseStream.Position + 1) / BR.BaseStream.Length));
                }
                long   Offset    = BR.BaseStream.Position;
                string ShortName = Encoding.ASCII.GetString(BR.ReadBytes(4));
                uint   SizeInfo  = BR.ReadUInt32();
                if (BR.ReadUInt64() != 0)
                {
                    TL.Clear();
                    return(TL);
                }
                if (BR.BaseStream.Position < BR.BaseStream.Length)
                {
                    if (Encoding.ASCII.GetString(BR.ReadBytes(8)) != "menu    ")
                    {
                        TL.Clear();
                        return(TL);
                    }
                    string MenuName = Encoding.ASCII.GetString(BR.ReadBytes(8));
                    // Used to be a full match but the JP data of 20061218 had pr_sc vs pr_1
                    if (BR.ReadUInt32() != 0 || MenuName.Substring(0, 3) != ShortName.Substring(0, 3))
                    {
                        TL.Clear();
                        return(TL);
                    }
                    int EntryCount = BR.ReadInt32();
                    for (int i = 0; i < EntryCount; ++i)
                    {
                        Things.QuestInfo QI = new Things.QuestInfo();
                        if (!QI.Read(BR, MenuName, Offset + 0x10))
                        {
                            TL.Clear();
                            return(TL);
                        }
                        TL.Add(QI);
                    }
                }
                BR.BaseStream.Position = Offset + ((SizeInfo & 0xFFFFFF80) >> 3);
            }
            return(TL);
        }
 public static void Save(ThingList thingList)
 {
     _instance.Save(thingList);
 }
Example #43
0
 private void LoadFile(string FileName)
 {
     this.ResetViewers();
       this.LoadedThings_ = null;
       if (FileName != null && File.Exists(FileName)) {
     this.Enabled = false;
       FileScanner FS = new FileScanner();
     FS.ScanFile(this, FileName);
     this.LoadedThings_ = FS.FileContents;
     this.LoadedItems_  = new ThingList<Item>();
     if (FS.FileContents != null) {
     int LoadCount = 0;
       if (FS.FileContents.Count > 0) {
     this.tabViewers.TabPages.Add(this.tabViewerGeneral);
     this.tabViewers.Visible = true;
     Application.DoEvents();
     foreach (IThing T in FS.FileContents) {
     ListView LV = this.MaybeAddListView(T.TypeName);
     int IconIndex = -1;
       {
       Image Icon = T.GetIcon();
         if (Icon != null) {
           IconIndex = this.ListIcons_.Images.Count;
           this.ListIcons_.Images.Add(Icon);
         }
       }
     ListViewItem LVI = LV.Items.Add(T.TypeName, IconIndex);
       LVI.Tag = T;
       for (int i = 1; i < LV.Columns.Count; ++i)
         LVI.SubItems.Add("");
       foreach (string Field in T.GetFields()) {
         if (!LV.Columns.ContainsKey(Field)) {
           LV.Columns.Add(Field, T.GetFieldName(Field), 60, HorizontalAlignment.Left, -1);
           LVI.SubItems.Add("");
         }
         LVI.SubItems[LV.Columns[Field].Index].Text = T.GetFieldText(Field);
       }
       if (T is Item) {
         if (this.cmbItems.Items.Count == 0)
           this.tabViewers.TabPages.Add(this.tabViewerItems);
         this.cmbItems.Items.Add(T);
         this.LoadedItems_.Add(T as Item);
       }
       else if (T is Graphic) {
         if (this.cmbImageChooser.Items.Count == 0)
           this.tabViewers.TabPages.Add(this.tabViewerImages);
         this.cmbImageChooser.Items.Add(T);
       }
       if ((++LoadCount % 100) == 0)
         Application.DoEvents();
     }
     this.btnThingListSaveImages.Enabled = (this.ListIcons_.Images.Count != 0);
     this.chkShowIcons.Enabled = (this.ListIcons_.Images.Count != 0);
     Application.DoEvents();
     foreach (ListView LV in this.ListViews_.Values) {
       if (this.ListIcons_.Images.Count == 0)
         LV.SmallImageList = null;
       LV.HeaderStyle = ColumnHeaderStyle.Clickable;
     }
     this.ResizeListColumns();
       }
       if (this.cmbImageChooser.Items.Count > 0) {
     this.cmbImageChooser.SelectedItem = null;
     this.tabViewers.SelectedTab = this.tabViewerImages;
     this.cmbImageChooser.Select();
     this.cmbImageChooser.SelectedIndex = 0;
     Application.DoEvents();
       }
       if (this.cmbItems.Items.Count > 0) {
     this.cmbItems.SelectedItem = null;
     this.tabViewers.SelectedTab = this.tabViewerItems;
     this.cmbItems.Select();
     this.cmbItems.SelectedIndex = 0;
     Application.DoEvents();
       }
     }
     if (!this.tabViewers.Visible)
       this.pnlNoViewers.Visible = true;
     this.Enabled = true;
       }
 }
Example #44
0
        public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
        {
            ThingList TL = new ThingList();

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
            }
            if (BR.BaseStream.Length < 0x40 || BR.BaseStream.Position != 0)
            {
                return(TL);
            }
            FFXIEncoding E = new FFXIEncoding();

            // Skip (presumably) fixed portion of the header
            if ((E.GetString(BR.ReadBytes(8)) != "d_msg".PadRight(8, '\0')) || BR.ReadUInt16() != 1 || BR.ReadUInt16() != 1 || BR.ReadUInt32() != 3 || BR.ReadUInt32() != 3)
            {
                return(TL);
            }
            // Read the useful header fields
            uint FileSize = BR.ReadUInt32();

            if (FileSize != BR.BaseStream.Length)
            {
                return(TL);
            }
            uint HeaderBytes = BR.ReadUInt32();

            if (HeaderBytes != 0x40)
            {
                return(TL);
            }
            uint EntryBytes = BR.ReadUInt32();

            if (BR.ReadUInt32() != 0)
            {
                return(TL);
            }
            uint DataBytes = BR.ReadUInt32();

            if (FileSize != HeaderBytes + EntryBytes + DataBytes)
            {
                return(TL);
            }
            uint EntryCount = BR.ReadUInt32();

            if (EntryBytes != EntryCount * 8)
            {
                return(TL);
            }
            if (BR.ReadUInt32() != 1 || BR.ReadUInt64() != 0 || BR.ReadUInt64() != 0)
            {
                return(TL);
            }
            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
            }
            for (uint i = 0; i < EntryCount; ++i)
            {
                BR.BaseStream.Position = HeaderBytes + i * 8;
                int Offset = ~BR.ReadInt32();
                int Length = ~BR.ReadInt32();
                if (Length < 0 || Offset < 0 || Offset + Length > DataBytes)
                {
                    TL.Clear();
                    break;
                }
                BR.BaseStream.Position = HeaderBytes + EntryBytes + Offset;
                BinaryReader EntryBR   = new BinaryReader(new MemoryStream(BR.ReadBytes(Length)));
                bool         ItemAdded = false;
                {
                    Things.DMSGStringBlock SB = new Things.DMSGStringBlock();
                    if (SB.Read(EntryBR, E, i))
                    {
                        TL.Add(SB);
                        ItemAdded = true;
                    }
                }
                EntryBR.Close();
                if (!ItemAdded)
                {
                    TL.Clear();
                    break;
                }
                if (ProgressCallback != null)
                {
                    ProgressCallback(null, (double)(i + 1) / EntryCount);
                }
            }
            return(TL);
        }
Example #45
0
 private void mnuELCESelected_Click(object sender, EventArgs e)
 {
     ListView LV = this.mnuEntryListContext.SourceControl as ListView;
       if (LV != null) {
       ThingList ThingsToExport = new ThingList();
     foreach (ListViewItem LVI in LV.SelectedItems) {
       if (LVI.Tag is IThing)
     ThingsToExport.Add(LVI.Tag as IThing);
     }
     if (ThingsToExport.Count > 0)
       this.ExportThings(ThingsToExport);
       }
 }
Example #46
0
 private void LoadItemsWorker(string FileName, ItemEditor IE)
 {
     ThingList<Item> TL = new ThingList<Item>();
     if (TL.Load(FileName))
     {
         if (IE == this.ieLeft)
         {
             this.LeftItems = TL;
         }
         else
         {
             this.RightItems = TL;
         }
     }
     this.LeftItemsShown = null;
     this.RightItemsShown = null;
     if (this.RightItems == null && this.LeftItems == null)
     {
         this.CurrentItem = -1;
     }
     else
     {
         this.CurrentItem = 0;
     }
     // In general, this tool supports comparing heterogenic item sets (as useless as that may be).
     // However, the 2010-09-09 patch prepended a range of 1024 armor pieces to the previous range (so 0x2800-0x4000 instead of 0x2C00-0x4000).
     // So we detect that specific case and cope with it padding the shorter set at the front (with nulls); this also means we should drop leading null entries whenever
     // a new set is loaded.
     while (this.LeftItems != null && this.LeftItems.Count > 0 && this.LeftItems[0] == null)
     {
         this.LeftItems.RemoveAt(0);
     }
     while (this.RightItems != null && this.RightItems.Count > 0 && this.RightItems[0] == null)
     {
         this.RightItems.RemoveAt(0);
     }
     if (this.RightItems != null && this.LeftItems != null)
     {
         if (this.LeftItems.Count != this.RightItems.Count)
         {
             uint LID = (uint)this.LeftItems[0].GetFieldValue("id");
             uint RID = (uint)this.RightItems[0].GetFieldValue("id");
             if (LID == 0x2800 && RID == 0x2c00)
             {
                 this.RightItems.InsertRange(0, new Item[0x400]);
             }
             if (LID == 0x2c00 && RID == 0x2800)
             {
                 this.LeftItems.InsertRange(0, new Item[0x400]);
             }
         }
         this.btnRemoveUnchanged.Invoke(new AnonymousMethod(delegate() { this.btnRemoveUnchanged.Enabled = true; }));
     }
     this.PWD.Invoke(new AnonymousMethod(delegate() { this.PWD.Close(); }));
 }
Example #47
0
        /// <summary>
        /// Populate the sub entities of widgetList
        /// </summary>
        /// <param name="widgets"></param>
        /// <param name="toPopulate"></param>
        public override void Populate(IEnumerable <Widget> widgets, Flags toPopulate)
        {
            Log("Populate", widgets.GetIdenties(), toPopulate);

            // Implement breadth first loading of related entities.
            // Any entity that has been requested to be loaded, should be loaded at this level where possible.
            // Remove all sub entity types that this entity relates to directly.
            Flags stillToPopulate = toPopulate;

            stillToPopulate = stillToPopulate.Remove(EntityType.FieldTest);
            stillToPopulate = stillToPopulate.Remove(EntityType.FieldTest);
            stillToPopulate = stillToPopulate.Remove(EntityType.Thing);

            // Get sub entities: FieldTest
            if ((toPopulate & EntityType.FieldTest) == EntityType.FieldTest)
            {
                // Grab the ones that actually need populating
                IEnumerable <Widget> toBePopulated = widgets.Where(entity => entity.FieldTestListUsingForeignKeyFieldPopulated == false);

                // And load the sub entities for those ones.
                FieldTestList childFieldTestList = toBePopulated.Count() > 0
                    ? FieldTestRepo.GetByForeignKeyField(
                    toBePopulated.GetIdenties(),
                    stillToPopulate)
                    : new FieldTestList();
                Dictionary <int, List <FieldTest> > fieldTestListByForeignKeyField = childFieldTestList.MapByForeignKeyField;

                // Now go over all the entites. For ones that need popualting, populate collection
                // directly. For those already populated, make a check on sub entities to ensure
                // they are loaded to the required level
                FieldTestList toBeChecked = new FieldTestList();
                foreach (Widget widget in widgets)
                {
                    if (!widget.FieldTestListUsingForeignKeyFieldPopulated)
                    {
                        var FieldTestListsForWidget = fieldTestListByForeignKeyField.ContainsKey(widget.Identity)
                                                        ? fieldTestListByForeignKeyField[widget.Identity]
                                                        : null;
                        if (FieldTestListsForWidget != null)
                        {
                            FieldTestListsForWidget.ForEach(entity => entity.ForeignKeyFieldWidget = widget);
                        }
                        widget.PopulateFieldTestListUsingForeignKeyField(FieldTestListsForWidget);
                    }
                    else
                    {
                        toBeChecked.AddRange(widget.FieldTestListUsingForeignKeyField);
                    }
                }

                // If there's any "to be checked" (because they were already loaded) let the entities own
                // repo do whatever checks it needs to do
                if (toBeChecked.Count > 0)
                {
                    FieldTestRepo.Populate(toBeChecked, stillToPopulate);
                }
            }

            // Get sub entities: FieldTest
            if ((toPopulate & EntityType.FieldTest) == EntityType.FieldTest)
            {
                // Grab the ones that actually need populating
                IEnumerable <Widget> toBePopulated = widgets.Where(entity => entity.FieldTestListUsingForeignKeyFieldNullablePopulated == false);

                // And load the sub entities for those ones.
                FieldTestList childFieldTestList = toBePopulated.Count() > 0
                    ? FieldTestRepo.GetByForeignKeyFieldNullable(
                    toBePopulated.GetIdenties().Select(i => new Nullable <int>(i)).ToArray(),
                    stillToPopulate)
                    : new FieldTestList();
                Dictionary <int?, List <FieldTest> > fieldTestListByForeignKeyFieldNullable = childFieldTestList.MapByForeignKeyFieldNullable;

                // Now go over all the entites. For ones that need popualting, populate collection
                // directly. For those already populated, make a check on sub entities to ensure
                // they are loaded to the required level
                FieldTestList toBeChecked = new FieldTestList();
                foreach (Widget widget in widgets)
                {
                    if (!widget.FieldTestListUsingForeignKeyFieldNullablePopulated)
                    {
                        var FieldTestListsForWidget = fieldTestListByForeignKeyFieldNullable.ContainsKey(widget.Identity)
                                                        ? fieldTestListByForeignKeyFieldNullable[widget.Identity]
                                                        : null;
                        if (FieldTestListsForWidget != null)
                        {
                            FieldTestListsForWidget.ForEach(entity => entity.ForeignKeyFieldNullableWidget = widget);
                        }
                        widget.PopulateFieldTestListUsingForeignKeyFieldNullable(FieldTestListsForWidget);
                    }
                    else
                    {
                        toBeChecked.AddRange(widget.FieldTestListUsingForeignKeyFieldNullable);
                    }
                }

                // If there's any "to be checked" (because they were already loaded) let the entities own
                // repo do whatever checks it needs to do
                if (toBeChecked.Count > 0)
                {
                    FieldTestRepo.Populate(toBeChecked, stillToPopulate);
                }
            }

            // Get parent entities: Thing
            if ((toPopulate & EntityType.Thing) == EntityType.Thing)
            {
                // Grab the ids for the ones that actually need populating
                IEnumerable <Widget> toBePopulated = widgets.Where(entity => entity.ThingRequiresPopulation);
                int[] idsToLoad = toBePopulated.Select(entity => entity.ThingId).ToList().ToArray();

                // And load the sub entities for those ones.
                ThingList parentThingList = toBePopulated.Count() > 0
                    ? ThingRepo.Get(idsToLoad, stillToPopulate)
                    : new ThingList();
                Dictionary <int, Thing> thingListById = parentThingList.MapById;

                // Now go over all the entites. For ones that need popualting, populate entities
                // directly. For those already populated, make a check on sub entities to ensure
                // they are loaded to the required level
                ThingList toBeChecked = new ThingList();
                foreach (Widget widget in widgets)
                {
                    if (widget.ThingRequiresPopulation)
                    {
                        widget.Thing =
                            thingListById.ContainsKey(widget.ThingId)
                                                        ? thingListById[widget.ThingId]
                                                        : null;
                    }
                    else if (widget.ThingPopulated)
                    {
                        toBeChecked.Add(widget.Thing);
                    }
                }

                // If there's any "to be checked" (because they were already loaded) let the entiies own
                // repo do whatever checks it needs to do
                if (toBeChecked.Count > 0)
                {
                    ThingRepo.Populate(toBeChecked, stillToPopulate);
                }
            }
        }
Example #48
0
 private void RemoveUnchangedItemsWorker()
 {
     Application.DoEvents();
     this.LeftItemsShown = new ThingList<Item>();
     this.RightItemsShown = new ThingList<Item>();
     for (int i = 0; i < this.LeftItems.Count && i < this.RightItems.Count; ++i)
     {
         Item LI = this.LeftItems[i];
         Item RI = this.RightItems[i];
         bool DifferenceSeen = false;
         if (LI == null)
         {
             DifferenceSeen = !(RI == null || RI.GetFieldText("name") == String.Empty || RI.GetFieldText("name") == ".");
         }
         else if (RI == null)
         {
             DifferenceSeen = !(LI == null || LI.GetFieldText("name") == String.Empty || LI.GetFieldText("name") == ".");
         }
         else if (this.GetIconString(LI) != this.GetIconString(RI))
         {
             DifferenceSeen = true;
         }
         else
         {
             foreach (string Field in Item.AllFields)
             {
                 if (!this.ieLeft.IsFieldShown(Field)) // If we can't see the difference, there's no point
                 {
                     continue;
                 }
                 if (LI.GetFieldText(Field) != RI.GetFieldText(Field))
                 {
                     DifferenceSeen = true;
                     break;
                 }
             }
         }
         if (DifferenceSeen)
         {
             this.LeftItemsShown.Add(LI);
             this.RightItemsShown.Add(RI);
         }
         Application.DoEvents();
     }
     // All non-dummy overflow items are "changed"
     if (this.LeftItems.Count < this.RightItems.Count)
     {
         int OverflowPos = this.LeftItems.Count;
         while (OverflowPos < this.RightItems.Count)
         {
             Item I = this.RightItems[OverflowPos++];
             if (I == null || I.GetFieldText("name") == String.Empty || I.GetFieldText("name") == ".")
             {
                 continue;
             }
             this.RightItemsShown.Add(I);
         }
     }
     else if (this.LeftItems.Count > this.RightItems.Count)
     {
         int OverflowPos = this.RightItems.Count;
         while (OverflowPos < this.LeftItems.Count)
         {
             Item I = this.LeftItems[OverflowPos++];
             if (I == null || I.GetFieldText("name") == String.Empty || I.GetFieldText("name") == ".")
             {
                 continue;
             }
             this.LeftItemsShown.Add(I);
         }
     }
     this.CurrentItem = ((this.LeftItemsShown.Count == 0) ? -1 : 0);
     this.PWD.Invoke(new AnonymousMethod(delegate() { this.PWD.Close(); }));
 }
Example #49
0
 private static void DoFullFileScan(string FFXIFolder, string OutputFolder)
 {
     Directory.SetCurrentDirectory(FFXIFolder);
     for (int i = 1; i < 20; ++i)
     {
         string ROMFolder = "Rom";
         if (i > 1)
         {
             ROMFolder += i.ToString();
         }
         if (Directory.Exists(ROMFolder))
         {
             for (int j = 0; j < 1000; ++j)
             {
                 string ROMSubFolder = Path.Combine(ROMFolder, j.ToString());
                 if (Directory.Exists(ROMSubFolder))
                 {
                     Console.WriteLine(I18N.GetText("Scanning"), ROMSubFolder);
                     long Files      = 0;
                     long KnownFiles = 0;
                     for (int k = 0; k < 128; ++k)
                     {
                         string ROMFile = Path.Combine(ROMSubFolder, String.Format("{0}.DAT", k));
                         if (File.Exists(ROMFile))
                         {
                             try
                             {
                                 ThingList KnownData = FileType.LoadAll(ROMFile, null);
                                 if (KnownData != null && KnownData.Count > 0)
                                 {
                                     Console.WriteLine(I18N.GetText("ExtractingAll"), KnownData.Count, ROMFile);
                                     ++KnownFiles;
                                     ThingList <Graphic> Images    = new ThingList <Graphic>();
                                     ThingList           NonImages = new ThingList();
                                     foreach (IThing T in KnownData)
                                     {
                                         if (T is Graphic)
                                         {
                                             Images.Add(T as Graphic);
                                         }
                                         else
                                         {
                                             NonImages.Add(T);
                                         }
                                     }
                                     KnownData.Clear();
                                     if (Images.Count == 1)
                                     {
                                         Image I = Images[0].GetFieldValue("image") as Image;
                                         if (I != null)
                                         {
                                             string Category  = Images[0].GetFieldText("category");
                                             string ID        = Images[0].GetFieldText("id");
                                             string ImageFile = String.Format("{0}-{1}-{2} - ({3}) {4}.png", i, j, k,
                                                                              Category, ID);
                                             I.Save(Path.Combine(OutputFolder, ImageFile), ImageFormat.Png);
                                         }
                                     }
                                     else if (Images.Count > 0)
                                     {
                                         string ImageFolder = Path.Combine(OutputFolder,
                                                                           String.Format("{0}-{1}-{2}", i, j, k));
                                         int ImageIndex = 0;
                                         foreach (Graphic G in Images)
                                         {
                                             Image I = G.GetFieldValue("image") as Image;
                                             if (I != null)
                                             {
                                                 if (!Directory.Exists(ImageFolder))
                                                 {
                                                     Directory.CreateDirectory(ImageFolder);
                                                 }
                                                 string Category  = G.GetFieldText("category");
                                                 string ID        = G.GetFieldText("id");
                                                 string ImageFile = String.Format("{0} - ({1}) {2}.png", ++ImageIndex,
                                                                                  Category, ID);
                                                 I.Save(Path.Combine(ImageFolder, ImageFile), ImageFormat.Png);
                                             }
                                         }
                                     }
                                     Images.Clear();
                                     if (NonImages.Count > 0)
                                     {
                                         NonImages.Save(Path.Combine(OutputFolder, String.Format("{0}-{1}-{2}.xml", i, j, k)));
                                     }
                                     NonImages.Clear();
                                 }
                                 ++Files;
                             }
                             catch (Exception E)
                             {
                                 Console.ForegroundColor = ConsoleColor.Red;
                                 Console.WriteLine(I18N.GetText("Exception"), E.Message);
                                 Console.ForegroundColor = ConsoleColor.White;
                             }
                         }
                     }
                     Console.WriteLine(" => {0} of {1} file(s) contained recogniseable data", KnownFiles, Files);
                 }
             }
         }
     }
 }
 public static void Populate(ThingList thingList, Flags toPopulate)
 {
     _instance.Populate(thingList, toPopulate);
 }
Example #51
0
 public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
 {
     ThingList TL = new ThingList();
     if (ProgressCallback != null)
     {
         ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
     }
     if (BR.BaseStream.Position != 0)
     {
         goto Failed;
     }
     if (Encoding.ASCII.GetString(BR.ReadBytes(4)) != "menu")
     {
         goto Failed;
     }
     if (BR.ReadInt32() != 0x101)
     {
         goto Failed;
     }
     if (BR.ReadInt64() != 0)
     {
         goto Failed;
     }
     if (BR.ReadInt64() != 0)
     {
         goto Failed;
     }
     if (BR.ReadInt64() != 0)
     {
         goto Failed;
     }
     if (ProgressCallback != null)
     {
         ProgressCallback(I18N.GetText("FTM:LoadingData"), (double)BR.BaseStream.Position / BR.BaseStream.Length);
     }
     string firstFourBytes = Encoding.ASCII.GetString(BR.ReadBytes(4));
     {
         // Part 0: Monster?
         if (firstFourBytes != "mon_")
         {
             goto Part1;
         }
         uint SizeInfo = BR.ReadUInt32();
         if (BR.ReadInt64() != 0)
         {
             goto Failed;
         }
         uint BlockSize = (SizeInfo & 0xFFFFFF80) >> 3;
         if ((BlockSize - 0x10) % 0x58 != 0)
         {
             goto Failed;
         }
         uint EntryCount = (BlockSize - 0x10) / 0x58;
         while (EntryCount-- > 0)
         {
             Things.MonsterSpellInfo2 MSI2 = new Things.MonsterSpellInfo2();
             if (!MSI2.Read(BR))
             {
                 goto Failed;
             }
             if (ProgressCallback != null)
             {
                 ProgressCallback(null, (double)BR.BaseStream.Position / BR.BaseStream.Length);
             }
             TL.Add(MSI2);
         }
     }
     firstFourBytes = Encoding.ASCII.GetString(BR.ReadBytes(4));
     Part1:
     {
         // Part 1: Spell Info
         if (firstFourBytes != "mgc_")
         {
             goto Failed;
         }
         uint SizeInfo = BR.ReadUInt32();
         if (BR.ReadInt64() != 0)
         {
             goto Failed;
         }
         uint BlockSize = (SizeInfo & 0xFFFFFF80) >> 3;
         if ((BlockSize - 0x10) % 0x58 != 0)
         {
             goto Failed;
         }
         uint EntryCount = (BlockSize - 0x10) / 0x58;
         while (EntryCount-- > 0)
         {
             Things.SpellInfo2 SI2 = new Things.SpellInfo2();
             if (!SI2.Read(BR))
             {
                 goto Failed;
             }
             if (ProgressCallback != null)
             {
                 ProgressCallback(null, (double)BR.BaseStream.Position / BR.BaseStream.Length);
             }
             TL.Add(SI2);
         }
     }
     {
         // Part 2: Ability Info
         if (Encoding.ASCII.GetString(BR.ReadBytes(4)) != "comm")
         {
             goto Failed;
         }
         uint SizeInfo = BR.ReadUInt32();
         if (BR.ReadInt64() != 0)
         {
             goto Failed;
         }
         uint BlockSize = (SizeInfo & 0xFFFFFF80) >> 3;
         if ((BlockSize - 0x10) % 0x30 != 0)
         {
             goto Failed;
         }
         uint EntryCount = (BlockSize - 0x10) / 0x30;
         while (EntryCount-- > 0)
         {
             Things.AbilityInfo2 AI2 = new Things.AbilityInfo2();
             if (!AI2.Read(BR))
             {
                 goto Failed;
             }
             if (ProgressCallback != null)
             {
                 ProgressCallback(null, (double)BR.BaseStream.Position / BR.BaseStream.Length);
             }
             TL.Add(AI2);
         }
     }
     {
         // Part 3: End Marker
         if (Encoding.ASCII.GetString(BR.ReadBytes(4)) != "end\0")
         {
             goto Failed;
         }
         uint SizeInfo = BR.ReadUInt32();
         if (BR.ReadInt64() != 0)
         {
             goto Failed;
         }
         uint BlockSize = (SizeInfo & 0xFFFFFF80) >> 3;
         if (BlockSize != 0x10) // Header only
         {
             goto Failed;
         }
         if (ProgressCallback != null)
         {
             ProgressCallback(null, (double)BR.BaseStream.Position / BR.BaseStream.Length);
         }
     }
     goto Done;
     Failed:
     TL.Clear();
     Done:
     return TL;
 }
 public static void Save(Flags toSave, ThingList thingList)
 {
     _instance.Save(toSave, thingList);
 }
        public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
        {
            ThingList TL = new ThingList();

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
            }
            if (BR.BaseStream.Length < 0x38 || BR.BaseStream.Position != 0)
            {
                return(TL);
            }
            FFXIEncoding E = new FFXIEncoding();

            // Skip (presumably) fixed portion of the header
            if ((E.GetString(BR.ReadBytes(8)) != "d_msg".PadRight(8, '\0')) || BR.ReadUInt16() != 1 || BR.ReadUInt32() != 0 || BR.ReadUInt16() != 2 || BR.ReadUInt32() != 3)
            {
                return(TL);
            }
            // Read the useful header fields
            uint EntryCount = BR.ReadUInt32();

            if (BR.ReadUInt32() != 1)
            {
                return(TL);
            }
            uint FileSize = BR.ReadUInt32();

            if (FileSize != BR.BaseStream.Length)
            {
                return(TL);
            }
            uint HeaderSize = BR.ReadUInt32();

            if (HeaderSize != 0x38)
            {
                return(TL);
            }
            uint EntryBytes = BR.ReadUInt32();

            if (EntryBytes != EntryCount * 36)
            {
                return(TL);
            }
            uint DataBytes = BR.ReadUInt32();

            if (FileSize != 0x38 + EntryBytes + DataBytes)
            {
                return(TL);
            }
            // 12 NUL bytes
            if (BR.ReadUInt32() != 0 || BR.ReadUInt32() != 0 || BR.ReadUInt32() != 0)
            {
                return(TL);
            }
            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
            }
            for (uint i = 0; i < EntryCount; ++i)
            {
                Things.DMSGStringTableEntry DSTE = new Things.DMSGStringTableEntry();
                if (!DSTE.Read(BR, E, i, EntryBytes, DataBytes))
                {
                    TL.Clear();
                    break;
                }
                if (ProgressCallback != null)
                {
                    ProgressCallback(null, (double)(i + 1) / EntryCount);
                }
                TL.Add(DSTE);
            }
            return(TL);
        }
Example #54
0
 private static void DoFullFileScan(string FFXIFolder, string OutputFolder)
 {
     Directory.SetCurrentDirectory(FFXIFolder);
     for (int i = 1; i < 20; ++i)
     {
         string ROMFolder = "Rom";
         if (i > 1)
         {
             ROMFolder += i.ToString();
         }
         if (Directory.Exists(ROMFolder))
         {
             for (int j = 0; j < 1000; ++j)
             {
                 string ROMSubFolder = Path.Combine(ROMFolder, j.ToString());
                 if (Directory.Exists(ROMSubFolder))
                 {
                     Console.WriteLine(I18N.GetText("Scanning"), ROMSubFolder);
                     long Files = 0;
                     long KnownFiles = 0;
                     for (int k = 0; k < 128; ++k)
                     {
                         string ROMFile = Path.Combine(ROMSubFolder, String.Format("{0}.DAT", k));
                         if (File.Exists(ROMFile))
                         {
                             try
                             {
                                 ThingList KnownData = FileType.LoadAll(ROMFile, null);
                                 if (KnownData != null && KnownData.Count > 0)
                                 {
                                     Console.WriteLine(I18N.GetText("ExtractingAll"), KnownData.Count, ROMFile);
                                     ++KnownFiles;
                                     ThingList<Graphic> Images = new ThingList<Graphic>();
                                     ThingList NonImages = new ThingList();
                                     foreach (IThing T in KnownData)
                                     {
                                         if (T is Graphic)
                                         {
                                             Images.Add(T as Graphic);
                                         }
                                         else
                                         {
                                             NonImages.Add(T);
                                         }
                                     }
                                     KnownData.Clear();
                                     if (Images.Count == 1)
                                     {
                                         Image I = Images[0].GetFieldValue("image") as Image;
                                         if (I != null)
                                         {
                                             string Category = Images[0].GetFieldText("category");
                                             string ID = Images[0].GetFieldText("id");
                                             string ImageFile = String.Format("{0}-{1}-{2} - ({3}) {4}.png", i, j, k,
                                                 Category, ID);
                                             I.Save(Path.Combine(OutputFolder, ImageFile), ImageFormat.Png);
                                         }
                                     }
                                     else if (Images.Count > 0)
                                     {
                                         string ImageFolder = Path.Combine(OutputFolder,
                                             String.Format("{0}-{1}-{2}", i, j, k));
                                         int ImageIndex = 0;
                                         foreach (Graphic G in Images)
                                         {
                                             Image I = G.GetFieldValue("image") as Image;
                                             if (I != null)
                                             {
                                                 if (!Directory.Exists(ImageFolder))
                                                 {
                                                     Directory.CreateDirectory(ImageFolder);
                                                 }
                                                 string Category = G.GetFieldText("category");
                                                 string ID = G.GetFieldText("id");
                                                 string ImageFile = String.Format("{0} - ({1}) {2}.png", ++ImageIndex,
                                                     Category, ID);
                                                 I.Save(Path.Combine(ImageFolder, ImageFile), ImageFormat.Png);
                                             }
                                         }
                                     }
                                     Images.Clear();
                                     if (NonImages.Count > 0)
                                     {
                                         NonImages.Save(Path.Combine(OutputFolder, String.Format("{0}-{1}-{2}.xml", i, j, k)));
                                     }
                                     NonImages.Clear();
                                 }
                                 ++Files;
                             }
                             catch (Exception E)
                             {
                                 Console.ForegroundColor = ConsoleColor.Red;
                                 Console.WriteLine(I18N.GetText("Exception"), E.Message);
                                 Console.ForegroundColor = ConsoleColor.White;
                             }
                         }
                     }
                     Console.WriteLine(" => {0} of {1} file(s) contained recogniseable data", KnownFiles, Files);
                 }
             }
         }
     }
 }
Example #55
0
        public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback)
        {
            ThingList TL = new ThingList();

            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0);
            }
            if (BR.BaseStream.Length < 0x38 || BR.BaseStream.Position != 0)
            {
                return(TL);
            }
            FFXIEncoding E = new FFXIEncoding();

            // Read past the marker (32 bytes)
            if ((E.GetString(BR.ReadBytes(10)) != "XISTRING".PadRight(10, '\0')) || BR.ReadUInt16() != 2)
            {
                return(TL);
            }
            foreach (byte B in BR.ReadBytes(20))
            {
                if (B != 0)
                {
                    return(TL);
                }
            }
            // Read The Header
            uint FileSize = BR.ReadUInt32();

            if (FileSize != BR.BaseStream.Length)
            {
                return(TL);
            }
            uint EntryCount = BR.ReadUInt32();
            uint EntryBytes = BR.ReadUInt32();
            uint DataBytes  = BR.ReadUInt32();

            BR.ReadUInt32(); // Unknown
            BR.ReadUInt32(); // Unknown
            if (EntryBytes != EntryCount * 12 || FileSize != 0x38 + EntryBytes + DataBytes)
            {
                return(TL);
            }
            if (ProgressCallback != null)
            {
                ProgressCallback(I18N.GetText("FTM:LoadingData"), 0);
            }
            for (uint i = 0; i < EntryCount; ++i)
            {
                Things.XIStringTableEntry XSTE = new Things.XIStringTableEntry();
                if (!XSTE.Read(BR, E, i, EntryBytes, DataBytes))
                {
                    TL.Clear();
                    break;
                }
                if (ProgressCallback != null)
                {
                    ProgressCallback(null, (double)(i + 1) / EntryCount);
                }
                TL.Add(XSTE);
            }
            return(TL);
        }