A picture resource processing method and device
By traversing folders and using specific format strings and image loading functions to identify abandoned and missing image resources, the problem of uncleaned abandoned resources in the app is solved, improving cleaning efficiency and accuracy.
Patent Information
- Application Number
- CN202110583098.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-27
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2041-05-27
AI Technical Summary
In existing technologies, the failure to promptly clean up obsolete image resources in an app leads to problems such as increased package size, slow download speed, and wasted bandwidth. Furthermore, it is difficult to ensure that resource cleanup does not affect other components during component-based development.
By receiving resource processing requests, the system obtains the file resource paths of the target application, traverses folders, queries specific format strings and image loading function method names, identifies obsolete and missing image resources, and marks code statements for processing.
It enables timely cleaning of discarded image resources, improves the accuracy of image resource processing, solves the problem of time-consuming and labor-intensive manual searching, and retrieves missing resources.
Smart Images

Figure CN113326231B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for image resource processing. Background Technology
[0002] Applications (i.e., apps) use local static images to render pages. As the business expands and iterates, some image resources become obsolete. Due to issues such as a large number of developers, the number of such obsolete resources within the app increases. These uncollected image resources, if not cleaned up in a timely manner, increase the app's package size, leading to slower download speeds and higher data consumption for users. Therefore, it is necessary to clean up the app's obsolete image resources.
[0003] Currently, if all source code is in one app, each image name can be searched to determine whether the image has been applied and to obtain the images that need to be cleaned up. If the app is developed using a component-based approach, each image name can be searched for for each component to determine whether the image has been applied by the component and to obtain the images that need to be cleaned up.
[0004] In the process of realizing this invention, the inventors discovered that the prior art has at least the following problems: the prior art is a manual search, which is time-consuming and labor-intensive. For development teams with many business development needs, there is not enough time to clean up images, and it is impossible to guarantee that they can maintain a high level of concentration and make no mistakes in a large number of repetitive comparison and analysis. For apps that are developed using components, removing the resources of one component cannot guarantee that it will not affect other components. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide an image resource processing method and apparatus that can promptly clean up abandoned image resources and acquire missing image resources, thereby improving the accuracy of image resource processing.
[0006] To achieve the above objectives, according to one aspect of the present invention, an image resource processing method is provided.
[0007] An image resource processing method according to an embodiment of the present invention includes: receiving a resource processing request; obtaining a file resource path of a target application according to the resource processing request; traversing the folders corresponding to the file resource path to obtain code files and image resources contained in the folders, wherein the number of image resources is at least one; querying a specific format string contained in the code file; comparing the image resources with the specific format string to obtain discarded image resources corresponding to the target application; obtaining an image name string contained in the code file according to the method name of the image loading function; comparing the image name string with the image resources to obtain missing image resources corresponding to the target application.
[0008] Optionally, comparing the image resources with the specific format string to obtain the discarded image resources corresponding to the target application includes: for each image resource, determining whether the specific format string contains the name of the image resource; if not, determining that the image resource is a discarded image resource, thereby obtaining the discarded image resources corresponding to the target application.
[0009] Optionally, the step of obtaining the image name string contained in the code file based on the method name of the image loading function, and comparing the image name string with the image resource to obtain the missing image resource corresponding to the target application includes: obtaining the code statement for loading the image contained in the code file based on the method name of the image loading function; determining whether a specific format string exists in the obtained code statement, and if so, determining that the specific format string in the obtained code statement is the image name string; determining whether the image name string exists in the name of the image resource, and if not, determining that the image name string is the missing image resource corresponding to the target application.
[0010] Optionally, after determining whether a specific format string exists in the acquired code statement, the method further includes: if the specific format string does not exist in the acquired code statement, then marking the acquired code statement as a reminder statement so that the reminder statement can be processed according to business requirements.
[0011] Optionally, before traversing the folders corresponding to the file resource path, the method further includes: obtaining files to be excluded; and excluding the files to be excluded during the process of traversing the folders corresponding to the file resource path.
[0012] To achieve the above objectives, according to another aspect of the present invention, an image resource processing apparatus is provided.
[0013] An image resource processing apparatus according to an embodiment of the present invention includes: an acquisition module, configured to receive a resource processing request, acquire a file resource path of a target application according to the resource processing request, traverse the folders corresponding to the file resource path, and acquire code files and image resources contained in the folders, wherein the number of image resources is at least one; a first comparison module, configured to query a specific format string contained in the code file, compare the image resources with the specific format string, and obtain discarded image resources corresponding to the target application; and a second comparison module, configured to acquire an image name string contained in the code file according to the method name of the image loading function, compare the image name string with the image resources, and obtain missing image resources corresponding to the target application.
[0014] Optionally, the first comparison module is further configured to: for each image resource, determine whether the specific format string contains the name of the image resource; if not, determine that the image resource is a discarded image resource, so as to obtain the discarded image resource corresponding to the target application.
[0015] Optionally, the second comparison module is further configured to: obtain the code statements for loading images contained in the code file based on the method name of the image loading function; determine whether a specific format string exists in the obtained code statements, and if so, determine that the specific format string in the obtained code statements is the image name string; determine whether the image name string exists in the name of the image resource, and if not, determine that the image name string is the missing image resource corresponding to the target application.
[0016] Optionally, the second comparison module is further configured to: if the acquired code statement does not contain a specific format string, mark the acquired code statement as a reminder statement so that the reminder statement can be processed according to business requirements.
[0017] Optionally, the acquisition module is further configured to: acquire files that need to be excluded; and exclude the files that need to be excluded during the process of traversing the folders corresponding to the file resource paths.
[0018] To achieve the above objectives, according to another aspect of the present invention, an electronic device is provided.
[0019] An electronic device according to an embodiment of the present invention includes: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the image resource processing method of the present invention.
[0020] To achieve the above objectives, according to another aspect of the present invention, a computer-readable medium is provided.
[0021] An embodiment of the present invention provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the image resource processing method of the present invention.
[0022] One embodiment of the above invention has the following advantages or beneficial effects: it can retrieve and analyze the code files of the target program, obtain specific format strings used in the code files, and identify unused image resources, i.e., discarded image resources, by comparing image resources with specific format strings; it can also obtain image name strings by retrieving the method names of image loading functions in the code files, and then compare them with image resources to identify missing image resources; furthermore, it can mark statements with ambiguous code semantics as reminder statements to facilitate processing according to business needs. The image resource processing method provided by the embodiments of the present invention solves the problem of time-consuming and labor-intensive manual search for discarded resources in the prior art, achieves the effect of timely cleaning up discarded image resources, can obtain missing image resources, and can also solve the problem of not directly using image name strings in code files, thereby improving the accuracy of image resource processing.
[0023] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description
[0024] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:
[0025] Figure 1 This is a schematic diagram of the main steps of the image resource processing method according to an embodiment of the present invention;
[0026] Figure 2 This is a schematic diagram of the main flow of the image resource processing method according to an embodiment of the present invention;
[0027] Figures 3 to 5 This is a screenshot of the image resource detection tool page;
[0028] Figure 6 This is a schematic diagram of the main modules of the image resource processing device according to an embodiment of the present invention;
[0029] Figure 7 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;
[0030] Figure 8 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation
[0031] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0032] Figure 1 This is a schematic diagram illustrating the main steps of an image resource processing method according to an embodiment of the present invention. Figure 1 As shown, the main steps of an image resource processing method may include:
[0033] Step S101: Receive a resource processing request; according to the resource processing request, obtain the file resource path of the target application; traverse the folders corresponding to the file resource path; and obtain the code files and image resources contained in the folders.
[0034] Step S102: Query the specific format string contained in the code file, compare the image resources with the specific format string, and obtain the discarded image resources corresponding to the target application;
[0035] Step S103: Based on the method name of the image loading function, obtain the image name string contained in the code file, compare the image name string with the image resources, and obtain the missing image resources corresponding to the target application.
[0036] The resource processing request refers to a request to clean up the image resources of the App. By receiving the resource processing request, the target application, i.e., the target App, which is the App whose image resources need to be cleaned up, can be obtained. Furthermore, the file resource path of the target App can be obtained, and then the folders corresponding to that file resource path can be traversed to obtain the files contained within those folders. It is important to note that during the traversal of the folders corresponding to the file resource path, if the folder contains subfolders, the traversal of those subfolders must continue until all files within the folder corresponding to the file resource path are obtained. On the other hand, after obtaining all files within the folder, the format of each file needs to be determined, i.e., whether each file is a code file or an image resource. Specifically, this can be determined based on the filename extension. For example, code files can have extensions such as h, m, mm, swift, xib, etc., while image resources can have extensions such as jpg, etc. Therefore, in step S101, code files and image resources are obtained through the file resource path of the target application. It is important to note that the number of image resources must be at least one.
[0037] Furthermore, before traversing the folders corresponding to the file resource paths, the image resource processing method can also include: obtaining files to be excluded; and excluding files to be excluded during the traversal of the folders corresponding to the file resource paths. Considering that the folders corresponding to the file resource paths contain some open-source files or other directly used files, these files are files that need to be ignored; that is, they can be skipped during folder traversal. Therefore, obtaining the files to be excluded before traversing the folders allows these files to be ignored during the traversal process.
[0038] After obtaining the code files and image resources, it is necessary to analyze which image resources were not used, and also to analyze whether the code files used image resources other than those obtained, that is, to obtain the discarded image resources and missing image resources.
[0039] In step S102, specific format strings contained in the code files can be queried. For example, the code file can be opened with a text editor and analyzed to query for specific format strings. The code file can be viewed as a string, and the specific format string can be a string that uses image resources or other resources. Therefore, by querying the specific format strings, strings that use images can be retrieved. For example, the specific format can be @"", and the content within the double quotes is the retrieved specific format string. It is worth noting that this process analyzes all code files contained in the folder to obtain all specific format strings.
[0040] After obtaining the specific format string, the image resources obtained in step S101 can be compared with the specific format string to obtain the discarded image resources corresponding to the target app. Further, comparing the image resources with the specific format string to obtain the discarded image resources corresponding to the target application can include: for each image resource, determining whether the specific format string contains the name of the image resource; if not, determining that the image resource is a discarded image resource, thus obtaining the discarded image resources corresponding to the target application.
[0041] There must be at least one image resource. Each image resource can be analyzed to determine if its name is contained in a specific format string. If it is, the image resource is used in the code file and therefore does not need to be cleaned up. If it is not, the image resource is not used in the code file and can be considered a discarded image resource. After analyzing each image resource, the discarded image resources corresponding to the target application can be obtained. Furthermore, the name and file path of the discarded image resources can be recorded for easy display in a list format.
[0042] After obtaining the code file, it can be analyzed to extract the image name string contained within it, based on the image loading function method name. The image loading function method refers to the function in the code file that loads the image, such as `UIImage imageNamed:@"icon.jpg"`. Of course, it can also be other general image loading functions or a custom image loading function.
[0043] In this embodiment of the invention, the image loading function used in the code file can be obtained in advance, so as to obtain the image name string contained in the code file by combining the method name of the image loading function. Further, obtaining the image name string contained in the code file based on the method name of the image loading function may include: obtaining the code statement for loading the image contained in the code file based on the method name of the image loading function; determining whether a specific format string exists in the obtained code statement; if so, determining that the specific format string in the obtained code statement is the image name string.
[0044] In other words, during the analysis of the code file, the code statement containing the image loading function is directly obtained based on its method name; that is, the code statement used to load the image is obtained. Then, it is determined whether a specific format string exists in the obtained code statement. As explained above, the specific format string can be a string that uses image resources or other resources. Therefore, if the obtained code statement is for loading an image and contains a specific format string, it means that the specific format string is an image name string, i.e., it contains the image name.
[0045] Next, the analyzed image name string can be compared with the image resources obtained in step S101 to identify the missing image resources. Specifically, this can be achieved by checking if the image resource name contains the image name string; if not, the image name string is identified as the missing image resource corresponding to the target application. In other words, the image name string in the code file is compared with the names of all obtained image resources. If the image name string is not found in any of the image resource names, the image resource represented by that image name string is identified as the missing image resource. Finally, the missing image resource can be recorded for easy display in a list format.
[0046] Furthermore, as an embodiment of the present invention, after determining whether a specific format string exists in the acquired code statement, the image resource processing method may further include: if the specific format string does not exist in the acquired code statement, then the acquired code statement is marked as a reminder statement, so as to facilitate processing of the reminder statement according to business needs.
[0047] In this embodiment of the invention, the code statements for loading images contained in the code file can be obtained based on the method name of the image loading function. Then, it can be determined whether a specific format string exists in the obtained code statements. If the specific format string does not exist, it means that it is not possible to directly analyze the code semantics to determine whether the image loading code statement uses an image resource. In this case, the code statement can be marked as a warning statement. For example, if the code statement is `UIImageimageNamed: imgaNamed`, since it includes the image loading function `UIImage imageNamed`, it can be considered as an image loading code statement. However, since the code statement does not contain the specific format string `@"`, it is not possible to directly analyze the code semantics to determine whether it uses an image resource. In this case, the code statement can be marked as a warning statement, and then processed according to business requirements. For example, if it is determined to be an assignment, and `imgaNamed = @"settlement-close` exists in the code file, and an image resource named `settlement-close` exists, then it means that the code statement uses an image resource. It should be noted that although there is no specific format string in the code statement UIImage imageNamed: imgaNamed, there is imgaNamed = @"settlement-close" in the code file. Step S102 analyzes all specific format specifiers in the code file, so the image resource named settlement-close will not be cleaned up.
[0048] Figure 2This is a schematic diagram illustrating the main flow of an image resource processing method according to an embodiment of the present invention. Figure 2 As shown, the main process of image resource processing methods may include:
[0049] Step S201: Receive a resource processing request, and based on the resource processing request, obtain the file resource path of the target application and the files that need to be excluded;
[0050] Step S202: During the process of traversing the folders corresponding to the file resource paths, exclude the files that need to be excluded, and obtain the code files and image resources contained in the folders, wherein the number of image resources is at least one.
[0051] Step S203: Query the code file for specific format strings;
[0052] Step S204: For each image resource, determine whether the name of the image resource is contained in a specific format string. If not, determine that the image resource is a discarded image resource, so as to obtain the discarded image resource corresponding to the target application.
[0053] Step S205: Based on the method name of the image loading function, obtain the code statements for loading images contained in the code file;
[0054] Step S206: Determine whether a specific format string exists in the obtained code statement. If yes, proceed to step S207; otherwise, proceed to step S209.
[0055] Step S207: Determine that the specific format string in the obtained code statement is an image name string, and check whether the image resource name contains an image name string. If not, proceed to step S208.
[0056] Step S208: Determine that the image name string is the missing image resource corresponding to the target application;
[0057] Step S209: Mark the acquired code statements as reminder statements so that the reminder statements can be processed according to business needs.
[0058] In step S204, each image resource needs to be analyzed. If a specific format string contains the name of the image resource, it means that the image resource is used in the code file, and therefore it is a useful image resource that does not need to be cleaned up. Furthermore, in step S207, if it is determined that the name of an image resource contains an image name string, it means that the image resource contains a resource corresponding to that image name string.
[0059] In addition, the image resource processing method provided in the embodiments of the present invention can be integrated to develop an image resource detection tool, which can be named JDOSUnusedResources. Figures 3 to 5 This is a screenshot of the image resource detection tool page. Figure 3 As shown, click Browse to select the file resource path you want to search, then click Search at the bottom. The table below will then show the image resource files that are not used in the code file. Click the image to copy the resource path, double-click to open the folder where the image resource is located, then click the resource list to select it, and finally click Delete at the bottom to delete it. Figure 4 In the middle, click the Warning button. The table at the bottom displays some special cases encountered in the code statements. Select the prompt and click copy. Developers need to find it in the project and handle the relevant code block according to their own business logic. Figure 5 In the middle, click on "shortage" to display instances where images are missing from code within the project. Select the prompt content, click "copy," and search within the project. Depending on the business logic, developers need to add images or remove relevant code based on their specific business requirements.
[0060] The image resource processing method according to embodiments of the present invention can perform retrieval and analysis on the code files of a target program, obtain specific format strings used in the code files, and determine unused image resources, i.e., discarded image resources, by comparing image resources with the specific format strings; and obtain image name strings by retrieving the method names of image loading functions in the code files, and then compare them with image resources to determine missing image resources; furthermore, it can mark statements with ambiguous code semantics as reminder statements to facilitate processing according to business needs. The image resource processing method provided by the embodiments of the present invention solves the problem of time-consuming and labor-intensive manual search for discarded resources in the prior art, achieves the effect of timely cleaning up discarded image resources, can obtain missing image resources, and can also solve the problem of not directly using image name strings in code files, thereby improving the accuracy of image resource processing.
[0061] Figure 6 This is a schematic diagram of the main modules of an image resource processing apparatus according to an embodiment of the present invention. Figure 6 As shown, the main modules of the image resource processing device 600 may include: an acquisition module 601, a first comparison module 602, and a second comparison module 603.
[0062] The acquisition module 601 can be used to: receive a resource processing request, obtain the file resource path of the target application according to the resource processing request, traverse the folders corresponding to the file resource path, and obtain the code files and image resources contained in the folders, wherein the number of image resources is at least one; the first comparison module 602 can be used to: query a specific format string contained in the code file, compare the image resources with the specific format string, and obtain the discarded image resources corresponding to the target application; the second comparison module 603 can be used to: obtain the image name string contained in the code file according to the method name of the image loading function, compare the image name string with the image resources, and obtain the missing image resources corresponding to the target application.
[0063] As an embodiment of the present invention, the first comparison module 602 can also be used to: for each image resource, determine whether the name of the image resource is contained in a specific format string; if not, determine that the image resource is a discarded image resource, so as to obtain the discarded image resource corresponding to the target application.
[0064] As an embodiment of the present invention, the second comparison module 603 can also be used to: obtain the code statements for loading images contained in the code file according to the method name of the image loading function; determine whether a specific format string exists in the obtained code statements, and if so, determine that the specific format string in the obtained code statements is an image name string; determine whether an image name string exists in the name of the image resource, and if not, determine that the image name string is a missing image resource corresponding to the target application.
[0065] As an embodiment of the present invention, the second comparison module 603 can also be used to: if the acquired code statement does not contain a specific format string, mark the acquired code statement as a reminder statement so as to facilitate the processing of the reminder statement according to business needs.
[0066] As an embodiment of the present invention, the acquisition module 601 can also be used to: acquire files that need to be excluded; and exclude files that need to be excluded during the process of traversing the folders corresponding to the file resource paths.
[0067] The image resource processing apparatus according to embodiments of the present invention can perform retrieval and analysis on the code files of a target program, obtain specific format strings used in the code files, and determine unused image resources, i.e., discarded image resources, by comparing image resources with the specific format strings; and obtain image name strings by retrieving the method names of image loading functions in the code files, and then compare them with image resources to determine missing image resources; furthermore, it can mark statements with ambiguous code semantics as reminder statements to facilitate processing according to business needs. The image resource processing apparatus provided by the embodiments of the present invention can solve the problem of time-consuming and labor-intensive manual search for discarded resources in the prior art, achieve the effect of timely cleaning up discarded image resources, obtain missing image resources, and solve the problem of not directly using image name strings in code files, thereby improving the accuracy of image resource processing.
[0068] Figure 7 An exemplary system architecture 700 is shown that can be applied to the image resource processing method or image resource processing apparatus of the present invention.
[0069] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, and 703, a network 704, and a server 705. Network 704 serves as the medium for providing communication links between terminal devices 701, 702, and 703 and server 705. Network 704 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0070] Users can use terminal devices 701, 702, and 703 to interact with server 705 via network 704 to receive or send messages, etc. Terminal devices 701, 702, and 703 can be various electronic devices with displays and web browsing capabilities, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0071] Server 705 can be a server that provides various services, such as a backend management server that provides support during the process of users using terminal devices 701, 702, and 703 to process image resources (this is just an example); for another example, server 705 can complete the image resource processing of the embodiments of the present invention.
[0072] It should be noted that the image resource processing method provided in this embodiment of the invention is generally executed by server 705, and correspondingly, the image resource processing device is generally located in server 705.
[0073] It should be understood that Figure 7The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0074] The following is for reference. Figure 8 It shows a schematic diagram of the structure of a computer system 800 suitable for implementing a terminal device of the present invention. Figure 8 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0075] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 802 or programs loaded from storage section 808 into random access memory (RAM) 803. The RAM 803 also stores various programs and data required for the operation of the system 800. The CPU 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0076] The following components are connected to I / O interface 805: an input section 806 including a keyboard, mouse, etc.; an output section 807 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to I / O interface 805 as needed. A removable medium 811, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 810 as needed so that computer programs read from it can be installed into storage section 808 as needed.
[0077] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 809, and / or installed from removable medium 811. When the computer program is executed by central processing unit (CPU) 801, it performs the functions defined above in the system of this invention.
[0078] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0079] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0080] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be housed in a processor; for example, a processor can be described as including an acquisition module, a first comparison module, and a second comparison module. The names of these modules do not necessarily limit the module itself; for example, the acquisition module can also be described as "a module that receives a resource processing request, acquires the file resource path of the target application based on the resource processing request, traverses the folders corresponding to the file resource path, and acquires the code files and image resources contained in the folders."
[0081] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, which, when executed by the device, cause the device to include: receiving a resource processing request; obtaining a file resource path of a target application according to the resource processing request; traversing folders corresponding to the file resource path; obtaining code files and image resources contained in the folders, wherein the number of image resources is at least one; querying a specific format string contained in the code file; comparing the image resources with the specific format string to obtain discarded image resources corresponding to the target application; obtaining an image name string contained in the code file according to the method name of the image loading function; comparing the image name string with the image resources to obtain missing image resources corresponding to the target application.
[0082] According to the technical solution of the embodiments of the present invention, the code files of the target program can be searched and analyzed to obtain specific format strings used in the code files. By comparing image resources with specific format strings, unused image resources, i.e., discarded image resources, can be identified. Furthermore, by searching the method names of image loading functions in the code files, image name strings can be obtained and compared with image resources to identify missing image resources. Additionally, statements with ambiguous code semantics can be marked as warning statements for processing according to business needs. The image resource processing method provided by the embodiments of the present invention solves the problem of time-consuming and labor-intensive manual searching for discarded resources in the prior art, achieving the effect of timely cleaning up discarded image resources. It can also obtain missing image resources and solve the problem of not directly using image name strings in code files, improving the accuracy of image resource processing.
[0083] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for processing image resources, characterized in that, include: Receive a resource processing request, obtain the file resource path of the target application according to the resource processing request, traverse the folders corresponding to the file resource path, and obtain the code files and image resources contained in the folders, wherein the number of image resources is at least one; The process involves querying a specific format string contained in the code file, comparing the image resource with the specific format string, and obtaining the discarded image resource corresponding to the target application. This includes: for each image resource, determining whether the specific format string contains the name of the image resource; if not, determining that the image resource is a discarded image resource, thereby obtaining the discarded image resource corresponding to the target application; wherein, the specific format string is a string that uses the image resource or other resources. Based on the method name of the image loading function, obtain the image name string contained in the code file, compare the image name string with the image resource, and obtain the missing image resource corresponding to the target application. This includes: obtaining the code statement for loading the image contained in the code file based on the method name of the image loading function; determining whether a specific format string exists in the obtained code statement; if so, determining that the specific format string in the obtained code statement is the image name string; determining whether the image name string exists in the name of the image resource; if not, determining that the image name string is the missing image resource corresponding to the target application; if not, and if it is determined that it is an assignment, the image resource name exists in the code file, and an image resource with the name of the image resource exists, determining that the code statement applies the image resource.
2. The method according to claim 1, characterized in that, After determining whether a specific format string exists in the retrieved code statement, the method further includes: If the acquired code statement does not contain a specific format string, the acquired code statement is marked as a reminder statement so that the reminder statement can be processed according to business needs.
3. The method according to claim 1, characterized in that, Before traversing the folders corresponding to the file resource paths, the method further includes: Obtain the files that need to be excluded; and, During the process of traversing the folders corresponding to the file resource paths, exclude the files that need to be excluded.
4. An image resource processing device, characterized in that, include: The acquisition module is used to receive resource processing requests, acquire the file resource path of the target application according to the resource processing requests, traverse the folders corresponding to the file resource paths, and acquire the code files and image resources contained in the folders, wherein the number of image resources is at least one. The first comparison module is used to query a specific format string contained in the code file, compare the image resource with the specific format string, and obtain the discarded image resource corresponding to the target application. This includes: for each image resource, determining whether the specific format string contains the name of the image resource; if not, determining that the image resource is a discarded image resource, thereby obtaining the discarded image resource corresponding to the target application; wherein, the specific format string is a string that uses the image resource or other resources. The second comparison module is used to obtain the image name string contained in the code file based on the method name of the image loading function, and compare the image name string with the image resource to obtain the missing image resource corresponding to the target application. This includes: obtaining the code statement for loading the image contained in the code file based on the method name of the image loading function; determining whether a specific format string exists in the obtained code statement; if so, determining that the specific format string in the obtained code statement is the image name string; determining whether the image name string exists in the name of the image resource; if not, determining that the image name string is the missing image resource corresponding to the target application; if not, and if it is determined that the code statement applies the image resource, and an image resource with the name "image resource name" exists in the code file, then the code statement applies the image resource.
5. An electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-3.
6. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-3.
Citation Information
Patent Citations
Walkthrough method for web application page picture and page jump
CN101169786A
Method and device for deleting waste pictures and electronic equipment
CN109614511A
Picture resource processing method and system, client, server, processor and medium
CN110489576A
Application program processing method and device, terminal and storage medium
CN111679835A