Disclosure of Invention
In order to solve the problems in the prior art, embodiments of the present invention provide a data file verification method and apparatus. The technical scheme is as follows:
in a first aspect, a data file verification method is provided, where the method includes:
generating a first check code of key data based on the key data in the data file;
verifying the key data according to the first verification code and a second verification code of the key data stored in advance;
if the key data passes the verification, determining that the data file passes the verification;
and if the key data check is not passed, determining that the data file check is not passed.
In a first implementation manner of the first aspect, the verifying the critical data according to the first check code and a second check code of the critical data stored in advance includes:
comparing the first check code with the second check code;
if the first check code is the same as the second check code, determining that the key data passes the check;
and if the first check code is not the same as the second check code, determining that the key data check is not passed.
In a second implementation form of the first aspect, the method further includes:
when the key data needs to be used, executing the steps of generating the first check code of the key data and checking the key data;
and if the key data passes the verification, determining to use the key data.
In a third implementation manner of the first aspect, before generating the first check code of the critical data based on the critical data in the data file, the method further includes:
and generating a second check code of the key data according to a specified algorithm and the key data, and storing the second check code to a specified position.
In a fourth implementation manner of the first aspect, the storing the second check code to a specified location includes:
storing the second check code into the data file based on the starting position of the key data; or the like, or, alternatively,
and storing the second check code into other local files except the data file.
In a fifth implementation manner of the first aspect, after storing the second check code to a specified location, the method further includes:
when a modification instruction for the key data is received, modifying the key data, and generating a third check code of the key data based on the modified data;
updating the second check code stored at the specified location to the third check code.
In a sixth implementation manner of the first aspect, the critical data and the non-critical data in the data file are divided according to the size of the influence on the operating state of the electronic device.
In a seventh implementation manner of the first aspect, the key data in the data file includes image quality data, frequency point data, satellite data, and channel data, and the non-key data in the data file includes volume setting data and personality application setting data.
In a second aspect, there is provided a data file checking apparatus, the apparatus including:
the generating module is used for generating a first check code of the key data based on the key data in the data file;
the verification module is used for verifying the key data according to the first verification code and a second verification code of the key data stored in advance;
the determining module is used for determining that the data file passes the verification if the key data passes the verification;
the determining module is further configured to determine that the data file fails to check if the key data fails to check.
In a first implementation manner of the second aspect, the check module is configured to compare the first check code with the second check code; if the first check code is the same as the second check code, determining that the key data passes the check; and if the first check code is not the same as the second check code, determining that the key data check is not passed.
In a second implementation manner of the second aspect, the apparatus further includes an execution module:
the execution module is configured to execute the steps of generating the first check code of the critical data and checking the critical data when the critical data needs to be used;
the determining module is further configured to determine to use the critical data if the critical data passes verification.
In a third implementation manner of the second aspect, the apparatus further includes a storage module:
the generating module is further used for generating a second check code of the key data according to a specified algorithm and the key data;
the storage module is used for storing the second check code to a specified position.
In a fourth implementation manner of the second aspect, the storage module is configured to store the second check code into the data file based on a start position of the critical data; or the like, or, alternatively,
the storage module is used for storing the second check code to other local files except the data file.
In a fifth implementation manner of the second aspect, the apparatus further includes a modification module and an update module:
the modification module is used for modifying the key data when receiving a modification instruction of the key data;
the generating module is further configured to generate a third check code of the key data based on the modified data;
the updating module is configured to update the second check code stored at the designated location to the third check code.
In a sixth implementation manner of the second aspect, the critical data and the non-critical data in the data file are divided according to the size of the influence on the operating state of the electronic device.
In a seventh implementation manner of the second aspect, the key data in the data file includes image quality data, frequency point data, satellite data, and channel data, and the non-key data in the data file includes volume setting data and personalized application setting data.
The technical scheme provided by the embodiment of the invention has the following beneficial effects:
in the process of verifying the data file, a first verification code is generated according to key data in the data file, verification is carried out on a second verification code corresponding to the key data, and when the verification is passed, the data file is determined to be successfully verified. The key data are data which have great influence on the running state of the electronic equipment, so that the normal running of the electronic equipment can be ensured by ensuring the successful verification of the key data, namely the data file can be considered to be successfully verified, meanwhile, the verification of non-key data is not needed, the system-level recovery operation of the electronic equipment caused by the error of the non-key data in the data file is avoided, and the fault tolerance rate of the verification of the electronic equipment is improved; in addition, compared with the prior art that the check code is generated based on all contents of the data file, the electronic equipment consumes less computing resources for generating the check code based on the key data, the time consumed for loading and checking the data file is shorter, and the efficiency of loading and checking the data file by the electronic equipment system is improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
Fig. 1 is a flowchart of a data file verification method according to an embodiment of the present invention. Referring to fig. 1, the method includes:
101. and generating a first check code of the key data based on the key data in the data file.
102. And verifying the key data according to the first check code and a second check code of the key data stored in advance.
103. And if the key data passes the verification, determining that the data file passes the verification, and if the key data does not pass the verification, determining that the data file does not pass the verification.
According to the method provided by the embodiment of the invention, in the process of verifying the data file, the first verification code is generated according to the key data in the data file, the verification is carried out on the first verification code corresponding to the key data, and the data file is determined to be successfully verified when the verification is passed. The key data are data which have great influence on the running state of the electronic equipment, so that the normal running of the electronic equipment can be ensured by ensuring the successful verification of the key data, namely the data file can be considered to be successfully verified, meanwhile, the verification of non-key data is not needed, the system-level recovery operation of the electronic equipment caused by the error of the non-key data in the data file is avoided, and the fault tolerance rate of the verification of the electronic equipment is improved; in addition, compared with the prior art that the check code is generated based on all contents of the data file, the electronic equipment consumes less computing resources for generating the check code based on the key data, the time consumed for loading and checking the data file is shorter, and the efficiency of loading and checking the data file by the electronic equipment system is improved.
Optionally, the verifying the key data according to the first check code and a second check code of the key data stored in advance includes:
comparing the first check code with the second check code;
if the first check code is the same as the second check code, determining that the key data passes the check;
and if the first check code is not the same as the second check code, determining that the key data check is not passed.
Optionally, the method further comprises:
when the key data needs to be used, executing the steps of generating the first check code of the key data and checking the key data;
if the critical data check passes, it is determined to use the critical data.
Optionally, before generating the first check code of the key data based on the key data in the data file, the method further includes:
and generating a second check code of the key data according to a specified algorithm and the key data, and storing the second check code to a specified position.
Optionally, the storing the second check code to the specified location comprises:
storing the second check code into the data file based on the starting position of the key data; or the like, or, alternatively,
and storing the second check code into other local files except the data file.
Optionally, after storing the second check code to the specified location, the method further includes:
when a modification instruction for the key data is received, modifying the key data, and generating a third check code of the key data based on the modified data;
and updating the second check code stored at the specified position into the third check code.
Optionally, the critical data and the non-critical data in the data file are divided according to the influence on the operating state of the electronic device.
Optionally, the key data in the data file includes image quality data, frequency point data, satellite data, and channel data, and the non-key data in the data file includes volume setting data and personality application setting data.
All the above-mentioned optional technical solutions can be combined arbitrarily to form the optional embodiments of the present invention, and are not described herein again.
Fig. 2 is a flowchart of a data file verification method according to an embodiment of the present invention. The method is performed by an electronic device, see fig. 2, the method comprising:
201. when the key data in the data file needs to be used, a first check code of the key data is generated based on the key data in the data file.
The data file is a file for storing data required by the operation of the electronic equipment system. The data in the data file may include key data and non-key data, where the key data and the non-key data may be divided according to the size of the influence on the operating state of the electronic device, and specifically, the data that has a large influence on the operating state of the electronic device may be divided into key data, and the data that has a small influence on the operating state of the electronic device may be divided into non-key data, where the size of the influence on the operating state of the electronic device by the data may be judged based on a preset standard, for example, the key data may include image quality data, frequency point data, satellite data, and channel data, and the non-key data may include volume setting data and personality application setting data (such as source list (source list) aliases and favorite channel aliases in the television).
Referring to fig. 3, fig. 3 is a schematic diagram of a data file according to an embodiment of the present invention, key data (including key data 1 and key data 2) and non-key data (including non-key data 1, non-key data 2, and non-key data 3) in the data file may be arranged in sequence, each of the key data or the non-key data may include a plurality of data items, for example, non-key data 1 may include 5 volume setting data items, key data 1 may include 1 picture quality data item and 1 channel data item, or key data 1 may include 10 picture quality data items. Of course, each key data may also include one data item, for example, the key data 1 may include 1 image quality data item, and the non-key data 1 may include 1 volume setting data item, which is not limited in the embodiment of the present invention. The different types of key data may have different data formats, for example, the channel data may adopt a data format in the form of a list; the frequency point data and the satellite data can adopt an ini configuration file (such as an initialization file); the image quality data may be in an ini profile manner or a list manner as required by the storage condition, which is not limited in the embodiment of the present invention.
The electronic device may change the data in the data file according to a setting operation of a user during operation, for example, when an operation of increasing the image quality by the user is detected, the electronic device may increase the image quality data in the data file from the first image quality to the second image quality or from a plurality of image qualities to the third image quality; when an operation of turning up the volume by the user is detected, the electronic device may turn up the numerical value of the volume setting data in the data file accordingly.
In the embodiment of the invention, the electronic equipment needs to use the key data in the data file when realizing the service function, taking the key data as the image quality data as an example, and the electronic equipment needs to read the image quality data in the data file when playing the video so as to realize the image quality presenting function. When the key data in the data file is needed to realize the corresponding service function, the electronic device can check the data file to ensure that the content of the data file is correct, so that the situation that the service function cannot be realized due to the fact that the electronic device loads the wrong data file is avoided. Considering that the non-critical data in the data file has little influence on the operating state of the electronic device, the electronic device may only verify the critical data in the data file, and the verification process includes steps 201 to 203.
In this step 201, the electronic device may generate a first check code of the key data according to a specified algorithm and the key data in the data file. The specified algorithm may be a CRC (Cyclic Redundancy Check) 32 algorithm, the first Check code may be a Check code of the key data 1 and a Check code of the key data 2 in fig. 3, for example, the electronic device may calculate a verification code of the key data 1 according to the specified algorithm based on at least one data item included in the key data 1.
The embodiment of the present invention is described by taking an example that the electronic device executes the step 201 when the electronic device needs to use the key data, and actually, the electronic device may execute the step 201 at different times. For example, the electronic device may execute the step 201 after the abnormal shutdown and restart to perform subsequent services, for example, when a user watches a television at home, a sudden power failure phenomenon (such as an unexpected power failure in the home) occurs, which causes some data in the television system not to be normally stored, and the television may default to check the data file in the next system startup and data loading process, that is, execute the step 201 and the subsequent steps 202 and 203. Of course, the electronic device may also perform the step 201 periodically to ensure that the subsequent service is performed successfully. The embodiment of the present invention does not limit the specific time when the electronic device executes the step 201.
202. And verifying the key data according to the first check code and a second check code of the pre-stored key data.
Under normal conditions, each time the electronic device generates the check code based on the key data in the current data file, the check code and the key data are correspondingly stored in real time, even if the key data are subsequently modified, a new check code is generated based on the modified key data, and the new check code and the modified key data are correspondingly stored, namely, the check code stored last time is updated to the check code generated this time, so that the matching between the current key data and the check code is ensured. If an abnormal condition occurs during the operation of the electronic device, for example, the electronic device does not completely store the modified key data after modifying the key data, or the electronic device is unexpectedly shut down when the electronic device does not store the new check code after performing a series of operations such as modifying the key data, storing the modified key data, generating a new check code based on the modified key data, and the like, the key data in the data file is part of the modified key data, but the check code is generated based on the key data before modification, and in this case, the check code is not matched with the key data in the data, that is, the content of the data file has an error. Therefore, the electronic device may determine whether the verification passes by judging whether the corresponding stored key data and the verification code are matched, specifically, the electronic device may generate a first verification code based on the current key data, compare the first verification code with a second verification code stored in advance, and determine whether the verification of the key data passes according to a comparison result.
Accordingly, in this embodiment of the present invention, the step 202 may include: the electronic equipment compares the first check code with the second check code; if the first check code is the same as the second check code, the electronic device can determine that the key data passes the check; if the first check code is not the same as the second check code, the electronic device may determine that the critical data check fails.
The second check code is a check code of key data which is stored before the electronic equipment generates the first check code. For example, before the electronic device generates the first check code of the critical data, the electronic device may generate a second check code of the critical data according to the specified algorithm and the critical data, and store the second check code to the specified location. The electronic device may store the second check code in the data file based on the start position of the key data, for example, the position of the check code of the key data in the data file in fig. 3 is immediately adjacent to the start position of the key data, in this case, in order to facilitate the electronic device to correctly identify the corresponding relationship between the key data and the check code, a key data start symbol and an end symbol may be added at the beginning and the end of the key data, respectively, for example, the start symbol is added at the start position of the key data 1, and the end symbol is added at the end position of the key data 1. Of course, the electronic device may also store the second check code in a file other than the data file locally, in this case, in order to facilitate the confirmation of the key data corresponding to the check code, the electronic device may store the second check code and the key data in the other file correspondingly, for example, the electronic device may store the check code of the key data 1 and the key data 1 in the other file correspondingly. Considering that a user may perform corresponding setting operation on the electronic device in the operation process of the electronic device, which may involve a case of modifying data, for the case, after the electronic device stores the second check code to a specified position, if a modification instruction for the key data is received, the key data may be modified, and a third check code for the key data is generated based on the modified data; and updating the second check code stored at the specified position into the third check code. The electronic equipment can generate a new check code based on the data modified each time, so that the check passing rate is improved, the data file check failure caused by the modification of the key data in the data file can be avoided, and further, the recovery operation caused by the check failure caused by the reasons is not needed.
The method comprises the steps of comparing a first check code generated by the electronic equipment based on current key data with a second check code stored before the electronic equipment generates the first check code, namely comparing check codes generated by the electronic equipment based on key data at different moments, judging whether the two check codes are the same, and determining whether the key data passes the check based on the judgment result, so that the electronic equipment can avoid the condition that the data file fails to check due to the fact that the key data in the data file is modified.
203. And if the key data passes the verification, determining that the data file passes the verification, and further using the key data in the data file.
In the embodiment of the invention, the electronic equipment can determine that the data file passes the verification through the verification of the key data, and if the electronic equipment determines that the data file passes the verification, the electronic equipment can determine to use the key data in the data file and realize the corresponding service function based on the key data in the current data file, for example, realize the image quality presentation function based on the image quality data in the data file. The verification of the data file is realized by verifying the key data in the data file instead of integrally verifying all contents of the data file, so that even if the non-key data in the data file is in error, the data file is verified to be passed as long as the key data is verified to be passed, and system-level recovery operation (such as factory setting recovery) is not required, and the fault tolerance rate of the verification of the electronic equipment is greatly improved.
204. And if the key data are not verified, determining that the data file is not verified, and further performing recovery operation.
In the embodiment of the invention, the electronic equipment can determine that the data file cannot be verified through key data verification, and if the electronic equipment determines that the data file cannot be verified, the electronic equipment can restore factory settings and realize corresponding service functions based on the factory settings.
According to the method provided by the embodiment of the invention, in the process of verifying the data file, the first verification code is generated according to the key data in the data file, the verification is carried out on the first verification code corresponding to the key data, and the data file is determined to be successfully verified when the verification is passed. The key data are data which have great influence on the running state of the electronic equipment, so that the normal running of the electronic equipment can be ensured by ensuring the successful verification of the key data, namely the data file can be considered to be successfully verified, meanwhile, the verification of non-key data is not needed, the system-level recovery operation of the electronic equipment caused by the error of the non-key data in the data file is avoided, and the fault tolerance rate of the verification of the electronic equipment is improved; in addition, compared with the prior art that the check code is generated based on all contents of the data file, the electronic equipment consumes less computing resources for generating the check code based on the key data, the time consumed for loading and checking the data file is shorter, and the efficiency of loading and checking the data file by the electronic equipment system is improved.
Fig. 4 is a schematic structural diagram of a data file verification apparatus according to an embodiment of the present invention. Referring to fig. 4, the apparatus includes:
a generating module 401, configured to generate a first check code of key data based on the key data in the data file;
a verification module 402, configured to verify the critical data according to the first verification code and a second verification code of the critical data that is stored in advance;
a determining module 403, configured to determine that the data file is verified if the key data is verified;
the determining module 403 is further configured to determine that the data file fails to check if the key data fails to check.
Optionally, the checking module 402 is configured to compare the first check code with the second check code; if the first check code is the same as the second check code, determining that the key data passes the check; and if the first check code is not the same as the second check code, determining that the key data check is not passed.
Optionally, referring to fig. 5, the apparatus further includes an executing module 404:
the executing module 404 is configured to execute the steps of generating the first check code of the critical data and checking the critical data when the critical data needs to be used;
the determining module 403 is further configured to determine to use the critical data if the critical data passes the verification.
Optionally, referring to fig. 6, the apparatus further comprises a storage module 405:
the generating module 401 is further configured to generate a second check code of the key data according to a specified algorithm and the key data;
the storage module 405 is configured to store the second check code to a specified location.
Optionally, the storing module 405 is configured to store the second check code into the data file based on the start position of the key data; or the like, or, alternatively,
the storage module 405 is configured to store the second check code in a file other than the data file.
Optionally, referring to fig. 7, the apparatus further includes a modification module 406 and an update module 407:
the modifying module 406 is configured to modify the critical data when a modification instruction for the critical data is received;
the generating module 401 is further configured to generate a third check code of the key data based on the modified data;
the updating module 407 is configured to update the second check code stored at the designated location to the third check code.
Optionally, the critical data and the non-critical data in the data file are divided according to the influence on the operating state of the electronic device.
Optionally, the key data in the data file includes image quality data, frequency point data, satellite data, and channel data, and the non-key data in the data file includes volume setting data and personality application setting data.
In the embodiment of the invention, in the process of verifying the data file, a first verification code is generated according to the key data in the data file, verification is carried out on a second verification code corresponding to the key data, and the data file is determined to be successfully verified when the verification is passed. The key data are data which have great influence on the running state of the electronic equipment, so that the normal running of the electronic equipment can be ensured by ensuring the successful verification of the key data, namely the data file can be considered to be successfully verified, meanwhile, the verification of non-key data is not needed, the system-level recovery operation of the electronic equipment caused by the error of the non-key data in the data file is avoided, and the fault tolerance rate of the verification of the electronic equipment is improved; in addition, compared with the prior art that the check code is generated based on all contents of the data file, the electronic equipment consumes less computing resources for generating the check code based on the key data, the time consumed for loading and checking the data file is shorter, and the efficiency of loading and checking the data file by the electronic equipment system is improved.
It should be noted that: the data file verifying apparatus provided in the foregoing embodiment is only illustrated by the division of the functional modules in the data file verification, and in practical applications, the functions may be distributed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the data file verification apparatus and the data file verification method provided by the above embodiments belong to the same concept, and specific implementation processes thereof are detailed in the method embodiments and are not described herein again.
An embodiment of the present invention provides an electronic device 800, where the electronic device 800 may be configured to execute the data file verification method provided in each of the above embodiments. Referring to fig. 8, the electronic apparatus 800 includes a Central Processing Unit (CPU)801, a system memory 804 of a Random Access Memory (RAM)802 and a Read Only Memory (ROM)803, and a system bus 805 connecting the system memory 804 and the central processing unit 801. The electronic device 800 also includes a basic input/output system (I/O system) 806, which facilitates transfer of information between various devices within the computer, and a mass storage device 807 for storing an operating system 813, application programs 814, and other program modules 815.
The basic input/output system 806 includes a display 808 for displaying information and an input device 809 such as a mouse, keyboard, etc. for user input of information. Wherein the display 808 and the input device 809 are connected to the central processing unit 801 through an input output controller 810 connected to the system bus 805. The basic input/output system 806 may also include an input/output controller 810 for receiving and processing input from a number of other devices, such as a keyboard, mouse, or electronic stylus. Similarly, input-output controller 810 also provides output to a display screen, a printer, or other type of output device.
The mass storage device 807 is connected to the central processing unit 801 through a mass storage controller (not shown) connected to the system bus 805. The mass storage device 807 and its associated computer-readable media provide non-volatile storage for the electronic device 800. That is, the mass storage device 807 may include a computer-readable medium (not shown) such as a hard disk or CD-ROM drive.
Without loss of generality, the computer-readable media may comprise computer storage media and communication media. Computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Computer storage media includes RAM, ROM, EPROM, EEPROM, flash memory or other solid state memory technology, CD-ROM, DVD, or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices. Of course, those skilled in the art will appreciate that the computer storage media is not limited to the foregoing. The system memory 804 and mass storage 807 described above may be collectively referred to as memory.
The electronic device 800 may also operate as a remote computer connected to a network via a network, such as the internet, in accordance with various embodiments of the present invention. That is, the electronic device 800 may be connected to the network 812 through the network interface unit 811 coupled to the system bus 805, or may be connected to another type of network or a remote computer system (not shown) using the network interface unit 811.
The memory also includes one or more programs stored in the memory and configured to be executed by one or more processors. The one or more programs include instructions for performing the data file verification method. The instruction is loaded and executed by a processor in the electronic equipment, so that the functions of each module in the data file checking device are realized.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.