From 90ac3891d638910354fefd658ea7a2942612d6f3 Mon Sep 17 00:00:00 2001 From: Niki <39004156+zzniki@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:29:28 +0100 Subject: [PATCH] File extension association utility & improvements in run.cmd - Added an automatic .cbscript file extension association utility (file_assoc.cmd), making modifying the registry unnecessary. - Improved the run.cmd file with argument checks and support for other Python versions. --- file_assoc.cmd | 28 ++++++++++++++++++++++++++++ run.cmd | 47 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 file_assoc.cmd diff --git a/file_assoc.cmd b/file_assoc.cmd new file mode 100644 index 0000000..3e45feb --- /dev/null +++ b/file_assoc.cmd @@ -0,0 +1,28 @@ +@echo off +rem This script associates the .cbscript file extension with +rem the corresponding commmand to compile it, located in run.cmd + +:admincheck + rem Checks if the file is running with administrator privileges + if "%PROCESSOR_ARCHITECTURE%" equ "amd64" ( + >nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system" + ) else ( + >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" + ) + + if "%errorlevel%" equ "0" goto main + +:noadmin + echo Not running as administrator. + echo Requesting administrative privileges... + powershell -Command "Start-Process -Verb RunAs -FilePath '%0'" + exit /b + +:main + assoc .cbscript=CBScript + ftype CBScript=%~dp0run.cmd "%%1" %%* + + echo. + echo Successfully associated CBScript (.cbscript) files + + pause \ No newline at end of file diff --git a/run.cmd b/run.cmd index 0de83d8..beef45a 100644 --- a/run.cmd +++ b/run.cmd @@ -1,13 +1,34 @@ -@rem To make double clicking cbscript files work, modify: -@rem \HKEY_CLASSES_ROOT\cbscript_auto_file\shell\open\command -@rem Set the string value to the file location of this file followed by "%1" -@rem For example: "D:\Dropbox\Projects\Python\CBScript 1.16\run.cmd" "%1" -@rem -@rem To generate blocks.json, via command prompt at the minecraft server: -@rem java -DbundlerMainClass=net.minecraft.data.Main -jar {jar_path} --server --reports -@ECHO CBScript 1.20 -@title %~nx1 -@cd "%~dp0" -@if not defined PYTHON27 set PYTHON27=c:\python27\python -py -2.7 compile.py %1 -@pause \ No newline at end of file +@echo off +rem To make double clicking cbscript files work, either: +rem 1. Run file_assoc.cmd +rem 2. Modify +rem \HKEY_CLASSES_ROOT\cbscript_auto_file\shell\open\command +rem Set the string value to the file location of this file followed by "%1" +rem For example: "D:\Dropbox\Projects\Python\CBScript 1.16\run.cmd" "%1" +rem +rem To generate blocks.json, via command prompt at the minecraft server: +rem java -DbundlerMainClass=net.minecraft.data.Main -jar {jar_path} --server --reports + +echo CBScript 1.20 +title %~nx1 + +if "%1" == "" ( + echo You must specify a file path. + exit /b +) + +if not exist "%1" ( + echo The specified file does not exist. + exit /b +) + +cd "%~dp0" + +if not defined PYTHON27 set PYTHON27=c:\python27\python +if exist "%PYTHON27%" ( + py -2.7 compile.py %1 +) else ( + py compile.py %1 +) + +pause \ No newline at end of file