- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -debug verbose
-include_lib("xmerl/include/xmerl.hrl").
-export([main/1, install_mod/1]).
-record(mod_info, { name :: string()
, links :: [{file:filepath(), file:filepath()}]
}).
main(Args) ->
[ModeDir, GameDir] = Args,
VirtualInstall = filename:absname(ModeDir ++ "/VirtualInstall/"),
RealPath = filename:absname(GameDir),
VirtualModCfg = VirtualInstall ++ "/VirtualModConfig.xml",
io:format( "Mode dir: ~p~n"
"Install dir: ~p~n"
"Current dir: ~p~n"
, [VirtualInstall, RealPath, element(2, file:get_cwd())]),
{Doc, []} = xmerl_scan:file(VirtualModCfg),
Mods = get_mods(VirtualInstall, RealPath, Doc),
[install_mod(I) || I <- Mods],
ok.
get_mods(VirtPath, RealPath, Doc) ->
[ #mod_info
{ name = xpath("/modInfo/@modName", Mod)
, links = get_links(VirtPath, RealPath, Mod)
}
|| Mod <- xmerl_xpath:string( "/virtualModActivator/modList/modInfo"
, Doc)].
get_links(VirtPath, RealPath, Doc) ->
[{ filename:absname( unixify(xpath("/fileLink/@realPath", FL))
, VirtPath)
, filename:absname( unixify(xpath("/fileLink/@virtualPath", FL))
, RealPath)
}
|| FL <- xmerl_xpath:string( "//fileLink[isActive = 'True']"
, Doc)].
xpath(Query, Doc) ->
case xmerl_xpath:string(Query, Doc) of
[#xmlAttribute{value = Val}] ->
Val
end.
unixify(Path) ->
lists:map(
fun($\\) -> $/;
(A) -> A
end,
Path).
install_mod(#mod_info{name = Name, links = Links}) ->
io:format("Installing ~s...~n", [Name]),
lists:foreach(
fun({From, To}) ->
filelib:ensure_dir(To),
file:make_symlink(From, To)
end,
Links).