Class: LaunchCraft
- Inherits:
-
Object
- Object
- LaunchCraft
- Defined in:
- lib/launchcraft/version.rb,
lib/launchcraft.rb,
lib/launchcraft/auth.rb,
lib/launchcraft/java.rb,
lib/launchcraft/java.rb,
lib/launchcraft/config.rb,
lib/launchcraft/update.rb,
lib/launchcraft/md5_file.rb
Overview
– Copyleft shura. [ [email protected] ]
This file is part of launchcraft.
launchcraft is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
launchcraft is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with launchcraft. If not, see <www.gnu.org/licenses/>. ++
Defined Under Namespace
Constant Summary collapse
- Config =
Class.new(Hash) { def initialize rehash end def rehash @path = File.join(LaunchCraft.working_dir, 'options.txt') set_default File.file?(@path) ? parse : save end def []= (key, value) super(key.to_s, value.to_s) end def to_s map {|*kv| kv.join(':') }.join("\n") end def save File.open(@path, 'wb') {|f| f.write to_s } end protected def set_default update({ 'music' => '1.0', 'sound' => '1.0', 'invertYMouse' => 'false', 'mouseSensitivity' => '0.5', 'fov' => '0.0', 'gamma' => '0.0', 'viewDistance' => '0', 'guiScale' => '0', 'bobView' => 'false', 'anaglyph3d' => 'false', 'advancedOpengl' => 'false', 'fpsLimit' => '1', 'difficulty' => '0', 'fancyGraphics' => 'true', 'ao' => 'false', 'skin' => 'Default', 'lastServer' => '', 'url.login' => 'https://login.minecraft.net/', 'url.joinserver' => 'http://session.minecraft.net/game/joinserver.jsp', 'url.skins' => 'http://s3.amazonaws.com/MinecraftSkins/', 'url.resources' => 'http://s3.amazonaws.com/MinecraftResources/', 'url.download' => 'http://s3.amazonaws.com/MinecraftDownload/', 'url.has_paid' => 'https://login.minecraft.net/session', 'url.cloacks' => 'http://s3.amazonaws.com/MinecraftCloaks/', 'key_key.attack' => '-100', 'key_key.use' => '-99', 'key_key.forward' => '17', 'key_key.left' => '30', 'key_key.back' => '31', 'key_key.right' => '32', 'key_key.jump' => '57', 'key_key.sneak' => '42', 'key_key.drop' => '16', 'key_key.inventory' => '18', 'key_key.chat' => '20', 'key_key.playerList' => '15', 'key_key.pickItem' => '-98', }) end def parse update(Hash[File.read(@path).split(/\r?\n/).map {|line| next if line =~ /^\s*#/ line.split(':', 2) }]) save end }.new
- VERSION =
'0.0.1.4.2'.freeze
- MD5File =
Class.new { attr_accessor :lwjgl, :jinput, :lwjgl_util, :minecraft attr_accessor "#{OS.parse.to_s.gsub(/^macos$/, 'macosx')}_natives".to_sym def initialize rehash end def rehash @path = File.join(LaunchCraft.working_dir, 'bin', 'md5s') self.lwjgl = self.jinput = self.lwjgl_util = self.minecraft = self.natives = nil parse if File.file?(@path) end "#{OS.parse.to_s.gsub(/^macos$/, 'macosx')}_natives".tap {|m| alias_method :natives, m.to_sym alias_method :natives=, "#{m}=".to_sym } def to_s n = OS.parse.to_s.gsub(/^macos$/, 'macosx') "#md5 hashes for downloaded files\nlwjgl.jar=#{@lwjgl}\njinput.jar=#{@jinput}\n" + "lwjgl_util.jar=#{@lwjgl_util}\n#{n}_natives.jar.lzma=" + "#{instance_variable_get("@#{n}_natives")}\nminecraft.jar=#{@minecraft}" end def save File.open(@path, 'wb') {|f| f.write to_s } end protected def parse File.read(@path).split(/\r?\n/).each {|line| next if line =~ /^\s*#/ key, value = line.split('=', 2).map(&:strip) instance_variable_set("@#{key.split('.').first}".to_sym, value) } end }.new
Class Method Summary collapse
Class Method Details
.appname ⇒ Object
24 25 26 |
# File 'lib/launchcraft.rb', line 24 def self.appname @appname ||= 'minecraft' end |
.appname=(name) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/launchcraft.rb', line 28 def self.appname=(name) @appname = name.to_s Config.rehash MD5File.rehash @appname end |
.working_dir(appname = self.appname) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/launchcraft.rb', line 35 def self.working_dir (appname=self.appname) res = case OS.parse when :linux, :solaris File.join(ENV['HOME'], ".#{appname}") when :windows File.join(ENV['APPDATA'] || ENV['HOME'], ".#{appname}") when :macos File.join(ENV['HOME'], 'Library', 'Application Support', appname) else File.join(ENV['HOME'], appname) end Dir.mkdir(res) unless File.directory?(res) %w[bin resources saves screenshots stats texturepacks].each {|dir| dir = File.join(res, dir) Dir.mkdir(dir) unless File.directory?(dir) } return res end |