Hello!
This tutorial is designed to help beginners who don't know how to change the file encoding.
Since the default encoding is EUC-KR, if I use Chinese, the comments in the code will be garbled. It's very uncomfortable.
The first step is to convert the file encoding
You can use any IDE to convert, I provide my python script here。
import os
import chardet
binary_extensions = [
'.o', '.exe', '.dll', '.so', '.a', '.lib', '.dat', '.bin', '.img', '.iso',
'.bak', '.apk', '.jar', '.war', '.class', '.gz', '.tar', '.zip', '.7z', '.rar',
'.eix','.epk',
]
source_extensions = ['.cpp', '.h', '.py', '.txt', '.lua', '.quest']
def detect_encoding(file_path):
with open(file_path, 'rb') as f:
raw_data = f.read(10000)
result = chardet.detect(raw_data) # Or write "EUC-KR" here
return result['encoding']
def convert_encoding(file_path, dest_encoding='utf-8'):
try:
src_encoding = detect_encoding(file_path)
if src_encoding is None:
print(f"Cannot detect encoding for {file_path}")
return
with open(file_path, 'r', encoding=src_encoding, errors='ignore') as f:
content = f.read()
with open(file_path, 'w', encoding=dest_encoding) as f:
f.write(content)
#print(f"Converted: {file_path} from {src_encoding} to {dest_encoding}")
except Exception as e:
print(f"Failed to convert {file_path}: {e}")
def convert_directory(directory, exclude_dirs=None):
if exclude_dirs is None:
exclude_dirs = []
for root, dirs, files in os.walk(directory):
dirs[:] = [d for d in dirs if d not in exclude_dirs]
for file in files:
if any(file.endswith(ext) for ext in binary_extensions) or not any(file.endswith(ext) for ext in source_extensions):
continue
file_path = os.path.join(root, file)
convert_encoding(file_path)
if __name__ == "__main__":
# SETTING
target_directory = r"F:\metin2\github_ulthar\DumpProto"
excluded_folders = ['.git','.idea', 'Extern','.vs']
# START
convert_directory(target_directory, exclude_dirs=excluded_folders)
Save code files in UTF-8 IN Visual Studio
Visual Studio supports generating an .editorconfig file based on local settings. The operation path is
Tools / Options / Text Editor / C/C++ / Code Stype / General: Generate .editorconfig file from settings.
root = true
[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4
[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}]
The second step is to modify the client locale.cfg file.
The file contents are as follows:
10002 65001 newcibn
Make sure the middle value is changed to: 65001
That's all, I hope it helps. I'll add more if you need it. I didn't encounter any problems compiling on the server side!
Have a nice day!