AlbedoDatabaseGenerator.Database.Load C# (CSharp) Метод

Load() публичный Метод

public Load ( FileInfo _FileName ) : void
_FileName System.IO.FileInfo
Результат void
        public void Load( FileInfo _FileName )
        {
            XmlDocument	Doc = new XmlDocument();
            Doc.Load( _FileName.FullName );

            XmlElement	Root = Doc["TexturesDatabase"];
            if ( Root == null )
                throw new Exception( "Failed to retrieve the root \"TextureDatabase\" element! Not a valid database file?" );

            string	Location = Root.GetAttribute( "Location" );
            if ( Location == "" )
                throw new Exception( "Failed to retrieve the location path for the database!" );

            int	EntriesCount = 0;
            if ( !int.TryParse( Root.GetAttribute( "EntriesCount" ), out EntriesCount ) )
                throw new Exception( "Failed to parse amount of entries in the database!" );

            m_Errors = "";

            foreach ( Entry E in m_Entries )
                E.Dispose();
            m_Entries.Clear();
            for ( int EntryIndex=0; EntryIndex < EntriesCount; EntryIndex++ )
            {
                try
                {
                    XmlElement	EntryElement = Root.ChildNodes[EntryIndex] as XmlElement;
                    Entry	E = new Entry( this );
                    E.Load( this, EntryElement );
                    m_Entries.Add( E );
                }
                catch ( Exception _e )
                {
                    m_Errors += "An error occurred while loading database entry #" + EntryIndex + ": " + _e.Message;
                }
            }

            // Reconnect manifests found from the specified location
            RootPath = new DirectoryInfo( Location );
        }

Usage Example

Пример #1
0
        private void buttonLoadDatabase_Click( object sender, EventArgs e )
        {
            if ( m_Database != null && m_Database.Entries.Length > 0 )
            {	// Caution!
                if ( MessageBox( "Loading a new database will lose existing database data, do you wish to continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning ) != DialogResult.Yes )
                    return;
            }

            string	OldFileName = GetRegKey( "DatabaseFileName", Path.Combine( m_ApplicationPath, "Database.rdb" ) );
            openFileDialogDatabase.InitialDirectory = Path.GetFullPath( OldFileName );
            openFileDialogDatabase.FileName = Path.GetFileName( OldFileName );
            if ( openFileDialogDatabase.ShowDialog( this ) != DialogResult.OK )
                return;

            SetRegKey( "DatabaseFileName", openFileDialogDatabase.FileName );

            try
            {
                Database	D = new Database();
                try
                {
                    D.Load( new FileInfo( openFileDialogDatabase.FileName ) );
                }
                catch ( Database.InvalidDatabaseRootPathException _e )
                {
                    MessageBox( "The database could not be opened completely as it did not manage to reconnect manifest files on disk based on its embedded location path.\nConsider changing the root folder location to a valid path.\n\nError: " + _e.Message, MessageBoxButtons.OK, MessageBoxIcon.Warning );
                }

                if ( m_Database != null )
                    m_Database.Dispose();

                Database = D;

                // Update UI
                textBoxDatabaseFileName.Text = openFileDialogDatabase.FileName;
                UpdateDatabaseEntries();
            }
            catch ( Exception _e )
            {
                MessageBox( "An error occurred while opening the database:\n\n", _e );
            }
        }