Summary of the invention
In order to solve the problems of the technologies described above, the objective of the invention is: provide a kind of based on Hook technology and the fast file packing method of access speed.
Another object of the present invention is: provide a kind of based on Hook technology and the fast file packaging system of access speed.
The technical solution adopted for the present invention to solve the technical problems is: a kind of file packing method based on the Hook technology comprises:
A, employing Hook technology are gathered the access order of file in wrapping, thereby are obtained the file access sequence list;
The file access sequence list that B, basis obtain is treated the file of packing and is packed, thereby file that will be to be packed is written in the APMB package.
Further, described steps A, it comprises:
A1, empty the file access sequence list;
A2, by the Hook technology, the File Open function is redirected to file sequence collection function in will wrap;
A3, working procedure client trigger the logic that reads of wrapping interior file, thereby the filename of file store in the file access sequence list in will wrapping into;
A4, described file sequence are gathered the interior File Open function of function call bag and are judged whether that file all is read in all bags, if then finish collection, thereby obtain storing the file access sequence list of filename; Otherwise, then re-execute steps A 3.
Further, described step B, it comprises:
B1, file and corresponding file access sequence list that will be to be packed be passed to strapping tool;
B2, described strapping tool read the filename in the file access sequence list;
B3, described strapping tool are inquired about in file to be packed, and check the file that whether has filename identical with the described filename that reads, if having, then read the content of this document, and the content that reads is stored to the end of APMB package, execution in step B4 then, otherwise, direct execution in step B4 then;
B4, judge whether that the All Files name in the file access sequence list all is read, if, execution in step B5 then, otherwise, then re-execute step B2;
B5, the file to be packed of remainder is write the end of APMB package, and generate the index area that is used for file in the visit bag, then the index area that generates is stored to the end of APMB package.
Further, after described step B, also be provided with step C, described step C, it is specially:
APMB package after the packing is upgraded, thereby will need the outer file of bag that increases newly and the interior file of bag that needs upgrade to store in the APMB package, and regenerate the index area of APMB package.
Further, after described step B, also be provided with step D, described step D, it is specially, and treat the APMB package of arrangement according to the file access sequence list that obtains and put in order, thus file and file in wrapping resequenced in the deletion bag that can't have access to.
Further, described step D, it comprises:
D1, finishing tool load APMB package to be put in order and corresponding file access sequence list;
D2, described finishing tool read the filename in the file access sequence list;
D3, described finishing tool are inquired about in APMB package index area to be put in order, check whether file in the filename bag identical with the described filename that reads is arranged, if have, then read the content of this document, and the file content that reads is stored to the end of new APMB package, execution in step D4 then, otherwise, direct execution in step D4 then;
D4, judge whether that the All Files name in the file access sequence list all is read, if, execution in step D5 then, otherwise, then re-execute step D2;
D5, will be to be put in order APMB package in the remaining bag file be stored to the end of new APMB package, and generate the index area that is used for file in the visit bag, then the index area that generates is stored to the end of new APMB package;
D6, deletion APMB package to be put in order also keep the new APMB package after the arrangement.
Further, the filename of a described file file by name or be used for the asterisk wildcard of expression file class.
The present invention solves another technical scheme that its technical matters adopts: a kind of file packaging system based on the Hook technology comprises:
Acquisition module is used for adopting the Hook technology that the access order of file in wrapping is gathered, thereby obtains the file access sequence list;
Packetization module pack for the file for the treatment of packing according to the file access sequence list that obtains, thereby file that will be to be packed is written in the APMB package;
The output terminal of described acquisition module is connected with the input end of packetization module.
Further, described acquisition module comprises:
Empty the unit, be used for emptying the file access sequence list;
Be redirected the unit, be used for by the Hook technology, the File Open function is redirected to file sequence collection function in will wrapping;
The filename record cell is used for the working procedure client, trigger the logic that reads of the interior file of bag, thereby the filename of file stores in the file access sequence list in will wrapping into;
Call and judging unit, be used for described file sequence and gather the interior File Open function of function call bag and judge whether that file all is read in all bags, if then end is gathered, thereby obtain storing the file access sequence list of filename; Otherwise, then go to the filename record cell again;
The described output terminal that empties the unit is successively by being redirected unit and filename record cell and then being connected with calling with the input end of judging unit.
Further, described packetization module comprises:
Uploading unit is passed to strapping tool for file and corresponding file access sequence list that will be to be packed;
The filename reading unit is used for the filename that described strapping tool reads the file access sequence list;
Query unit, being used for described strapping tool inquires about at file to be packed, check the file that whether has filename identical with the described filename that reads, if have, then read the content of this document, and the content that reads is stored to the end of APMB package, go to judging unit then, otherwise, then jump directly to judging unit;
Judging unit is used for judging whether that the All Files name of file access sequence list all is read, if, then go to writing unit, otherwise, then go to the filename reading unit again;
Writing unit is used for the file to be packed of remainder is write the end of APMB package, and generates the index area that is used for file in the visit bag, then the index area that generates is stored to the end of APMB package;
The input end of described uploading unit is connected with the output terminal of acquisition module, and the output terminal of described uploading unit is connected with judging unit and then with the input end of writing unit by filename reading unit, query unit successively.
The beneficial effect of method of the present invention is: method of the present invention is packed according to the file access sequence list of gathering, and the file access sequence list of gathering when move with actual software visit to wrap the order of interior file identical or close, can make two positions of file in APMB package of visit order relation nearer, thereby make hard disc magnetic head read mode travel all over APMB package with approximate order, promoted the access speed of APMB package.Further, method of the present invention also comprises carries out updating steps C to the APMB package after the packing, can upgrade or the outer file of newly-increased bag reasonable more and science according to actual needs to the content of file in wrapping.Further, method of the present invention also comprises the step D that the APMB package for the treatment of arrangement is put in order, can delete the interior file of invalid bag and make the distance of two files in APMB package of visit order relation more approaching, thereby further improve the access speed of APMB package.
The beneficial effect of system of the present invention is: packetization module is packed according to the file access sequence list of acquisition module collection in the system of the present invention, and the file access sequence list of gathering when move with actual software visit to wrap the order of interior file identical or close, can make two positions of file in APMB package of visit order relation nearer, thereby make hard disc magnetic head read mode travel all over APMB package with approximate order, promoted the access speed of APMB package.
Embodiment
With reference to Fig. 1, a kind of file packing method based on the Hook technology of the present invention comprises:
A, employing Hook technology are gathered the access order of file in wrapping, thereby are obtained the file access sequence list;
The file access sequence list that B, basis obtain is treated the file of packing and is packed, thereby file that will be to be packed is written in the APMB package.
Wherein, APMB package is the file bag of packing, having upgraded or put in order, is made up of file in one or more bags.For example, an APMB package G is arranged, comprise among the G that filename is respectively the interior file of these four bags of a, b, c and d, then the file of file e by name is the outer file of bag of G.The file access sequence list is made of tactic filename or relative path, near the access order of actual software to file in wrapping.Read for convenience, can in access file list, increase access sequence number this (in fact, access sequence number be not present in the file access sequence list) usually.For example, software reads and will read the file that file b.tga file by name and file are called c.ani behind the file of file a.mesh by name again, and the access sequence that then obtains is listed as follows shown in the table 1:
Table 1
Access sequence number |
Filename |
1 |
a.mesh |
2 |
b.tga |
3 |
c.ani |
In the table 1, access sequence number 1 corresponding file is to be read at first when the software actual access.
The access file list that obtains also can be used for carrying out the arrangement of APMB package except being used for packing.
With reference to Fig. 2, be further used as preferred embodiment, described steps A, it comprises:
A1, empty the file access sequence list;
A2, by the Hook technology, the File Open function is redirected to file sequence collection function in will wrap;
A3, working procedure client trigger the logic that reads of wrapping interior file, thereby the filename of file store in the file access sequence list in will wrapping into;
A4, described file sequence are gathered the interior File Open function of function call bag and are judged whether that file all is read in all bags, if then finish collection, thereby obtain storing the file access sequence list of filename; Otherwise, then re-execute steps A 3.
Wherein, the File Open function reads to wrap function for software commonly used in the bag, and the file sequence is gathered function and then only Duoed this function of log file name than the interior File Open function of bag.The file sequence is gathered function and is realized by the entry address of File Open function in the Hook interception bag usually.The File Open function is redirected to the file sequence to gather the purpose of function is to gather function with the file sequence to substitute the interior File Open function of former bag in will wrapping in the steps A 2.Steps A 3 and A4 all are in order can successfully the filename that wraps interior file to be recorded in the access file list.
Steps A 3 is that the filename of file stores the file access sequence list in will wrapping according to top-down order, namely earlier in the bag of the file of visit file be stored in the bag of file of back visit on the file.The file sequence is gathered function after storing into file spare name in the access file list, still can call File Open function in the bag, in order to continue the filename of subsequent file is gathered.
Gatherer process with table 1 access file list is example below, and the gatherer process of access file list is described:
At first, empty the file access sequence list, and File Open function in the former bag of HOOK, the HOOK program will be redirected to the file sequence to File Open function in the former bag gathers function.
Then, working procedure client, client three files of by name a.mesh, b.tga of access file and c.ani successively.Because former APMB package is opened function by Hook and be redirected to the collection function, so the file sequence is gathered the filename that function can obtain current institute access file.And be appended to the bottom of access sequence tabulation at the filename that will obtain after, capture program can call APMB package again and open function, make the normal operation of calling program and continue to gather follow-up filename, filename a.mesh, b.tga and c.ani add in the access file list in order the most at last, thereby obtain the access file list of table 1.
With reference to Fig. 3, be further used as preferred embodiment, described step B, it comprises:
B1, file and corresponding file access sequence list that will be to be packed be passed to strapping tool;
B2, described strapping tool read the filename in the file access sequence list;
B3, described strapping tool are inquired about in file to be packed, and check the file that whether has filename identical with the described filename that reads, if having, then read the content of this document, and the content that reads is stored to the end of APMB package, execution in step B4 then, otherwise, direct execution in step B4 then;
B4, judge whether that the All Files name in the file access sequence list all is read, if, execution in step B5 then, otherwise, then re-execute step B2;
B5, the file to be packed of remainder is write the end of APMB package, and generate the index area that is used for file in the visit bag, then the index area that generates is stored to the end of APMB package.
Wherein, corresponding file access sequence list is a kind of of the resulting file access sequence list of steps A, and it is specifically designed to packs to wrapping outer file (file namely to be packed).And since the file access sequence list according to top-down acquisition order, therefore the order of the APMB package after the packing also is top-down, namely the position of the file of packing in bag is positioned at above the file of packing the back earlier.So the end of APMB package refers to, the bottom position of APMB package.
Packing process is finished by strapping tool.At first, the filename with the outer file of bag imports strapping tool into corresponding file access sequence list.Then, strapping tool can read the content of the outer file of bag successively according to the filename in the file access sequence list, and to be written into APMB package interior (be step B1~B4).After if all files corresponding with the filename in the file sequence list all are written in the APMB package, also have the outer file of unnecessary bag not to be written in the APMB package, then the file appending that strapping tool can be unnecessary with these is to the end of APMB package, and need not to be concerned about the position (be step B6) of these files in bag.
For example, if five files having filename to be respectively a.mesh, a.bone, b.tga, c.tga and c.ani need pack, and corresponding access file list is table 1 during packing, and then Da Bao process is as follows:
At first, strapping tool receives file to be packed (being these five files of file a.mesh, a.bone, b.tga, c.tga and c.ani by name) and corresponding file access sequence list (i.e. table 1).
Then, strapping tool reads first filename a.mesh in the table 1.
Follow again, strapping tool inquires the file existence of file a.mesh by name in file to be packed after, the content of this document is appended to the end of APMB package.
Then, strapping tool reads second filename b.tga again from table 1, and the file of finding file b.tga by name in file to be packed when inquiring about also exists, this moment, strapping tool still can read the content of the file of file b.tga by name, and it is appended to the end (namely being appended to file following of file a.mesh by name) of APMB package.
Then, strapping tool reads the 3rd filename c.mesh again from table 1.But the file of finding file c.mesh by name in file to be packed when inquiring about does not exist, this moment strapping tool what do not do, so far All Files name corresponding file reads and finishes in the table 1, also has this moment three files to be packed of file a.bone, c.tga by name and c.ani not to be written in the APMB package.Therefore, strapping tool can be appended to these three files the end of APMB package with any order.
At last, strapping tool can generate the index area, and the end that writes APMB package that will generate, thereby obtains the APMB package of structure (a three-dimensional square represents file in the bag among the figure) as shown in Figure 4.The index area comprises essential informations such as filename, document misregistration value and file size.
With reference to Fig. 5, be further used as preferred embodiment, after described step B, also be provided with step C, described step C, it is specially:
APMB package after the packing is upgraded, thereby will need the outer file of bag that increases newly and the interior file of bag that needs upgrade to store in the APMB package, and regenerate the index area of APMB package.
Wherein, the APMB package after the packing refers to the APMB package that obtained by step B.
The outer file of bag that the renewal process of step C can increase needs newly and the file appending that needs the to upgrade end to APMB package, and regenerate the index area.Renewal process is by the refresh routine load, and the original copy of file (being file in the former bag) still can be retained in the APMB package in the bag after upgrading, and just the index area owing to APMB package is changed and can't has access to forever.In addition, the renewal process of step C and packing process or arrangement process are different, and it can be according to position or the order of file in APMB package in the file access sequence list adjustment bag of gathering.
The renewal process of step C is as follows:
1) in refresh routine, imports the APMB package that needs renewal into;
2) in refresh routine, import file in the bag that needs to upgrade into;
3) in the bag that needs are upgraded file appending to the end of APMB package;
4) search successively in the index area of APMB package whether file exists in the bag that needs to upgrade,
If find that this file is present in the index area, then revise the index of this file, it is pointed to upgrade the position of file in bag, back; If find that this file not in the index area, then adds information such as this file name, document location and file size in the index area to.
For example, five files of include file a.mesh, a.bone, b.tga, c.tga and c.ani by name in the APMB package that has existed, its structure is as shown in Figure 4.If need the file of the outer file of newly-increased bag d.tga by name, the file of file b.tga by name in the bag that needs to upgrade.Then its process of upgrading is as follows:
At first, refresh routine loads the APMB package that has existed.
Then, refresh routine reads the file of file d.tga by name, and after its content appended to the APMB package that has existed.
Afterwards, refresh routine file whether Already in the APMB package in the bag of index area inquiry file d.tga by name.Owing in the index area, do not find the file of file d.tga by name, so refresh routine can write current off-set value, filename and the document size information of file of file d.tga by name in the index area.
Then, refresh routine reads the file of file b.tga by name, and after its content appended to the APMB package that has existed.
Follow, Already in whether refresh routine at the file of index area inquiry file b.tga by name in the APMB package again.Owing to the file that in the index area, can find file b.tga by name, so the index of the file of refresh routine meeting revised file b.tga by name, make its position of pointing to new b.tga file (position after namely adding).APMB package structure after the final updated as shown in Figure 6.
With reference to Fig. 7, be further used as preferred embodiment, after described step B, also be provided with step D, described step D, it is specially, treat the APMB package of arrangement according to the file access sequence list that obtains and put in order, thus file and file in wrapping resequenced in the deletion bag that can't have access to.
Wherein, the file access sequence list that obtains both can be the file access sequence list of gathering again, access file list that also can (being step B) uses when packing before.
In this arrangement process of step D, the at first loading APMB package to be put in order that collates program, and successively respective file is written in the new APMB package according to the filename in the access sequence tabulation.And exist for index area in the former APMB package but do not appear at file in the file access sequence list, the end (being the bottom position of new APMB package) of collating program and can simply its content be appended to new APMB package, and need not to be concerned about its order.After the All Files arrangement is finished, collate program former APMB package deletion, and only keep new APMB package.This new APMB package is compared with former APMB package, and access speed is faster, visits more efficient.
With reference to Fig. 8, be further used as preferred embodiment, described step D, it comprises:
D1, finishing tool load APMB package to be put in order and corresponding file access sequence list;
D2, described finishing tool read a filename in the file access sequence list;
D3, described finishing tool are inquired about in APMB package index area to be put in order, check whether file in the filename bag identical with the described filename that reads is arranged, if have, then read the content of this document, and be appended to execution in step D4 behind the end of new APMB package at the file content that will read, otherwise, direct execution in step D4 then;
D4, judge whether that the All Files name in the file access sequence list all is read, if, execution in step D5 then, otherwise, then re-execute step D2;
D5, will be to be put in order APMB package in the remaining bag file write the end of new APMB package, and after generating the index area that is used for file in the visit bag, the index area of generation is appended to the end of new APMB package;
D6, deletion APMB package to be put in order also keep the new APMB package after the arrangement.
Wherein, corresponding file access sequence list both can be new file access sequence list of gathering, the file access sequence list of using in the time of also can packing for step B.And since the file access sequence list according to top-down acquisition order, therefore the order of the APMB package after the arrangement also is top-down, namely the position of file in bag of storage earlier is positioned at above the file of storing the back when arrangement.So the end of new APMB package refers to, the bottom position of new APMB package.
Arrangement process similar with packing process, difference is that packing process can keep file former to be packed, the arrangement process then can be deleted file former to be put in order.
The arrangement process not only can be adjusted the position of file in the bag again and generate new index area, but also can remove the file that those can't have access to, and can further save resource and improve access speed.
For example, the structure of APMB package to be put in order as shown in Figure 6, APMB package namely to be put in order is the APMB package after upgrading.Have two filenames to be b.tga among the figure, the file that is positioned under the a.mesh can't be visited, and the file that is positioned under the c.tga then can have access to.If this moment is as shown in table 2 below through the new file access sequence list that steps A obtains:
Table 2
Then the APMB package structure that obtains behind process step D1~D6 as shown in Figure 9, can see that the arrangement process not only adjusted the order (namely having adjusted the position of file in the bag) of file in the bag according to table 2, and the file of that file that can't visit b.tga by name has been deleted.
Be further used as preferred embodiment, described file is called the filename of a file or is used for the asterisk wildcard of expression file class.
Comprise one or more filenames in the file access sequence list.Filename both can be the filename (as shown in table 1) of a file, also can be the asterisk wildcard for the expression file class.For example, if can visit again two files of file a.tga by name and a.ani behind the file of access file a.mesh by name, and can visit again two files of file b.tga by name and b.ani behind the file of access file b.mesh by name, then can represent above-mentioned two group access sequences with asterisk wildcard, thereby obtain file access sequence list as shown in table 3:
Table 3
Access sequence number |
Filename |
1 |
*.mesh |
2 |
{1}.tga |
3 |
{1}.ani |
In the table 3, * .mesh, { 1}.tga and { 1}.ani is the asterisk wildcard of representation file type.
With reference to Figure 10, a kind of file packaging system based on the Hook technology of the present invention comprises:
Acquisition module is used for adopting the Hook technology that the access order of file in wrapping is gathered, thereby obtains the file access sequence list;
Packetization module pack for the file for the treatment of packing according to the file access sequence list that obtains, thereby file that will be to be packed is written in the APMB package;
The output terminal of described acquisition module is connected with the input end of packetization module.
With reference to Figure 11, be further used as preferred embodiment, described acquisition module comprises:
Empty the unit, be used for emptying the file access sequence list;
Be redirected the unit, be used for by the Hook technology, the File Open function is redirected to file sequence collection function in will wrapping;
The filename record cell is used for the working procedure client, trigger the logic that reads of the interior file of bag, thereby the filename of file stores in the file access sequence list in will wrapping into;
Call and judging unit, be used for described file sequence and gather the interior File Open function of function call bag and judge whether that file all is read in all bags, if then end is gathered, thereby obtain storing the file access sequence list of filename; Otherwise, then go to the filename record cell again;
The described output terminal that empties the unit is successively by being redirected unit and filename record cell and then being connected with calling with the input end of judging unit.
With reference to Figure 12, be further used as preferred embodiment, described packetization module comprises:
Uploading unit is passed to strapping tool for file and corresponding file access sequence list that will be to be packed;
The filename reading unit is used for the filename that described strapping tool reads the file access sequence list;
Query unit, being used for described strapping tool inquires about at file to be packed, check the file that whether has filename identical with the described filename that reads, if have, then read the content of this document, and the content that reads is stored to the end of APMB package, go to judging unit then, otherwise, then jump directly to judging unit;
Judging unit is used for judging whether that the All Files name of file access sequence list all is read, if, then go to writing unit, otherwise, then go to the filename reading unit again;
Writing unit is used for the file to be packed of remainder is write the end of APMB package, and generates the index area that is used for file in the visit bag, then the index area that generates is stored to the end of APMB package;
The input end of described uploading unit is connected with the output terminal of acquisition module, and the output terminal of described uploading unit is connected with judging unit and then with the input end of writing unit by filename reading unit, query unit successively.
More than be that preferable enforcement of the present invention is specified, but the invention is not limited to described embodiment, those of ordinary skill in the art make all equivalent variations or replacement also can doing under the prerequisite of spirit of the present invention, the distortion that these are equal to or replace all is included in the application's claim institute restricted portion.