EnumeratorModuleFolder.java
3.79 KB
1
2
3
4
5
6
7
8
9
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* This file is part of LiteLoader.
* Copyright (C) 2012-16 Adam Mummery-Smith
* All Rights Reserved.
*/
package com.mumfrey.liteloader.core.api;
import java.io.File;
import com.mumfrey.liteloader.interfaces.ModularEnumerator;
import com.mumfrey.liteloader.launch.LoaderEnvironment;
import com.mumfrey.liteloader.launch.LoaderProperties;
import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
/**
* Enumerator module which searches for mods and tweaks in a folder
*
* @author Adam Mummery-Smith
*/
public class EnumeratorModuleFolder extends EnumeratorModuleFiles
{
protected File directory;
protected boolean readJarFiles;
protected boolean loadTweaks;
protected boolean forceInjection;
/**
* True if this is a versioned folder and the enumerator should also try to
* load tweak jars which would normally be ignored.
*/
protected final boolean loadTweakJars;
public EnumeratorModuleFolder(LiteLoaderCoreAPI api, ContainerEnvironment containers, File directory, boolean loadTweakJars)
{
super(api, containers);
this.directory = directory;
this.loadTweakJars = loadTweakJars;
}
@Override
public void init(LoaderEnvironment environment, LoaderProperties properties)
{
this.loadTweaks = properties.loadTweaksEnabled();
this.readJarFiles = properties.getAndStoreBooleanProperty(LoaderProperties.OPTION_SEARCH_JARFILES, true);
this.forceInjection = properties.getAndStoreBooleanProperty(LoaderProperties.OPTION_FORCE_INJECTION, false);
this.api.writeDiscoverySettings();
}
/**
* Write settings
*/
@Override
public void writeSettings(LoaderEnvironment environment, LoaderProperties properties)
{
properties.setBooleanProperty(LoaderProperties.OPTION_SEARCH_JARFILES, this.readJarFiles);
properties.setBooleanProperty(LoaderProperties.OPTION_FORCE_INJECTION, this.forceInjection);
}
@Override
protected boolean forceInjection()
{
return this.forceInjection;
}
@Override
protected boolean loadTweakJars()
{
return this.loadTweakJars;
}
@Override
protected boolean loadTweaks()
{
return this.loadTweaks;
}
@Override
protected boolean readJarFiles()
{
return this.readJarFiles;
}
@Override
protected File[] getFiles()
{
return this.directory.listFiles(this.getFilenameFilter());
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return this.directory.getAbsolutePath();
}
/**
* Get the directory this module will inspect
*/
public File getDirectory()
{
return this.directory;
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.core.Enumerator
* #enumerate(com.mumfrey.liteloader.core.EnabledModsList,
* java.lang.String)
*/
@Override
public void enumerate(ModularEnumerator enumerator, String profile)
{
if (this.directory.exists() && this.directory.isDirectory())
{
LiteLoaderLogger.info("Discovering valid mod files in folder %s", this.directory.getPath());
this.findValidFiles(enumerator);
}
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.api.EnumeratorModule#register(
* com.mumfrey.liteloader.interfaces.ModularEnumerator,
* java.lang.String)
*/
@Override
public void register(ModularEnumerator enumerator, String profile)
{
if (this.directory.exists() && this.directory.isDirectory())
{
LiteLoaderLogger.info("Registering discovered mod files in folder %s", this.directory.getPath());
this.sortAndRegisterFiles(enumerator);
}
}
}