Jump to content

Automat remove define, if app


Recommended Posts

Script for scanning and automatically removing definitions

Remove.cpp

import os

folder_path = '/txt/src'

encoding = 'latin1'

definition_to_remove = '#ifdef __ENABLE_OFFLINE_SHOP__'

for root, dirs, files in os.walk(folder_path):
    for file in files:
        if file.endswith('.cpp') or file.endswith('.h'):
            file_path = os.path.join(root, file)
            with open(file_path, 'r', encoding=encoding) as f:
                lines = f.readlines()
            with open(file_path, 'w', encoding=encoding) as f:
                remove_lines = False
                for line in lines:
                    if definition_to_remove in line:
                        remove_lines = True
                    if remove_lines:
                        if '#endif' in line:
                            remove_lines = False
                        continue
                    f.write(line)

Remove if app.

import os

directory = '/txt/src'

encoding = 'latin1'

target_if = 'if app.ENABLE_OFFLINE_SHOP:'

for filename in os.listdir(directory):
    if filename.endswith('.py'):
        filepath = os.path.join(directory, filename)
        with open(filepath, 'r', encoding=encoding) as f:
            lines = f.readlines()
        with open(filepath, 'w', encoding=encoding) as f:
            in_target_block = False
            target_indent = 0
            for line in lines:
                indent = len(line) - len(line.lstrip())
                if target_if in line:
                    in_target_block = True
                    target_indent = indent
                elif in_target_block and indent > target_indent:
                    continue
                else:
                    in_target_block = False
                    f.write(line)

 

  • Metin2 Dev 1

Grzyb.ovh

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.