modsvaskr 0.1.11 → 0.2.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.
@@ -1,106 +1,110 @@
1
- require 'open-uri'
2
- require 'tmpdir'
3
- require 'nokogiri'
4
-
5
- module Modsvaskr
6
-
7
- module Games
8
-
9
- # Handle a Skyrim installation
10
- class SkyrimSe < Game
11
-
12
- # Initialize the game
13
- # [API] - This method is optional
14
- def init
15
- @tmp_dir = "#{Dir.tmpdir}/modsvaskr"
16
- end
17
-
18
- # Complete the game menu
19
- # [API] - This method is optional
20
- #
21
- # Parameters::
22
- # * *menu* (CursesMenu): Menu to complete
23
- def complete_game_menu(menu)
24
- menu.item 'Install SKSE64' do
25
- install_skse64
26
- out 'Press Enter to continue...'
27
- wait_for_user_enter
28
- end
29
- end
30
-
31
- # Get the game running executable name (that can be found in a tasks manager)
32
- # [API] - This method is mandatory
33
- #
34
- # Result::
35
- # * String: The running exe name
36
- def running_exe
37
- 'SkyrimSE.exe'
38
- end
39
-
40
- # Ordered list of default esps present in the game (the ones in the Data folder when 0 mod is being used).
41
- # The list is ordered according to the game's load order.
42
- # [API] - This method is mandatory
43
- #
44
- # Result::
45
- # * Array<String>: List of esp/esm/esl base file names.
46
- def game_esps
47
- %w[
48
- skyrim.esm
49
- update.esm
50
- dawnguard.esm
51
- hearthfires.esm
52
- dragonborn.esm
53
- ]
54
- end
55
-
56
- # Get the load order.
57
- # [API] - This method is mandatory
58
- #
59
- # Result::
60
- # * Array<String>: List of all active plugins, including masters
61
- def load_order
62
- game_esps +
63
- File.read("#{ENV['USERPROFILE']}/AppData/Local/Skyrim Special Edition/plugins.txt").split("\n").map do |line|
64
- line =~ /^\*(.+)$/ ? $1.downcase : nil
65
- end.compact
66
- end
67
-
68
- private
69
-
70
- # Install SKSE64 corresponding to our game
71
- def install_skse64
72
- doc = Nokogiri::HTML(URI.open('https://skse.silverlock.org/'))
73
- p_element = doc.css('p').find { |el| el.text.strip =~ /^Current SE build .+: 7z archive$/ }
74
- if p_element.nil?
75
- log '!!! Can\'t get SKSE64 from https://skse.silverlock.org/. It looks like the page structure has changed. Please update the code or install it manually.'
76
- else
77
- url = "https://skse.silverlock.org/#{p_element.at('a')['href']}"
78
- path = "#{@tmp_dir}/skse64.7z"
79
- FileUtils.mkdir_p File.dirname(path)
80
- log "Download from #{url} => #{path}..."
81
- URI.open(url, 'rb') do |web_io|
82
- File.write(path, web_io.read, mode: 'wb')
83
- end
84
- skse64_tmp_dir = "#{@tmp_dir}/skse64"
85
- log "Unzip into #{skse64_tmp_dir}..."
86
- FileUtils.rm_rf skse64_tmp_dir
87
- FileUtils.mkdir_p skse64_tmp_dir
88
- run_cmd(
89
- {
90
- dir: @config.seven_zip_path,
91
- exe: '7z.exe'
92
- },
93
- args: ['x', "\"#{path}\"", "-o\"#{skse64_tmp_dir}\"", '-r']
94
- )
95
- skse64_subdir = Dir.glob("#{skse64_tmp_dir}/*").first
96
- log "Move files from #{skse64_subdir} to #{self.path}..."
97
- FileUtils.cp_r "#{skse64_subdir}/.", self.path, remove_destination: true
98
- log 'SKSE64 installed successfully.'
99
- end
100
- end
101
-
102
- end
103
-
104
- end
105
-
106
- end
1
+ require 'open-uri'
2
+ require 'tmpdir'
3
+ require 'nokogiri'
4
+
5
+ module Modsvaskr
6
+
7
+ module Games
8
+
9
+ # Handle a Skyrim installation
10
+ class SkyrimSe < Game
11
+
12
+ # Initialize the game
13
+ # [API] - This method is optional
14
+ def init
15
+ @tmp_dir = "#{Dir.tmpdir}/modsvaskr"
16
+ end
17
+
18
+ # Complete the game menu
19
+ # [API] - This method is optional
20
+ #
21
+ # Parameters::
22
+ # * *menu* (CursesMenu): Menu to complete
23
+ def complete_game_menu(menu)
24
+ menu.item 'Install SKSE64' do
25
+ install_skse64
26
+ out 'Press Enter to continue...'
27
+ wait_for_user_enter
28
+ end
29
+ end
30
+
31
+ # Get the game running executable name (that can be found in a tasks manager)
32
+ # [API] - This method is mandatory
33
+ #
34
+ # Result::
35
+ # * String: The running exe name
36
+ def running_exe
37
+ 'SkyrimSE.exe'
38
+ end
39
+
40
+ # Ordered list of default esps present in the game (the ones in the Data folder when 0 mod is being used).
41
+ # The list is ordered according to the game's load order.
42
+ # [API] - This method is mandatory
43
+ #
44
+ # Result::
45
+ # * Array<String>: List of esp/esm/esl base file names.
46
+ def game_esps
47
+ %w[
48
+ skyrim.esm
49
+ update.esm
50
+ dawnguard.esm
51
+ hearthfires.esm
52
+ dragonborn.esm
53
+ ccbgssse001-fish.esm
54
+ ccqdrsse001-survivalmode.esl
55
+ ccbgssse037-curios.esl
56
+ ccbgssse025-advdsgs.esm
57
+ ]
58
+ end
59
+
60
+ # Read the load order.
61
+ # [API] - This method is mandatory
62
+ #
63
+ # Result::
64
+ # * Array<String>: List of all active plugins, including masters
65
+ def read_load_order
66
+ game_esps +
67
+ File.read("#{ENV.fetch('USERPROFILE')}/AppData/Local/Skyrim Special Edition/plugins.txt").split("\n").map do |line|
68
+ line =~ /^\*(.+)$/ ? Regexp.last_match(1).downcase : nil
69
+ end.compact
70
+ end
71
+
72
+ private
73
+
74
+ # Install SKSE64 corresponding to our game
75
+ def install_skse64
76
+ doc = Nokogiri::HTML(URI.open('https://skse.silverlock.org/'))
77
+ p_element = doc.css('p').find { |el| el.text.strip =~ /^Current SE build .+: 7z archive$/ }
78
+ if p_element.nil?
79
+ log '!!! Can\'t get SKSE64 from https://skse.silverlock.org/. It looks like the page structure has changed. Please update the code or install it manually.'
80
+ else
81
+ url = "https://skse.silverlock.org/#{p_element.at('a')['href']}"
82
+ path = "#{@tmp_dir}/skse64.7z"
83
+ FileUtils.mkdir_p File.dirname(path)
84
+ log "Download from #{url} => #{path}..."
85
+ URI.parse(url).open('rb') do |web_io|
86
+ File.write(path, web_io.read, mode: 'wb')
87
+ end
88
+ skse64_tmp_dir = "#{@tmp_dir}/skse64"
89
+ log "Unzip into #{skse64_tmp_dir}..."
90
+ FileUtils.rm_rf skse64_tmp_dir
91
+ FileUtils.mkdir_p skse64_tmp_dir
92
+ run_cmd(
93
+ {
94
+ dir: @config.seven_zip_path,
95
+ exe: '7z.exe'
96
+ },
97
+ args: ['x', "\"#{path}\"", "-o\"#{skse64_tmp_dir}\"", '-r']
98
+ )
99
+ skse64_subdir = Dir.glob("#{skse64_tmp_dir}/*").first
100
+ log "Move files from #{skse64_subdir} to #{self.path}..."
101
+ FileUtils.cp_r "#{skse64_subdir}/.", self.path, remove_destination: true
102
+ log 'SKSE64 installed successfully.'
103
+ end
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+
110
+ end