Jump to content

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

Just a keyboard and some caffeine, making things work.

Link to comment
https://metin2.dev/topic/30821-automat-remove-define-if-app/
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • 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.