Bughy 5 Posted August 9, 2023 Share Posted August 9, 2023 (edited) Hi Maybe not many of you need this, but since I made it, it may help someone. It's a simple script made in python, which checks both files (item_names.txt and item_proto.txt) for missing VNUM differences in one of the files. For example: I used it because I rebuilt both files, deleted items I will never use and restructured some data. In the end, I realized that I have quite a few missing lines from the item_proto.txt file but have them present in item_names.txt. So I made this script, which checked every VNUM present in item_names.txt but missing from item_proto.txt. This made it much easier for me to solve this problem. Atention: For the GUI one, you will need to install PyQt5 via PIP There is a version of just code, so u gonna modify in the code the file names, then run it via terminal Spoiler def read_vnums_from_file(filename): vnums = set() with open(filename, 'r', encoding='utf-8', errors='replace') as file: next(file) for line_number, line in enumerate(file, start=1): line = line.strip() if not line: continue parts = line.split() if len(parts) >= 1: vnum = parts[0] vnums.add(vnum) else: print(f"Warning: Invalid data at line {line_number} in file {filename}") return vnums item_proto_file = "item_proto.txt" item_names_file = "item_names.txt" try: item_proto_vnums = read_vnums_from_file(item_proto_file) item_names_vnums = read_vnums_from_file(item_names_file) missing_vnums = item_proto_vnums - item_names_vnums print("Vnums present in item_proto.txt but not in item_names.txt:") print(missing_vnums) except FileNotFoundError as e: print(f"Error: {e}") except Exception as e: print(f"Error: An unexpected error occurred - {e}") And there is a GUI version, when u run it into a terminal, it will open a GUI and u can chose the files from anywhere, check vnums and also lines Spoiler import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QFileDialog, QTextEdit, QVBoxLayout, QWidget, QTableWidget, QTableWidgetItem, QLabel from PyQt5.QtGui import QTextCursor, QColor from PyQt5.QtCore import Qt def read_vnums_from_file(filename): vnums = {} with open(filename, 'r', encoding='utf-8', errors='replace') as file: next(file) for line_number, line in enumerate(file, start=1): line = line.strip() if not line: continue parts = line.split() if len(parts) >= 1: vnum = parts[0] vnums[vnum] = line_number return vnums class VnumsCheckerApp(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setWindowTitle("Vnums Checker Metin2Dev") self.setGeometry(100, 100, 200, 500) self.setStyleSheet("background-color: #282a36; color: #f8f8f2;") self.central_widget = QWidget(self) self.setCentralWidget(self.central_widget) self.layout = QVBoxLayout(self.central_widget) self.choose_item_proto_btn = QPushButton("Choose item_proto.txt", self.central_widget) self.choose_item_proto_btn.setStyleSheet("background-color: #6272a4; color: #f8f8f2;") self.choose_item_proto_btn.clicked.connect(self.choose_item_proto_file) self.layout.addWidget(self.choose_item_proto_btn) self.choose_item_names_btn = QPushButton("Choose item_names.txt", self.central_widget) self.choose_item_names_btn.setStyleSheet("background-color: #6272a4; color: #f8f8f2;") self.choose_item_names_btn.clicked.connect(self.choose_item_names_file) self.layout.addWidget(self.choose_item_names_btn) self.check_btn = QPushButton("Check Missing Vnums", self.central_widget) self.check_btn.setStyleSheet("background-color: #6272a4; color: #f8f8f2;") self.check_btn.clicked.connect(self.check_missing_vnums) self.layout.addWidget(self.check_btn) self.vnums_label = QLabel("Missing Vnums and Line Numbers in item_proto.txt:", self.central_widget) self.vnums_label.setStyleSheet("color: #ff79c6;") self.layout.addWidget(self.vnums_label) self.table = QTableWidget(self.central_widget) self.table.setStyleSheet("background-color: #44475a; color: #f8f8f2;") self.table.setColumnCount(2) self.table.setHorizontalHeaderLabels(["Vnum", "Line Number"]) self.table.setEditTriggers(QTableWidget.NoEditTriggers) # Prevent editing cells header = self.table.horizontalHeader() header.setStyleSheet("background-color: #44475a; color: #f8f8f2;") header.setDefaultAlignment(Qt.AlignLeft | Qt.AlignVCenter) # Adjust alignment # Set color for header labels header_item = QTableWidgetItem("Vnum") header_item.setForeground(QColor("#ff79c6")) # Set the desired color self.table.setHorizontalHeaderItem(0, header_item) header_item = QTableWidgetItem("Line Number") header_item.setForeground(QColor("#ff79c6")) # Set the desired color self.table.setHorizontalHeaderItem(1, header_item) self.layout.addWidget(self.table) self.layout.setContentsMargins(20, 20, 20, 20) self.layout.setSpacing(10) self.selected_item_proto = "" self.selected_item_names = "" def choose_item_proto_file(self): file_dialog = QFileDialog() file_dialog.setNameFilter("Text Files (*.txt)") item_proto_file, _ = file_dialog.getOpenFileName(self, "Choose item_proto.txt") if item_proto_file: self.selected_item_proto = item_proto_file self.choose_item_proto_btn.setText(item_proto_file.split('/')[-1]) def choose_item_names_file(self): file_dialog = QFileDialog() file_dialog.setNameFilter("Text Files (*.txt)") item_names_file, _ = file_dialog.getOpenFileName(self, "Choose item_names.txt") if item_names_file: self.selected_item_names = item_names_file self.choose_item_names_btn.setText(item_names_file.split('/')[-1]) def check_missing_vnums(self): if not self.selected_item_proto or not self.selected_item_names: self.table.clearContents() self.table.setRowCount(0) return table_width = self.table.viewport().width() self.table.setColumnWidth(0, table_width // 2 - 9) self.table.setColumnWidth(1, table_width // 2 - 9) try: item_proto_vnums = read_vnums_from_file(self.selected_item_proto) item_names_vnums = read_vnums_from_file(self.selected_item_names) missing_vnums = [(vnum, str(line_number)) for vnum, line_number in item_proto_vnums.items() if vnum not in item_names_vnums] self.table.setRowCount(len(missing_vnums)) for row, (vnum, line_number) in enumerate(missing_vnums): vnum_item = QTableWidgetItem(vnum) line_number_item = QTableWidgetItem(line_number) self.table.setItem(row, 0, vnum_item) self.table.setItem(row, 1, line_number_item) except Exception as e: self.table.clearContents() self.table.setRowCount(0) def main(): app = QApplication(sys.argv) window = VnumsCheckerApp() window.show() sys.exit(app.exec_()) if __name__ == "__main__": main() Edited August 9, 2023 by Bughy Adding Infos about requirements 2 3 Link to comment Share on other sites More sharing options...
Forum Moderator VegaS™ 10275 Posted August 9, 2023 Forum Moderator Share Posted August 9, 2023 Thanks for the release, but if you do a quick search in the forum, you'll find that I released something similar to this 4 years ago. 1 Check my GitHub Profile Click to find all the threads started by me [TOOL] Text file loader + JSON Link to comment Share on other sites More sharing options...
Bughy 5 Posted August 9, 2023 Author Share Posted August 9, 2023 1 hour ago, VegaS™ said: Thanks for the release, but if you do a quick search in the forum, you'll find that I released something similar to this 4 years ago. This is the hidden content, please Sign In or Sign Up Oh, srry man. I did not searched before. Well, you can remove the post if so. Sorry again Link to comment Share on other sites More sharing options...
Recommended Posts