Skip to main content
ferro
Lead
October 31, 2024
Solved

Cube 1.16.1 and GfxDesigner 4.24.1 generates different .cproject

  • October 31, 2024
  • 1 reply
  • 631 views

Hi Cube/Gfx Team,

Cube 1.16.1 and GfxDesigner 4.24.1 generate different .cproject outputs.

ferro_0-1730383784009.png

 

In a commit on the left, rows 2 and 3 are on separate lines but in newly generated .cproject these are combined into single line 2 on the right. Also spaces are replaced with tabs.

Could this be somehow 'fixed' ?

Thanks

Best answer by ferro

This python script fixes the .cproject

 

#
# Tested on Windows, Cube 1.17, Gfx 4.24.1
# This script processes a `.cproject` file with the following modifications:
# 1. Replaces every two-space indentation with a tab.
# 2. Uses CRLF (`\r\n`) as the newline format.
# 3. Merges lines 2 and 3 into line 2 with no extra characters between them.
# 4. Ensures the last line is exactly `</cproject>`, with no EOF or trailing newline.
#

import os

def process_cproject_file(filename):
 with open(filename, 'r', encoding='utf-8') as file:
 content = file.read()
 
 # Force CRLF as the newline type
 newline_type = '\r\n'
 
 # Split into lines while preserving newline characters
 lines = content.splitlines()
 
 # Replace leading spaces with corresponding number of tabs
 processed_lines = []
 for line in lines:
 leading_spaces = len(line) - len(line.lstrip())
 tabs = '\t' * (leading_spaces // 2) # Each two spaces become one tab
 processed_lines.append(tabs + line.lstrip())
 
 # Combine lines 2 and 3 into line 2 with no extra space
 if len(processed_lines) > 2:
 processed_lines[1] = processed_lines[1].rstrip() + processed_lines[2].lstrip()
 del processed_lines[2]
 
 # Ensure last element is exactly '</cproject>' with no extra newlines or EOF
 processed_lines[-1] = '</cproject>'
 
 # Write back changes using CRLF and ensure no trailing newline
 with open(filename, 'w', encoding='utf-8', newline='') as file:
 file.write(newline_type.join(processed_lines))
 
if __name__ == "__main__":
 process_cproject_file(".cproject")

 

 

1 reply

ferro
ferroAuthorBest answer
Lead
March 3, 2025

This python script fixes the .cproject

 

#
# Tested on Windows, Cube 1.17, Gfx 4.24.1
# This script processes a `.cproject` file with the following modifications:
# 1. Replaces every two-space indentation with a tab.
# 2. Uses CRLF (`\r\n`) as the newline format.
# 3. Merges lines 2 and 3 into line 2 with no extra characters between them.
# 4. Ensures the last line is exactly `</cproject>`, with no EOF or trailing newline.
#

import os

def process_cproject_file(filename):
 with open(filename, 'r', encoding='utf-8') as file:
 content = file.read()
 
 # Force CRLF as the newline type
 newline_type = '\r\n'
 
 # Split into lines while preserving newline characters
 lines = content.splitlines()
 
 # Replace leading spaces with corresponding number of tabs
 processed_lines = []
 for line in lines:
 leading_spaces = len(line) - len(line.lstrip())
 tabs = '\t' * (leading_spaces // 2) # Each two spaces become one tab
 processed_lines.append(tabs + line.lstrip())
 
 # Combine lines 2 and 3 into line 2 with no extra space
 if len(processed_lines) > 2:
 processed_lines[1] = processed_lines[1].rstrip() + processed_lines[2].lstrip()
 del processed_lines[2]
 
 # Ensure last element is exactly '</cproject>' with no extra newlines or EOF
 processed_lines[-1] = '</cproject>'
 
 # Write back changes using CRLF and ensure no trailing newline
 with open(filename, 'w', encoding='utf-8', newline='') as file:
 file.write(newline_type.join(processed_lines))
 
if __name__ == "__main__":
 process_cproject_file(".cproject")