Skip to content

Commit

Permalink
Now uses glob 🦠! Also works with block comments on lua 🌘 files
Browse files Browse the repository at this point in the history
  • Loading branch information
LombardiDaniel committed Feb 17, 2022
1 parent 18d414d commit 8a3cfe5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 87 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Simple script to unlock all skins from all nations in DCS: World.

### Download

You can get the latest executable from [releases](https://github.com/LombardiDaniel/dcs-livery-unlocker/releases). Or from the UserFiles: [https://www.digitalcombatsimulator.com/en/files/3318254/]
You can get the latest executable from [releases](https://github.com/LombardiDaniel/dcs-livery-unlocker/releases). Or from the UserFiles: https://www.digitalcombatsimulator.com/en/files/3318254/

### Usage

Expand All @@ -32,5 +32,5 @@ This project is under the MIT license - see the file [LICENSE.md](LICENSE.md) fo

Create executable (from `src` folder):
```sh
pyinstaller --onefile --icon=logo.ico main.py
pyinstaller --clean --onefile --icon='logo.ico' main.py
```
Binary file modified requirements.txt
Binary file not shown.
4 changes: 2 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def main():

DEBUG = True
DEBUG = False

ui = UI()
utils = Utils()
Expand Down Expand Up @@ -51,7 +51,7 @@ def main():

try:
utils.fix_default_liveries()
utils.fix_mods_liveries()
# utils.fix_mods_liveries() # this one is commented because each mod does it their own way
utils.fix_downloaded_liveries()
utils.fix_bazar_liveries()

Expand Down
2 changes: 1 addition & 1 deletion src/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ class UI:
sg.theme('Dark Teal 4')

def __init__(self):
self.window = sg.Window('DCS Liveries Nation Unlocker - v1.3', layout, icon='logo.ico')
self.window = sg.Window('DCS Liveries Nation Unlocker - v1.2.1', layout, icon='logo.ico')
122 changes: 41 additions & 81 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,114 +15,74 @@ def __init__(self):
self.saved_games_dcs_dir = ''
# self.window = ui_window

def ready(self):
return self.dcs_dir != '' and self.saved_games_dcs_dir != ''

def fix_default_liveries(self):

CORE_MODS_GLOB_STR = os.path.join(self.dcs_dir, '/CoreMods/aircraft/*[!Pack]/Liveries/**/**/description.lua')

for file_path in glob(CORE_MODS_GLOB_STR):
if '13th_Fighter_Squadron' in file_path:
print('bateu, path: ', file_path)


def comment_out_countries(self, file_path):
@staticmethod
def comment_out_countries_restriction(file_path):
'''
'''

print(f'Unlocking: {file_path}')

lines = []
with open(file_path, 'r', encoding='UTF-8') as file:
lines = file.readlines()

open_flag = False
for i, line in enumerate(lines):
if 'countries = {' in line and '}' in line: # Single-line comment
lines[i] = f'-- {line}'

def fix_mods_liveries(self):

aircrafts_dir = os.path.join(self.saved_games_dcs_dir, 'mods', 'aircraft')

if os.path.isdir(aircrafts_dir):
for aircraft_name in os.listdir(aircrafts_dir):
if not aircraft_name.endswith('Pack'):
aircraft_liveries_dir = os.path.join(aircrafts_dir, aircraft_name, 'Liveries')

if os.path.isdir(aircraft_liveries_dir):
for arcraft_var_name in os.listdir(aircraft_liveries_dir):
arcraft_var_dir = os.path.join(aircraft_liveries_dir, arcraft_var_name)

if os.path.isdir(arcraft_var_dir):
for livery_name in os.listdir(arcraft_var_dir):
description_lua_path = os.path.join(arcraft_var_dir, livery_name, 'description.lua')
if os.path.isfile(description_lua_path):
lines = []
if 'countries = {' in line and '}' not in line: # Opening Line of block
open_flag = True
print(f'Unlocking: {file_path}')
lines[i] = f'-- {line}'

print(description_lua_path)
if open_flag and '}' not in line: # Center of block
lines[i] = f'-- {line}'

with open(description_lua_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
if open_flag and '}' in line: # End of block
open_flag = False
lines[i] = f'-- {line}'

for i, line in enumerate(lines):
if 'countries = {' in line:
print(f'Unlocking: {description_lua_path}')
lines[i] = line.replace('countries = {', '-- countries = {')
with open(file_path, 'w', encoding='UTF-8') as f:
f.writelines(lines)

with open(description_lua_path, 'w') as f:
f.writelines(lines)

def fix_bazar_liveries(self):
def ready(self):
return self.dcs_dir != '' and self.saved_games_dcs_dir != ''

aircrafts_dir = os.path.join(self.dcs_dir, 'Bazar', 'liveries')

for aircraft_name in os.listdir(aircrafts_dir):
if not aircraft_name.endswith('Pack'):
aircraft_liveries_dir = os.path.join(aircrafts_dir, aircraft_name)
def fix_default_liveries(self):

for livery_name in os.listdir(aircraft_liveries_dir):
livery_dir = os.path.join(aircraft_liveries_dir, livery_name)
CORE_MODS_GLOB_STR = os.path.join(self.dcs_dir, 'CoreMods/aircraft/**/Liveries/**/**/*.lua')

description_lua_path = os.path.join(livery_dir, 'description.lua')
if os.path.isfile(description_lua_path):
lines = []
for file_path in glob(CORE_MODS_GLOB_STR):
if 'Pack\Liveries' not in file_path:
self.comment_out_countries_restriction(file_path)

print(description_lua_path)

with open(description_lua_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
def fix_downloaded_liveries(self):

for i, line in enumerate(lines):
if 'countries = {' in line:
print(f'Unlocking: {description_lua_path}')
lines[i] = line.replace('countries = {', '-- countries = {')
SAVED_GAMES_LIVERIES = os.path.join(self.saved_games_dcs_dir, '?iveries/**/*.lua')

with open(description_lua_path, 'w', encoding='utf-8') as f:
f.writelines(lines)
for file_path in glob(SAVED_GAMES_LIVERIES):
self.comment_out_countries_restriction(file_path)

def fix_downloaded_liveries(self):

liveries_dir = os.path.join(self.saved_games_dcs_dir, 'Liveries')
def fix_mods_liveries(self):

if os.path.isdir(liveries_dir):
for aircraft_name in os.listdir(liveries_dir):
if not aircraft_name.endswith('Pack'):
aircraft_liveries_dir = os.path.join(liveries_dir, aircraft_name)
SAVED_GAMES_MODS_LIVERIES = os.path.join(self.saved_games_dcs_dir, '?ods/aircraft/**/Liveries/**/*.lua')

if os.path.isdir(aircraft_liveries_dir):
if os.path.isdir(aircraft_liveries_dir):
for livery_name in os.listdir(aircraft_liveries_dir):
description_lua_path = os.path.join(aircraft_liveries_dir, livery_name, 'description.lua')
if os.path.isfile(description_lua_path):
lines = []
for file_path in glob(SAVED_GAMES_LIVERIES):
if 'Pack\Liveries' not in file_path:
self.comment_out_countries_restriction(file_path)

print(description_lua_path)

with open(description_lua_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
def fix_bazar_liveries(self):

for i, line in enumerate(lines):
if 'countries = {' in line and '--' not in line:
print(f'Unlocking: {description_lua_path}')
lines[i] = line.replace('countries = {', '-- countries = {')
print(lines[i])
CORE_MODS_GLOB_STR = os.path.join(self.dcs_dir, 'Bazar/Liveries/**/**/*.lua')

with open(description_lua_path, 'w') as f:
f.writelines(lines)
for file_path in glob(CORE_MODS_GLOB_STR):
self.comment_out_countries_restriction(file_path)


class Notifier:
Expand Down
1 change: 0 additions & 1 deletion venv

This file was deleted.

0 comments on commit 8a3cfe5

Please sign in to comment.