Created
June 1, 2014 01:59
-
-
Save Taraflex/bce7d5d10b07b9d29c5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ; | |
import haxe.ds.StringMap; | |
import sys.io.File; | |
import sys.FileSystem; | |
/** | |
* ... | |
* @author qw01_01 | |
*/ | |
class Main | |
{ | |
static var formats = new StringMap<StringMap<String>>(); | |
inline static function getformat(file:String):String { | |
if (FileSystem.isDirectory(file)) | |
return "/"; | |
return file.split(".").pop(); | |
} | |
static function main() | |
{ | |
var args = Sys.args(); | |
if (args.length < 1) | |
return; | |
try { | |
var d = StringTools.replace(File.getContent("launcher.cfg"), "\\", "/"); | |
var curentSection:StringMap<String> = null; | |
for (s in d.split("\n")) { | |
s = StringTools.trim(s); | |
if (s.charAt(0) == "[") { | |
var a = s.substring(1, s.length-1).split(","); | |
curentSection = new StringMap<String>(); | |
for (sectionname in a) { | |
formats.set(StringTools.trim(sectionname), curentSection); | |
} | |
}else { | |
var a = s.split("="); | |
if (a.length == 2 && a[0].length>0 && a[1].length>0) { | |
curentSection.set(StringTools.trim(a[0]), StringTools.trim(a[1])); | |
} | |
} | |
} | |
}catch (e:Dynamic) { | |
} | |
var pr = args.shift(); | |
if (Std.string(Std.parseInt(pr)) == pr && args.length > 0) { | |
run(pr,args.join(" ")); | |
}else { | |
run("default",Sys.args().join(" ")); | |
} | |
} | |
static function run(programName:String, file:String) { | |
var format = getformat(file); | |
if (formats.exists(format)) { | |
var c = formats.get(format); | |
if (c.exists(programName)) { | |
cmd(c.get(programName),file); | |
}else | |
cmd(file); | |
}else | |
cmd(file); | |
} | |
inline static function cmd(c:String, args:String = null) { | |
if(args==null) | |
Sys.command('"$c"'); | |
else { | |
Sys.command("call", [c,args]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment