@@ -48,13 +48,33 @@ fn align_to(val: u32, alignment: u32) -> u32 {
4848
4949fn main ( ) -> Result < ( ) , Box < dyn Error > > {
5050 let args: Vec < String > = std:: env:: args ( ) . collect ( ) ;
51- if args. len ( ) < 2 {
52- println ! ( "Usage: nvpatch-rs <inputfile> [<outputfile>] [--disable]" ) ;
53- return Ok ( ( ) ) ;
54- }
51+ let mut is_interactive = false ;
52+
53+ let input_path = if args. len ( ) < 2 {
54+ is_interactive = true ;
55+ println ! ( "╔══════════════════════════════════════════════╗" ) ;
56+ println ! ( "║ GPU Performance Patcher ║" ) ;
57+ println ! ( "╚══════════════════════════════════════════════╝" ) ;
58+ println ! ( "\n Instructions:" ) ;
59+ println ! ( "▶ Drag & Drop a .exe file directly into this window." ) ;
60+ println ! ( "▶ Or type the path to the executable manually.\n " ) ;
61+ print ! ( "Target File: " ) ;
62+ use std:: io:: Write ;
63+ std:: io:: stdout ( ) . flush ( ) ?;
64+
65+ let mut input = String :: new ( ) ;
66+ std:: io:: stdin ( ) . read_line ( & mut input) ?;
67+ let trimmed = input. trim ( ) . trim_matches ( '\"' ) . trim_matches ( '\'' ) . to_string ( ) ;
68+ if trimmed. is_empty ( ) {
69+ println ! ( "❌ Aborted: No input provided." ) ;
70+ return Ok ( ( ) ) ;
71+ }
72+ trimmed
73+ } else {
74+ args[ 1 ] . clone ( )
75+ } ;
5576
56- let input_path = & args[ 1 ] ;
57- let mut output_path = input_path;
77+ let mut output_path = input_path. clone ( ) ;
5878 let mut disable = false ;
5979
6080 if args. contains ( & "--disable" . to_string ( ) ) {
@@ -63,16 +83,48 @@ fn main() -> Result<(), Box<dyn Error>> {
6383
6484 for arg in args. iter ( ) . skip ( 2 ) {
6585 if !arg. starts_with ( "--" ) {
66- output_path = arg;
86+ output_path = arg. clone ( ) ;
6787 break ;
6888 }
6989 }
7090
71- let bytes = fs:: read ( input_path) ?;
72- let patched = patch_pe ( & bytes, disable, Path :: new ( input_path) . file_name ( ) . and_then ( |n| n. to_str ( ) ) . unwrap_or ( "output.exe" ) ) ?;
91+ let bytes = match fs:: read ( & input_path) {
92+ Ok ( b) => b,
93+ Err ( e) => {
94+ println ! ( "❌ Error reading file '{}': {}" , input_path, e) ;
95+ if is_interactive {
96+ println ! ( "\n Press Enter to exit..." ) ;
97+ let mut _b = String :: new ( ) ;
98+ std:: io:: stdin ( ) . read_line ( & mut _b) ?;
99+ }
100+ return Err ( e. into ( ) ) ;
101+ }
102+ } ;
103+
104+ let patch_result = patch_pe (
105+ & bytes,
106+ disable,
107+ Path :: new ( & input_path) . file_name ( ) . and_then ( |n| n. to_str ( ) ) . unwrap_or ( "output.exe" )
108+ ) ;
109+
110+ match patch_result {
111+ Ok ( patched) => {
112+ fs:: write ( & output_path, patched) ?;
113+ println ! ( "\n ✨ SUCCESS: Successfully patched -> {}" , output_path) ;
114+ println ! ( "🚀 The executable is now forced to high-performance GPU mode." ) ;
115+ }
116+ Err ( e) => {
117+ println ! ( "\n ❌ PATCH FAILED: {}" , e) ;
118+ }
119+ }
73120
74- fs:: write ( output_path, patched) ?;
75- println ! ( "Successfully patched {}" , output_path) ;
121+ // Keep the console window open if was run interactively or by drag-n-dropping onto EXE icon
122+ // (Windows closes the window immediately after binary completion otherwise)
123+ if is_interactive || args. len ( ) == 2 {
124+ println ! ( "\n Press Enter to close..." ) ;
125+ let mut _final_input = String :: new ( ) ;
126+ std:: io:: stdin ( ) . read_line ( & mut _final_input) ?;
127+ }
76128
77129 Ok ( ( ) )
78130}
0 commit comments