Cainiao learns ogre and tianlong Babu 18: Get the archive file list

Source: Internet
Author: User

To obtain the file list of an archive file, you can call the list () function to obtain the file list as long as you get the archive pointer.

 

But how to obtain the archive pointer? First, let's look at the resource loading process:

 

First, obtain the resource path, resource group, and resource file type from the resources. cfg file. The three data types are as follows:

Configfile CF;
Cf. Load ("resources. cfg ");

 

Then pass the three data into the resource locating function:

Resourcegroupmanager: getsingleton (). addresourcelocation (archname, typename, secname );

Find out the source code for how to locate the resource:

Void resourcegroupmanager: addresourcelocation (const string & name, <br/> const string & loctype, const string & resgroup, bool recursive) <br/>{ <br/> resourcegroup * GRP = getresourcegroup (resgroup); <br/> If (! GRP) <br/>{< br/> createresourcegroup (resgroup); <br/> GRP = getresourcegroup (resgroup ); <br/>}</P> <p> ogre_lock_mutex (GRP-> ogre_auto_mutex_name) // lock group mutex </P> <p> // get archive <br/> archive * parch = archivemanager: getsingleton (). load (name, loctype); <br/> // Add to location list <br/> resourcelocation * loc = new resourcelocation (); <br/> loc-> archive = parch; <br/> loc-> recursive = rec Ursive; <br/> GRP-> locationlist. push_back (LOC); <br/> // index resources <br/> stringvectorptr VEC = parch-> Find ("*", recursive); <br/> for (stringvector:: iterator it = Vec-> begin (); it! = Vec-> end (); ++ it) <br/>{< br/> // index under full name, case Sensitive <br/> GRP-> resourceindexcasesensitive [(* It)] = parch; <br/> If (! Parch-> iscasesensitive () <br/> {<br/> // index under lower case name too for case insensitive match <br/> string indexname = (* it ); <br/> stringutil: tolowercase (indexname); <br/> GRP-> resourceindexcaseinsensitive [indexname] = parch; <br/>}</P> <p> stringutil: strstreamtype MSG; <br/> MSG <"added resource location'" <name <"'of type'" <loctype <br/> <"' to resource group '" <resgroup <"'"; <br/> If (recursive) <br/> MSG <"with recursive option"; <br/> logmanager: getsingleton (). logmessage (MSG. STR (); </P> <p>}

 

We can see that

// Get Archive
Archive * parch = archivemanager: getsingleton (). Load (name, loctype );

Here, the file pointer is returned when the file is loaded. This is what we need. Next, he transfers the pointer to two places.

// Add to location list
Resourcelocation * loc = new resourcelocation ();
Loc-> archive = parch; // input once here

 

// Index under full name, case sensitive
GRP-> resourceindexcasesensitive [(* It)] = parch; // re-input here

 

In theory, we can get pointers from these two data structures, but unfortunately, these are all protected members and cannot be obtained.

This class does not provide related functions. What should I do? Is it necessary to change the Ogre source code?

 

Look at the previous function.

// Get Archive
Archive * parch = archivemanager: getsingleton (). Load (name, loctype );

If it has been loaded once, we will load it again. What will happen?

Archive * archivemanager: load (const string & filename, const string & archivetype) <br/>{< br/> archivemap: iterator I = marchives. find (filename); <br/> archive * parch = 0; </P> <p> if (I = marchives. end () <br/>{< br/> // search factories <br/> archivefactorymap: iterator it = marchfactories. find (archivetype); <br/> If (IT = marchfactories. end () <br/> // factory not found <br/> ogre_0000t (exception: err_item_not_found, "cannot find an archive factory" <br/> "to deal with archive of type" + archivetype, "archivemanager: Load "); </P> <p> parch = it-> second-> createinstance (filename); <br/> parch-> load (); <br/> marchives [filename] = parch; </P> <p >}< br/> else <br/>{< br/> parch = I-> second; <br/>}< br/> return parch; <br/>}

 

After reading the source code, I suddenly got started !!!

When loading the file, he will first check whether the file resource has been loaded. If it has already been loaded, he will directly return the pointer to this file resource !!!

 

So we can get the pointer to this resource after loading it again:

// Obtain the map list file <br/> tlbbarchive * arch = (tlbbarchive *) archivemanager: getsingleton (). load (".. /.. /data/scene. AXP "," axppack "); <br/> mmaplistptr = arch-> List ();

 

At this point, you have obtained the list file information,

Open it in the MFC dialog box:

Bool copenmapdlg: oninitdialog () <br/>{< br/> cdialog: oninitdialog (); </P> <p> // obtain the map list <br/> clistbox * plistbox = (clistbox *) getdlgitem (idc_list1 ); </P> <p> ctlbbview * view = (ctlbbview *) (cmainframe *) afxgetmainwnd ()-> getactiveview (); // obtain the View class <br/> stringvectorptr svptr = view-> getogreapp ()-> getmaplistptr (); </P> <p> vector <string> :: iterator iter = svptr-> begin (); <br/> for (; iter! = Svptr-> end (); ++ ITER) <br/>{< br/> string STR = * ITER; <br/> If (stringutil: endswith (STR, ". scene ", false) <br/>{< br/> plistbox-> addstring (Str. c_str (); <br/>}</P> <p> return true; <br/>}

 

Final effect:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.