standalone-ruby 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -22
  3. data/lib/data/bat-cmd/default_bat_cmd.txt +9 -9
  4. data/lib/data/c_compilers/tcc/include/_mingw.h +54 -0
  5. data/lib/data/c_compilers/tcc/include/assert.h +71 -0
  6. data/lib/data/c_compilers/tcc/include/conio.h +159 -0
  7. data/lib/data/c_compilers/tcc/include/ctype.h +232 -0
  8. data/lib/data/c_compilers/tcc/include/dir.h +26 -0
  9. data/lib/data/c_compilers/tcc/include/direct.h +95 -0
  10. data/lib/data/c_compilers/tcc/include/dirent.h +96 -0
  11. data/lib/data/c_compilers/tcc/include/dos.h +110 -0
  12. data/lib/data/c_compilers/tcc/include/errno.h +117 -0
  13. data/lib/data/c_compilers/tcc/include/excpt.h +20 -0
  14. data/lib/data/c_compilers/tcc/include/fcntl.h +135 -0
  15. data/lib/data/c_compilers/tcc/include/fenv.h +85 -0
  16. data/lib/data/c_compilers/tcc/include/float.h +224 -0
  17. data/lib/data/c_compilers/tcc/include/inttypes.h +275 -0
  18. data/lib/data/c_compilers/tcc/include/io.h +296 -0
  19. data/lib/data/c_compilers/tcc/include/limits.h +115 -0
  20. data/lib/data/c_compilers/tcc/include/locale.h +100 -0
  21. data/lib/data/c_compilers/tcc/include/malloc.h +87 -0
  22. data/lib/data/c_compilers/tcc/include/math.h +438 -0
  23. data/lib/data/c_compilers/tcc/include/mem.h +8 -0
  24. data/lib/data/c_compilers/tcc/include/memory.h +9 -0
  25. data/lib/data/c_compilers/tcc/include/process.h +158 -0
  26. data/lib/data/c_compilers/tcc/include/setjmp.h +72 -0
  27. data/lib/data/c_compilers/tcc/include/share.h +44 -0
  28. data/lib/data/c_compilers/tcc/include/signal.h +111 -0
  29. data/lib/data/c_compilers/tcc/include/stdarg.h +16 -0
  30. data/lib/data/c_compilers/tcc/include/stdbool.h +10 -0
  31. data/lib/data/c_compilers/tcc/include/stddef.h +26 -0
  32. data/lib/data/c_compilers/tcc/include/stdint.h +184 -0
  33. data/lib/data/c_compilers/tcc/include/stdio.h +413 -0
  34. data/lib/data/c_compilers/tcc/include/stdlib.h +482 -0
  35. data/lib/data/c_compilers/tcc/include/string.h +206 -0
  36. data/lib/data/c_compilers/tcc/include/sys/fcntl.h +8 -0
  37. data/lib/data/c_compilers/tcc/include/sys/file.h +9 -0
  38. data/lib/data/c_compilers/tcc/include/sys/locking.h +52 -0
  39. data/lib/data/c_compilers/tcc/include/sys/stat.h +190 -0
  40. data/lib/data/c_compilers/tcc/include/sys/time.h +3 -0
  41. data/lib/data/c_compilers/tcc/include/sys/timeb.h +82 -0
  42. data/lib/data/c_compilers/tcc/include/sys/types.h +118 -0
  43. data/lib/data/c_compilers/tcc/include/sys/unistd.h +9 -0
  44. data/lib/data/c_compilers/tcc/include/sys/utime.h +89 -0
  45. data/lib/data/c_compilers/tcc/include/tchar.h +367 -0
  46. data/lib/data/c_compilers/tcc/include/time.h +219 -0
  47. data/lib/data/c_compilers/tcc/include/unistd.h +10 -0
  48. data/lib/data/c_compilers/tcc/include/values.h +4 -0
  49. data/lib/data/c_compilers/tcc/include/varargs.h +11 -0
  50. data/lib/data/c_compilers/tcc/include/wchar.h +318 -0
  51. data/lib/data/c_compilers/tcc/include/wctype.h +127 -0
  52. data/lib/data/c_compilers/tcc/include/winapi/basetsd.h +119 -0
  53. data/lib/data/c_compilers/tcc/include/winapi/basetyps.h +144 -0
  54. data/lib/data/c_compilers/tcc/include/winapi/winbase.h +1852 -0
  55. data/lib/data/c_compilers/tcc/include/winapi/wincon.h +207 -0
  56. data/lib/data/c_compilers/tcc/include/winapi/windef.h +240 -0
  57. data/lib/data/c_compilers/tcc/include/winapi/windows.h +176 -0
  58. data/lib/data/c_compilers/tcc/include/winapi/winerror.h +1054 -0
  59. data/lib/data/c_compilers/tcc/include/winapi/wingdi.h +2843 -0
  60. data/lib/data/c_compilers/tcc/include/winapi/winnetwk.h +346 -0
  61. data/lib/data/c_compilers/tcc/include/winapi/winnls.h +651 -0
  62. data/lib/data/c_compilers/tcc/include/winapi/winnt.h +2667 -0
  63. data/lib/data/c_compilers/tcc/include/winapi/winreg.h +159 -0
  64. data/lib/data/c_compilers/tcc/include/winapi/winsvc.h +309 -0
  65. data/lib/data/c_compilers/tcc/include/winapi/winuser.h +3472 -0
  66. data/lib/data/c_compilers/tcc/include/winapi/winver.h +133 -0
  67. data/lib/data/c_compilers/tcc/lib/gdi32.def +337 -0
  68. data/lib/data/c_compilers/tcc/lib/kernel32.def +763 -0
  69. data/lib/data/c_compilers/tcc/lib/libtcc1.a +0 -0
  70. data/lib/data/c_compilers/tcc/lib/msvcrt.def +782 -0
  71. data/lib/data/c_compilers/tcc/lib/user32.def +654 -0
  72. data/lib/data/c_compilers/tcc/tcc.exe +0 -0
  73. data/lib/data/exe_templates/launcher_stub.c +30 -0
  74. data/lib/data/exe_templates/launcher_stub.cpp +31 -0
  75. data/lib/data/launcher_templates/vbs/default_vbs.txt +7 -0
  76. data/lib/data/launcher_templates/vbs/vbs_gui.txt +8 -0
  77. data/lib/data/resource_files/default.rc +17 -0
  78. data/lib/data/tcc/include/_mingw.h +54 -54
  79. data/lib/data/tcc/include/assert.h +71 -71
  80. data/lib/data/tcc/include/conio.h +159 -159
  81. data/lib/data/tcc/include/ctype.h +232 -232
  82. data/lib/data/tcc/include/dir.h +26 -26
  83. data/lib/data/tcc/include/direct.h +95 -95
  84. data/lib/data/tcc/include/dirent.h +96 -96
  85. data/lib/data/tcc/include/dos.h +110 -110
  86. data/lib/data/tcc/include/errno.h +117 -117
  87. data/lib/data/tcc/include/excpt.h +20 -20
  88. data/lib/data/tcc/include/fcntl.h +135 -135
  89. data/lib/data/tcc/include/fenv.h +85 -85
  90. data/lib/data/tcc/include/float.h +224 -224
  91. data/lib/data/tcc/include/inttypes.h +275 -275
  92. data/lib/data/tcc/include/io.h +296 -296
  93. data/lib/data/tcc/include/limits.h +115 -115
  94. data/lib/data/tcc/include/locale.h +100 -100
  95. data/lib/data/tcc/include/malloc.h +87 -87
  96. data/lib/data/tcc/include/math.h +438 -438
  97. data/lib/data/tcc/include/mem.h +8 -8
  98. data/lib/data/tcc/include/memory.h +9 -9
  99. data/lib/data/tcc/include/process.h +158 -158
  100. data/lib/data/tcc/include/setjmp.h +72 -72
  101. data/lib/data/tcc/include/share.h +44 -44
  102. data/lib/data/tcc/include/signal.h +111 -111
  103. data/lib/data/tcc/include/stdarg.h +16 -16
  104. data/lib/data/tcc/include/stdbool.h +10 -10
  105. data/lib/data/tcc/include/stddef.h +26 -26
  106. data/lib/data/tcc/include/stdint.h +184 -184
  107. data/lib/data/tcc/include/stdio.h +413 -413
  108. data/lib/data/tcc/include/stdlib.h +482 -482
  109. data/lib/data/tcc/include/string.h +206 -206
  110. data/lib/data/tcc/include/sys/fcntl.h +8 -8
  111. data/lib/data/tcc/include/sys/file.h +9 -9
  112. data/lib/data/tcc/include/sys/locking.h +52 -52
  113. data/lib/data/tcc/include/sys/stat.h +190 -190
  114. data/lib/data/tcc/include/sys/time.h +3 -3
  115. data/lib/data/tcc/include/sys/timeb.h +82 -82
  116. data/lib/data/tcc/include/sys/types.h +118 -118
  117. data/lib/data/tcc/include/sys/unistd.h +9 -9
  118. data/lib/data/tcc/include/sys/utime.h +89 -89
  119. data/lib/data/tcc/include/tchar.h +367 -367
  120. data/lib/data/tcc/include/time.h +219 -219
  121. data/lib/data/tcc/include/unistd.h +10 -10
  122. data/lib/data/tcc/include/values.h +4 -4
  123. data/lib/data/tcc/include/varargs.h +11 -11
  124. data/lib/data/tcc/include/wchar.h +318 -318
  125. data/lib/data/tcc/include/wctype.h +127 -127
  126. data/lib/data/tcc/include/winapi/basetsd.h +119 -119
  127. data/lib/data/tcc/include/winapi/basetyps.h +144 -144
  128. data/lib/data/tcc/include/winapi/winbase.h +1852 -1852
  129. data/lib/data/tcc/include/winapi/wincon.h +207 -207
  130. data/lib/data/tcc/include/winapi/windef.h +240 -240
  131. data/lib/data/tcc/include/winapi/windows.h +176 -176
  132. data/lib/data/tcc/include/winapi/winerror.h +1054 -1054
  133. data/lib/data/tcc/include/winapi/wingdi.h +2843 -2843
  134. data/lib/data/tcc/include/winapi/winnetwk.h +346 -346
  135. data/lib/data/tcc/include/winapi/winnls.h +651 -651
  136. data/lib/data/tcc/include/winapi/winnt.h +2667 -2667
  137. data/lib/data/tcc/include/winapi/winreg.h +159 -159
  138. data/lib/data/tcc/include/winapi/winsvc.h +309 -309
  139. data/lib/data/tcc/include/winapi/winuser.h +3472 -3472
  140. data/lib/data/tcc/include/winapi/winver.h +133 -133
  141. data/lib/data/tcc/lib/gdi32.def +337 -337
  142. data/lib/data/tcc/lib/kernel32.def +763 -763
  143. data/lib/data/tcc/lib/msvcrt.def +782 -782
  144. data/lib/data/tcc/lib/user32.def +654 -654
  145. data/lib/data/vbs/default_vbs.txt +7 -7
  146. data/lib/data/vbs/vbs_gui.txt +8 -8
  147. data/lib/displayer.rb +66 -0
  148. data/lib/exe_packer.rb +82 -0
  149. data/lib/launcher.rb +84 -0
  150. data/lib/launcher_handler.rb +53 -0
  151. data/lib/logger_helper.rb +24 -0
  152. data/lib/parameter_parser.rb +210 -0
  153. data/lib/ruby_copy.rb +26 -0
  154. data/lib/sfx_generator.rb +11 -0
  155. data/lib/standalone_ruby.rb +1 -1
  156. data/lib/utils/launcher_handler.rb +110 -110
  157. data/lib/version/version.rb +1 -1
  158. metadata +85 -3
@@ -1,7 +1,7 @@
1
- Set objShell = CreateObject("WScript.Shell")
2
-
3
- rubyPath = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "/STANDALONE_RUBY_PATH"
4
- scriptPath = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "/STANDALONE_MAIN_FILE"
5
-
6
- command = """" & rubyPath & """ """ & scriptPath & """"
7
- objShell.Run command, 1, False
1
+ Set objShell = CreateObject("WScript.Shell")
2
+
3
+ rubyPath = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "/STANDALONE_RUBY_PATH"
4
+ scriptPath = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "/STANDALONE_MAIN_FILE"
5
+
6
+ command = """" & rubyPath & """ """ & scriptPath & """"
7
+ objShell.Run command, 1, False
@@ -1,8 +1,8 @@
1
- Set objShell = CreateObject("WScript.Shell")
2
-
3
- rubyPath = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\STANDALONE_RUBY_PATH"
4
- scriptPath = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\STANDALONE_MAIN_FILE"
5
-
6
- command = """" & rubyPath & """ """ & scriptPath & """"
7
-
8
- objShell.Run command, 1, False
1
+ Set objShell = CreateObject("WScript.Shell")
2
+
3
+ rubyPath = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\STANDALONE_RUBY_PATH"
4
+ scriptPath = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\STANDALONE_MAIN_FILE"
5
+
6
+ command = """" & rubyPath & """ """ & scriptPath & """"
7
+
8
+ objShell.Run command, 1, False
data/lib/displayer.rb ADDED
@@ -0,0 +1,66 @@
1
+ require_relative 'logger_helper'
2
+ require_relative 'version/version'
3
+
4
+ class Displayer
5
+ def initialize(params)
6
+ @params = params
7
+ @logger = LoggerHelper.instance
8
+ end
9
+
10
+ def display_params
11
+ begin
12
+ puts("Working With:")
13
+
14
+ display_map = {
15
+ "Project Path" => @params[:project_path],
16
+ "Resource File" => @params[:resource_file],
17
+ "Exe File" => @params[:exe],
18
+ "Ruby Path" => @params[:ruby_path],
19
+ "Ruby Folder" => @params[:ruby_path] ? File.basename(@params[:ruby_path]) : nil,
20
+ "Main File" => @params[:main_file],
21
+ "Launcher" => @params[:launcher],
22
+ "Launcher Type" => @params[:launcher_type],
23
+ "Template" => @params[:template] || "Default Template",
24
+ "Log Path" => "Users Documents Directory"
25
+ }
26
+
27
+ display_text = display_map.map { |key, value| " - #{key}: #{value}" if value }.compact
28
+
29
+ puts display_text.join("\n") unless display_text.empty?
30
+
31
+ rescue => e
32
+ print("Display Error: ".red); puts(e.message.red)
33
+ @logger.error("Display Error: #{e.message}")
34
+ end
35
+ end
36
+
37
+
38
+ def banner
39
+ banner = -<<"BANNER"
40
+ Standalone-Ruby v#{StandaloneRuby::VERSION} - Package your Ruby projects as exe!
41
+ # Github: https://github.com/ardatetikbey/Standalone-Ruby
42
+ # RubyGems: https://rubygems.org/gems/standalone-ruby
43
+
44
+ BANNER
45
+
46
+ puts banner
47
+ end
48
+ end
49
+
50
+ class String
51
+ def red
52
+ "\e[31m#{self}\e[0m"
53
+ end
54
+
55
+ def green
56
+ "\e[32m#{self}\e[0m"
57
+ end
58
+
59
+ def magenta
60
+ "\e[35m#{self}\e[0m"
61
+ end
62
+
63
+ def yellow
64
+ "\e[33m#{self}\e[0m"
65
+ end
66
+ end
data/lib/exe_packer.rb ADDED
@@ -0,0 +1,82 @@
1
+ require_relative 'logger_helper'
2
+
3
+ class ExePacker
4
+ def initialize(params)
5
+ @params = params
6
+ @logger = LoggerHelper.instance
7
+ end
8
+
9
+ def pack
10
+ begin
11
+ stub_path = File.join(File.expand_path("data/exe_templates", __dir__), "launcher_stub.c")
12
+ @logger.info("Reading stub template from: #{stub_path}")
13
+
14
+ stub_content = File.read(stub_path)
15
+
16
+ stub_output = "#{File.join(@params[:project_path].to_s, "launcher_stub.c")}"
17
+ exe_path = "#{File.join(@params[:project_path].to_s, @params[:exe].to_s)}"
18
+
19
+ File.open(stub_output, 'w') { |f| f.write(stub_content) }
20
+
21
+ if @params[:use_gcc]
22
+ puts "\nChecking GCC and Windres..."
23
+ output = `where gcc`
24
+ gcc_path = output.strip
25
+
26
+ output = `where windres`
27
+ windres_path = output.strip
28
+
29
+ if File.exist?(output.strip)
30
+ puts "GCC Path: #{gcc_path}"
31
+ puts "Windres Path: #{windres_path}"
32
+
33
+ windres_command = "#{windres_path} #{@params[:resource_file].to_s} -O coff -o #{File.join(@params[:project_path].to_s, "program.o")}"
34
+ @logger.info("Running command: #{windres_command}")
35
+ `#{windres_command}`
36
+
37
+ gcc_command = "#{gcc_path} -o #{exe_path} #{File.join(@params[:project_path].to_s, "program.o")} #{stub_output}"
38
+ @logger.info("Running command: #{gcc_command}")
39
+ `#{gcc_command}`
40
+
41
+ File.delete("#{File.join(@params[:project_path].to_s, 'program.o')}")
42
+ @logger.info("program.o file deleted")
43
+ else
44
+ print("Error: ".red); puts("GCC could not be found!")
45
+ exit!
46
+ end
47
+ else
48
+ puts "\nUsing Tiny C Compiler (TCC)..."
49
+
50
+ tcc_path = File.join(File.expand_path("data/c_compilers/tcc", __dir__), "tcc.exe")
51
+ @logger.info("TCC Path: #{tcc_path}")
52
+
53
+ command = "#{tcc_path} -o #{exe_path} #{stub_output} -lkernel32"
54
+ @logger.info("Running command: #{command}")
55
+ `#{command}`
56
+ end
57
+
58
+ File.delete(stub_output)
59
+ @logger.info("Stub file deleted successfully")
60
+
61
+ puts("\nExe file has been generated!".green_bold_dark)
62
+ @logger.info("Exe file generated at: #{exe_path}")
63
+ rescue Exception => err
64
+ @logger.error("Error occurred: #{err.message}")
65
+ print("Error: ".red); puts(err.message)
66
+ end
67
+ end
68
+ end
69
+
70
+ class String
71
+ def red
72
+ "\e[31m#{self}\e[0m"
73
+ end
74
+
75
+ def yellow
76
+ "\e[33m#{self}\e[0m"
77
+ end
78
+
79
+ def green_bold_dark
80
+ "\e[1m\e[38;5;28m#{self}\e[0m"
81
+ end
82
+ end
data/lib/launcher.rb ADDED
@@ -0,0 +1,84 @@
1
+ require 'optparse'
2
+
3
+ require_relative 'displayer'
4
+ require_relative 'parameter_parser'
5
+ require_relative 'ruby_copy'
6
+ require_relative 'logger_helper'
7
+ require_relative 'exe_packer'
8
+ require_relative 'launcher_handler'
9
+
10
+
11
+ class Launcher
12
+ def initialize
13
+ @parser = ParameterParser.new
14
+ @parser.parse
15
+ @params = @parser.params
16
+
17
+ @displayer = Displayer.new(@params)
18
+ @ruby_copy = RubyCopy.new(@params)
19
+ @logger = LoggerHelper.instance
20
+ @exe_packer = ExePacker.new(@params)
21
+ @launcher_handler = LauncherHandler.new(@params)
22
+ end
23
+
24
+ def platform_analysis
25
+ case RUBY_PLATFORM
26
+ when /win32|mingw|cygwin/
27
+ @params[:platform] = 'Windows'
28
+ @logger.info("Working on windows platform.")
29
+ else
30
+ print("Error: ".red); puts("This platform is not supported! Exiting...")
31
+ @logger.error("This platform is not supported! Exiting...")
32
+ exit!
33
+ end
34
+ end
35
+
36
+ def run
37
+ begin
38
+ Signal.trap("INT") do
39
+ @logger.info("The program was closed because an interrupt command was detected.")
40
+ puts "\nProgram interrupted. Shutting down..."
41
+ exit(0)
42
+ end
43
+
44
+ platform_analysis
45
+
46
+ @logger.info("the executor function is started.")
47
+ @displayer.banner
48
+ @logger.info("Banner display was made.")
49
+ @displayer.display_params
50
+ @logger.info("The parameters entered by the user are reflected on the screen.")
51
+ @ruby_copy.robocopy_interpreter
52
+ @logger.info("Ruby interpreter copy function completed.")
53
+ @launcher_handler.handle
54
+ @logger.info("Launcher handler finished.")
55
+ @exe_packer.pack
56
+ @logger.info("Exe pack finished.")
57
+
58
+ if @params[:one_file_exe]
59
+ require_relative 'sfx_generator'
60
+ @sfx_generator = SFXGenerator.new(@params)
61
+ @sfx_generator.generate_sfx
62
+ end
63
+
64
+ print("\nWARNING: ".yellow); puts("Instead of changing the path of the created exe file, create a shortcut. The same applies here as in every application.")
65
+
66
+ puts("\nThis project is under development. If you encounter any errors, you can open an issue on Github.\nIf you want to make a suggestion, you can contact me.")
67
+ puts "Thanks for using Standalone-Ruby! Don't forget to star the project on Github."
68
+ @logger.info("Program finished.")
69
+ rescue Exception => e
70
+ @logger.error("Launcher Error: #{e.message}")
71
+ print("Launcher Error: "); puts("#{e.message}".red)
72
+ end
73
+ end
74
+ end
75
+
76
+ class String
77
+ def red
78
+ "\e[31m#{self}\e[0m"
79
+ end
80
+
81
+ def yellow
82
+ "\e[33m#{self}\e[0m"
83
+ end
84
+ end
@@ -0,0 +1,53 @@
1
+ require 'fileutils'
2
+
3
+ require_relative 'logger_helper'
4
+
5
+ class LauncherHandler
6
+ def initialize(params)
7
+ @params = params
8
+ @logger = LoggerHelper.instance
9
+ end
10
+
11
+ def handle
12
+ begin
13
+ puts("\nThe template creation process has been started.")
14
+
15
+ ruby_file = @params[:gui] ? "rubyw.exe" : "ruby.exe"
16
+
17
+ if @params[:gui] == true
18
+ vbs_template = File.join(File.expand_path("data/launcher_templates/vbs", __dir__), "vbs_gui.txt")
19
+ ruby_file = "rubyw.exe"
20
+ else
21
+ vbs_template = File.join(File.expand_path("data/launcher_templates/vbs", __dir__), "default_vbs.txt")
22
+ ruby_file = "ruby.exe"
23
+ end
24
+
25
+ puts "Using: #{vbs_template}"
26
+
27
+ if File.exist?(vbs_template)
28
+ content = File.read(vbs_template)
29
+ @logger.info("The content of the template has been read.")
30
+
31
+ content.gsub!("STANDALONE_RUBY_PATH", "#{File.join(File.basename(@params[:ruby_path].to_s), "bin", "#{ruby_file}")}")
32
+ @logger.info("Placed the defined Ruby interpreter path in the template.")
33
+
34
+ content.gsub!("STANDALONE_MAIN_FILE", "#{File.basename(@params[:main_file].to_s)}")
35
+ @logger.info("The main project file path defined in the template is placed.")
36
+
37
+ new_launcher_path = File.join(@params[:project_path].to_s, @params[:launcher_name].to_s)
38
+ File.open(new_launcher_path, "w") do |f_man|
39
+ f_man.puts content
40
+ end
41
+
42
+ @logger.info("New launcher file directory created as #{new_launcher_path.to_s}")
43
+ else
44
+ print("Handler Error: ".red); puts("The template file could not be found.")
45
+ @logger.error("Template file not found!")
46
+ exit!
47
+ end
48
+ rescue Exception => e
49
+ print("Handler Error: ".red); puts("#{e.message}")
50
+ @logger.error("Handler Error: #{e.message}")
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,24 @@
1
+ require 'logger'
2
+ require 'time'
3
+ require 'fileutils'
4
+
5
+ class LoggerHelper
6
+ def self.instance
7
+ documents_path = File.join(ENV['USERPROFILE'], 'Documents', 'standalone-ruby-logs')
8
+
9
+ FileUtils.mkdir_p(documents_path) unless Dir.exist?(documents_path)
10
+
11
+ timestamp = Time.now.strftime("%Y-%m-%d_%H-%M-%S")
12
+ log_file = File.join(documents_path, "standalone-ruby_#{timestamp}.log")
13
+
14
+ logger = Logger.new(log_file)
15
+ logger.level = Logger::INFO
16
+
17
+ logger.formatter = proc do |severity, datetime, progname, msg|
18
+ msg = "(empty message)" if msg.nil? || msg.strip.empty?
19
+ "#{datetime.strftime('%Y-%m-%d %H:%M:%S')} [#{severity}] #{msg}\n"
20
+ end
21
+
22
+ return logger
23
+ end
24
+ end
@@ -0,0 +1,210 @@
1
+ require 'fileutils'
2
+ require 'tmpdir'
3
+ require 'optparse'
4
+
5
+ require_relative 'logger_helper'
6
+ require_relative 'version/version'
7
+
8
+ class ParameterParser
9
+ def initialize
10
+ @params = {
11
+ threads: 5,
12
+ sfx_path: Dir.tmpdir,
13
+ exe: "program.exe",
14
+ resource_file: File.join(File.expand_path("data/resource_files", __dir__), "default.rc"),
15
+ launcher: "launcher.vbs",
16
+ launcher_name: "launcher.vbs",
17
+ launcher_type: "vbs"
18
+ }
19
+
20
+ @logger = LoggerHelper.instance
21
+ end
22
+
23
+ def normalize_paths!
24
+ @params.each do |key, value|
25
+ @params[key] = value.gsub('\\', '/') if value.is_a?(String)
26
+ end
27
+ end
28
+
29
+ def display_help
30
+ help_text = <<~EOT
31
+ Standalone-Ruby v#{StandaloneRuby::VERSION} - Convert your Ruby projects to exe files!
32
+
33
+ Usage: standalone-ruby [--help] [--project-path PROJECT_PATH] [--ruby-path RUBY_PATH] [--main-file MAIN_FILE] [--launcher LAUNCHER] [--gui]
34
+ [--template TEMPLATE] [--exe-file EXE_FILE] [--threads THREADS] [--resource-file resource_file] [--gcc] [--version]
35
+
36
+ Required Options:
37
+ --project-path PROJECT_PATH
38
+ Target Ruby project path.
39
+
40
+ --ruby RUBY_PATH
41
+ Path to the Ruby interpreter.
42
+
43
+ --main-file MAIN_FILE
44
+ Path to the main Ruby file of the project.
45
+
46
+ Extra Options:
47
+ --exe-file EXE_FILE
48
+ Name of the exe file to be used for output (default is program.exe).
49
+
50
+ --threads THREADS
51
+ Number of threads to use (default is 5). Determines the number of threads used during the Ruby interpreter
52
+ copy process and for Robocopy operations. A higher number of threads can speed up the process, but requires more system resources.
53
+
54
+ --resource-file RESOURCE_FILE
55
+ Resource file (.rc) for the exe file to be created. Only possible with MinGW.
56
+
57
+ --help
58
+ Show this help message and exit.
59
+
60
+ --version
61
+ Show program version and exit.
62
+
63
+ --gcc
64
+ Use GCC compiler for exe file.
65
+
66
+ --gui
67
+ This option allows the rubyw.exe file in the bin folder to be used.
68
+ You can choose it for projects that include GUI.
69
+
70
+ Notes:
71
+ - Make sure that the Ruby interpreter you are using includes all the gems required for the target project.
72
+ - The Ruby interpreter uses Robocopy for copying, and the number of threads given affects the speed of this operation.
73
+
74
+ For more details, please visit the documentation at:
75
+ https://github.com/ardatetikbey/Standalone-Ruby
76
+
77
+ EOT
78
+
79
+ puts help_text
80
+ end
81
+
82
+ def parse
83
+ begin
84
+ OptionParser.new do |opts|
85
+ note = "Note: https://github.com/ardatetikbey/Standalone-Ruby Don't forget to review my github document to get the best results."
86
+ opts.banner = "Usage: ruby #{$0} [options]\n#{note}"
87
+
88
+ opts.on("--sfx-path SFX_PATH") do |sfx_path|
89
+ @params[:sfx_path] = sfx_path
90
+ end
91
+
92
+ opts.on("--resource-file RESOURCE_FILE") do |resource_file|
93
+ if File.exist?(resource_file)
94
+ @params[:resource_file] = resource_file
95
+ else
96
+ print("Parser Error: ".red); puts("The specified resource file #{resource_file} could not be found!")
97
+ @logger.error("Parser Error: The specified resource file #{resource_file} could not be found!")
98
+ exit!
99
+ end
100
+ end
101
+
102
+ opts.on("--one-file-exe") do
103
+ @params[:one_file_exe] = true
104
+ end
105
+
106
+ opts.on("--ruby-path RUBY_PATH") do |ruby_path|
107
+ ruby_path.strip!
108
+ if Dir.exist?("#{ruby_path}")
109
+ if Dir.exist?(File.join(ruby_path, "bin"))
110
+ @params[:ruby_path] = ruby_path
111
+ end
112
+ else
113
+ print("Parser Error: ".red); puts("The specified Ruby path #{ruby_path} could not be found!")
114
+ @logger.error("Parser Error: The specified Ruby path #{ruby_path} could not be found!")
115
+ exit!
116
+ end
117
+ end
118
+
119
+ opts.on("--project-path PROJECT_PATH", String) do |project_path|
120
+ project_path.strip!
121
+ if Dir.exist?("#{project_path}")
122
+ @params[:project_path] = project_path
123
+ else
124
+ print("Parser Error: ".red); puts("The specified project path #{project_path} could not be found!")
125
+ @logger.error("Parser Error: The project path #{project_path} could not be found!")
126
+ exit!
127
+ end
128
+ end
129
+
130
+ opts.on("--exe-file EXE_FILE") do |exe|
131
+ @params[:exe] = exe
132
+ end
133
+
134
+ opts.on("--gcc") do
135
+ @params[:use_gcc] = true
136
+ end
137
+
138
+ opts.on("--main-file MAIN_FILE", String) do |main_file|
139
+ main_file.strip!
140
+ if File.exist?(main_file)
141
+ @params[:main_file] = main_file
142
+ else
143
+ print("Parser Error: ".red); puts("The specified file #{main_file} could not be found!")
144
+ @logger.error("Parser Error: The specified file #{main_file} could not be found!")
145
+ exit!
146
+ end
147
+ end
148
+
149
+ opts.on("--threads THREADS", Integer) do |threads|
150
+ if threads.is_a?(Integer)
151
+ @params[:threads] = threads
152
+ else
153
+ print("Parser Error: ".red); puts("Invalid value for threads. Please provide an integer.")
154
+ @logger.error("Parser Error: Invalid value for threads.")
155
+ exit!
156
+ end
157
+ end
158
+
159
+ opts.on("--gui") do
160
+ @params[:gui] = true
161
+ end
162
+
163
+ opts.on("--version") do
164
+ puts "Standalone Ruby Gem Version #{StandaloneRuby::VERSION}"
165
+ exit!
166
+ end
167
+
168
+ opts.on("--help") do
169
+ display_help
170
+ exit!
171
+ end
172
+ end.parse!
173
+
174
+ normalize_paths!
175
+
176
+ if @params[:project_path].nil? || @params[:ruby_path].nil? || @params[:main_file].nil?
177
+ print("Error: ".red); puts("Missing required parameters. Please provide the necessary parameters:\n -p, -r, -m.\nYou can use the -h parameter for the help menu.")
178
+ @logger.error("Parser Error: Missing required parameters.")
179
+ exit!
180
+ end
181
+
182
+ rescue Exception => e
183
+ print("Parser Error: ".red); puts("#{e.message}".red)
184
+ @logger.error("Parser Error: #{e.message}")
185
+ exit!
186
+ end
187
+ end
188
+
189
+ def params
190
+ @params
191
+ end
192
+ end
193
+
194
+ class String
195
+ def red
196
+ "\e[31m#{self}\e[0m"
197
+ end
198
+
199
+ def green
200
+ "\e[32m#{self}\e[0m"
201
+ end
202
+
203
+ def magenta
204
+ "\e[35m#{self}\e[0m"
205
+ end
206
+
207
+ def yellow
208
+ "\e[33m#{self}\e[0m"
209
+ end
210
+ end
data/lib/ruby_copy.rb ADDED
@@ -0,0 +1,26 @@
1
+ require_relative 'logger_helper'
2
+
3
+ class RubyCopy
4
+ def initialize(params)
5
+ @params = params
6
+ @logger = LoggerHelper.instance
7
+ end
8
+
9
+ def robocopy_interpreter
10
+ begin
11
+ puts("\nThe Ruby interpreter copying process has been started.")
12
+ print("WARNING: ".yellow); puts("If you are using a development kit, the copying process may take a long time.")
13
+
14
+ @logger.info("Robocopy process started using backticks.")
15
+ copy_output = `robocopy "#{@params[:ruby_path]}" "#{File.join(@params[:project_path].to_s, File.basename(@params[:ruby_path].to_s))}" /E /MT:#{@params[:threads].to_i} /V /ETA /NFL /NDL /R:1000000 /W:30 /NP`
16
+ puts "Robocopy Command: robocopy \"#{@params[:ruby_path]}\" \"#{File.join(@params[:project_path], File.basename(@params[:ruby_path]))}\" /E /MT:#{@params[:threads].to_i} /V /ETA /NFL /NDL /R:1000000 /W:30 /NP"
17
+
18
+ @logger.info("Robocopy output printed to screen.")
19
+
20
+ puts("The Ruby interpreter copying process has been completed.")
21
+ rescue Exception => e
22
+ print("Copy Error: ".red); puts("#{e.message}".red)
23
+ @logger.error("Copy Error: #{e.message}")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'logger_helper'
2
+
3
+ class SFXGenerator
4
+ def initialize(params)
5
+ @params = params
6
+ end
7
+
8
+ def generate_sfx
9
+
10
+ end
11
+ end
@@ -1,4 +1,4 @@
1
- require_relative 'utils/launcher'
1
+ require_relative 'launcher'
2
2
 
3
3
  class Program
4
4
  def run