├── LICENSE ├── README.md └── InventorySearch.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 jamazzz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InventorySearch 2 | This Python script scans through your inventory resource folder to identify image files that are either not referenced in any of the files or are missing from the folder. The script helps in cleaning up unused images and identifying missing assets. 3 | 4 | # How to Use 5 | 6 | 1. Navigate to the directory containing your Python file and open it in your preferred text editor or Integrated Development Environment (IDE). 7 | 8 | 2. Locate the configuration section within the Python file and update the path to your inventory accordingly. Ensure that the path points to the correct location of your inventory data. 9 | 10 | 3. ** How to run ** 11 | - If you're using Visual Studio Code, simply press **F5** to start debugging. If the script doesn't execute as expected, you might need to install a Python extension for debugging. 12 | - Alternatively, open the command prompt and run `python InventorySearch.py`. 13 | 14 | 15 | # Requirements 16 | 17 | - **Python**: Make sure you have Python installed on your system. If not, you can download it from [python.org](https://www.python.org/). 18 | - **ox_inventory or qb-inventory**: You need one of these inventory systems installed to utilize the script. 19 | -------------------------------------------------------------------------------- /InventorySearch.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import shutil 4 | 5 | ######### CONFIG ########## 6 | 7 | inventoryPath = '' # Path to the inventory folder (Needs to use / instead of \) 8 | corePath = '' # QB ONLY # Path to the core folder (Needs to use / instead of \) 9 | 10 | #### DO NOT EDIT BELOW #### 11 | 12 | inventoryType = inventoryPath.split('/')[-1] 13 | desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop') 14 | 15 | itemsPath = inventoryPath+'/data/items.lua' if inventoryType == 'ox_inventory' else corePath+'/shared/items.lua' # Path to the items folder 16 | weaponsPath = inventoryPath+'/data/weapons.lua' if inventoryType == 'ox_inventory' else corePath+'/shared/weapons.lua' # Path to the weapons folder 17 | imagePath = inventoryPath+'/web/images' if inventoryType == 'ox_inventory' else inventoryPath+'/html/images' # Path to the images folder 18 | extrasPath = desktop+'/extras' # Path to the new extra images folder 19 | missingPath = extrasPath+'/missing.txt' # Path to the missing txt file 20 | 21 | missingPath = missingPath.replace('\\', '/') 22 | extrasPath = extrasPath.replace('\\', '/') 23 | 24 | image_list = [] 25 | item_list = [] 26 | weapon_list = [] 27 | 28 | if not os.path.exists(extrasPath): 29 | os.makedirs(extrasPath) 30 | 31 | 32 | if not os.path.exists(missingPath): 33 | with open(missingPath, 'w') as f: 34 | pass 35 | 36 | if inventoryType == 'ox_inventory': 37 | # Images 38 | for _, _, files in os.walk(imagePath): 39 | for file in files: 40 | image_list.append(file) 41 | 42 | # Items 43 | with open(itemsPath, 'r') as file: 44 | content = file.read() 45 | 46 | double_quote_pattern = r'\["(.*?)"\]' 47 | single_quote_pattern = r"\['(.*?)'\]" 48 | 49 | double_quoted_texts = re.findall(double_quote_pattern, content) 50 | single_quoted_texts = re.findall(single_quote_pattern, content) 51 | for text in double_quoted_texts: 52 | item_list.append(text) 53 | 54 | for text in single_quoted_texts: 55 | item_list.append(text) 56 | 57 | 58 | # Weapons 59 | 60 | with open(weaponsPath, 'r') as file: 61 | content = file.read() 62 | 63 | double_quote_pattern = r'\["(.*?)"\]' 64 | single_quote_pattern = r"\['(.*?)'\]" 65 | 66 | double_quoted_texts = re.findall(double_quote_pattern, content) 67 | single_quoted_texts = re.findall(single_quote_pattern, content) 68 | for text in double_quoted_texts: 69 | weapon_list.append(text) 70 | 71 | for text in single_quoted_texts: 72 | weapon_list.append(text) 73 | else: 74 | # Images 75 | for _, _, files in os.walk(imagePath): 76 | for file in files: 77 | image_list.append(file) 78 | 79 | # Items 80 | count = 0 81 | with open(itemsPath, 'r') as file: 82 | for line in file: 83 | if 'image' in line: 84 | item_list.append(re.search(r"['\"](.*?)['\"]", line).group(1)) 85 | # Check for missing images 86 | 87 | open(missingPath, 'w').close() 88 | for item in item_list and weapon_list: 89 | if item not in image_list: 90 | with open(missingPath, 'a') as file: 91 | file.write(item + '\n') 92 | print(f'Missing {item}') 93 | 94 | # Move the extra images to the new folder 95 | 96 | for image in image_list: 97 | if image.split('.')[0] not in item_list and image.split('.')[0] not in weapon_list: 98 | shutil.move(imagePath+'/'+image, extrasPath+'/'+image) 99 | print(f'Moved {image} to {extrasPath}') 100 | 101 | print('Done!') 102 | --------------------------------------------------------------------------------