Inheritance: IComparable
Beispiel #1
0
        public static int Execute( List<string> args )
        {
            if ( args.Count != 4 ) {
                Console.WriteLine( "Usage: LuxPainEvt_GraceNote event.evt NewDBFile GracesJapanese event.jp.evt" );
                return -1;
            }
            String Filename = args[0];
            String NewDB = args[1];
            String GracesDB = args[2];
            String JapaneseFilename = args[3];

            LuxPainEvt Evt;
            LuxPainEvt EvtJp;
            try {
                Evt = new LuxPainEvt( Filename );
                EvtJp = new LuxPainEvt( JapaneseFilename );
            } catch ( Exception ex ) {
                Console.WriteLine( ex.Message );
                Console.WriteLine( "Failed loading text file!" );
                return -1;
            }
            Evt.FormatTextForEditing();
            EvtJp.FormatTextForEditing();

            if ( Evt.TextEntries.Count != EvtJp.TextEntries.Count ) {
                Console.WriteLine( "Entry count over languages doesn't match, padding..." );

                while ( Evt.TextEntries.Count < EvtJp.TextEntries.Count ) {
                    LuxPainEvtText t = new LuxPainEvtText();
                    t.OffsetLocation = 0x7FFFFFFF;
                    t.Text = "[Entry does not exist in this language, this is just for completion's sake.]";
                    Evt.TextEntries.Add( t );
                }

                while ( Evt.TextEntries.Count > EvtJp.TextEntries.Count ) {
                    LuxPainEvtText t = new LuxPainEvtText();
                    t.OffsetLocation = 0x7FFFFFFF;
                    t.Text = "[Entry does not exist in this language, this is just for completion's sake.]";
                    EvtJp.TextEntries.Add( t );
                }

                if ( Evt.TextEntries.Count != EvtJp.TextEntries.Count ) { throw new Exception( "this shouldn't happen!" ); }
            }

            Console.WriteLine( "Found " + Evt.TextEntries.Count + " entries, importing..." );
            System.IO.File.WriteAllBytes( NewDB, Properties.Resources.gndb_template );

            List<GraceNoteDatabaseEntry> Entries = new List<GraceNoteDatabaseEntry>( Evt.TextEntries.Count );
            for ( int i = 0; i < Evt.TextEntries.Count; ++i ) {
                // fetch GracesJapanese ID or generate new & insert new text
                String EnPlusJp = Evt.TextEntries[i].Text + "\n\n" + EvtJp.TextEntries[i].Text;
                GraceNoteDatabaseEntry gn =
                    new GraceNoteDatabaseEntry( EnPlusJp, Evt.TextEntries[i].Text, "", 0, (int)Evt.TextEntries[i].OffsetLocation, "", 0 );
                Entries.Add( gn );
            }
            GraceNoteDatabaseEntry.InsertSQL( Entries.ToArray(), "Data Source=" + NewDB, "Data Source=" + GracesDB );
            Console.WriteLine( "Successfully imported entries!" );

            return 0;
        }
        public void GetSQL(String ConnectionString)
        {
            SQLiteConnection Connection = new SQLiteConnection(ConnectionString);

            Connection.Open();

            List <LuxPainEvtText> OriginalTextEntries = TextEntries;

            TextEntries = new List <LuxPainEvtText>();

            using (SQLiteTransaction Transaction = Connection.BeginTransaction())
                using (SQLiteCommand Command = new SQLiteCommand(Connection)) {
                    Command.CommandText = "SELECT english, PointerRef FROM Text WHERE PointerRef != 2147483647 ORDER BY ID";
                    SQLiteDataReader r = Command.ExecuteReader();
                    while (r.Read())
                    {
                        String SQLText;

                        try {
                            SQLText = r.GetString(0).Replace("''", "'");
                        } catch (System.InvalidCastException) {
                            SQLText = "";
                        }

                        int PointerRef = r.GetInt32(1);


                        LuxPainEvtText e = new LuxPainEvtText();
                        e.OffsetLocation = (uint)PointerRef;
                        e.Text           = SQLText;
                        TextEntries.Add(e);
                    }

                    Transaction.Rollback();
                }

            if (OriginalTextEntries.Count != TextEntries.Count)
            {
                throw new Exception("Entry count mismatch when reading from database!");
            }

            for (int i = 0; i < OriginalTextEntries.Count; ++i)
            {
                TextEntries[i].Offset = OriginalTextEntries[i].Offset;
            }

            return;
        }
        public void GetSQL( String ConnectionString )
        {
            SQLiteConnection Connection = new SQLiteConnection( ConnectionString );
            Connection.Open();

            List<LuxPainEvtText> OriginalTextEntries = TextEntries;
            TextEntries = new List<LuxPainEvtText>();

            using ( SQLiteTransaction Transaction = Connection.BeginTransaction() )
            using ( SQLiteCommand Command = new SQLiteCommand( Connection ) ) {
                Command.CommandText = "SELECT english, PointerRef FROM Text WHERE PointerRef != 2147483647 ORDER BY ID";
                SQLiteDataReader r = Command.ExecuteReader();
                while ( r.Read() ) {
                    String SQLText;

                    try {
                        SQLText = r.GetString( 0 ).Replace( "''", "'" );
                    } catch ( System.InvalidCastException ) {
                        SQLText = "";
                    }

                    int PointerRef = r.GetInt32( 1 );

                    LuxPainEvtText e = new LuxPainEvtText();
                    e.OffsetLocation = (uint)PointerRef;
                    e.Text = SQLText;
                    TextEntries.Add( e );
                }

                Transaction.Rollback();
            }

            if ( OriginalTextEntries.Count != TextEntries.Count ) {
                throw new Exception( "Entry count mismatch when reading from database!" );
            }

            for ( int i = 0; i < OriginalTextEntries.Count; ++i ) {
                TextEntries[i].Offset = OriginalTextEntries[i].Offset;
            }

            return;
        }
        private bool LoadFile(byte[] Bytes)
        {
            originalFile = Bytes;

            Header       = new LuxPainEvtHeader();
            Header.Magic = BitConverter.ToUInt32(Bytes, 0x00);
            if (Header.Magic != 0x31304353)
            {
                return(false);
            }
            Header.Unknown1            = BitConverter.ToUInt32(Bytes, 0x04);
            Header.Unknown2            = BitConverter.ToUInt32(Bytes, 0x08);
            Header.Unknown3            = BitConverter.ToUInt32(Bytes, 0x0C);
            Header.TextOffsetsLocation = BitConverter.ToUInt32(Bytes, 0x10);
            Header.TextLocation        = BitConverter.ToUInt32(Bytes, 0x14);

            UInt32 PredictedTextAmount = (Header.TextLocation - Header.TextOffsetsLocation) / 2;

            TextEntries = new List <LuxPainEvtText>((int)PredictedTextAmount);

            for (UInt32 loc = Header.TextOffsetsLocation; loc < Header.TextLocation; loc += 2)
            {
                LuxPainEvtText txt = new LuxPainEvtText();
                txt.OffsetLocation = loc;
                txt.Offset         = BitConverter.ToUInt16(Bytes, (int)loc);

                txt.Text = LuxPainUtil.GetTextLuxPain((int)(Header.TextLocation + (txt.Offset * 2)), Bytes);

                TextEntries.Add(txt);
            }

            //foreach (LuxPainEvtText t in TextEntries)
            //{
            //    Console.WriteLine(t.Text);
            //}

            return(true);
        }
        private bool LoadFile( byte[] Bytes )
        {
            originalFile = Bytes;

            Header = new LuxPainEvtHeader();
            Header.Magic = BitConverter.ToUInt32( Bytes, 0x00 );
            if ( Header.Magic != 0x31304353 ) return false;
            Header.Unknown1 = BitConverter.ToUInt32( Bytes, 0x04 );
            Header.Unknown2 = BitConverter.ToUInt32( Bytes, 0x08 );
            Header.Unknown3 = BitConverter.ToUInt32( Bytes, 0x0C );
            Header.TextOffsetsLocation = BitConverter.ToUInt32( Bytes, 0x10 );
            Header.TextLocation = BitConverter.ToUInt32( Bytes, 0x14 );

            UInt32 PredictedTextAmount = ( Header.TextLocation - Header.TextOffsetsLocation ) / 2;
            TextEntries = new List<LuxPainEvtText>( (int)PredictedTextAmount );

            for ( UInt32 loc = Header.TextOffsetsLocation; loc < Header.TextLocation; loc += 2 ) {
                LuxPainEvtText txt = new LuxPainEvtText();
                txt.OffsetLocation = loc;
                txt.Offset = BitConverter.ToUInt16( Bytes, (int)loc );

                txt.Text = LuxPainUtil.GetTextLuxPain( (int)( Header.TextLocation + ( txt.Offset * 2 ) ), Bytes );

                TextEntries.Add( txt );
            }

            //foreach (LuxPainEvtText t in TextEntries)
            //{
            //    Console.WriteLine(t.Text);
            //}

            return true;
        }