39
39
* Class to manage UCI chess engines.
40
40
*/
41
41
public class EngineManager {
42
- public static final String DATA_PATH = "/data/data/org.scid.android/" ;
43
42
private static final String ENGINE_DATA_FILE = "engines.xml" ;
44
43
private static final String INTERNAL_ENGINE_NAME = "Stockfish 5" ;
45
44
private static EngineConfig defaultEngine ;
@@ -85,32 +84,15 @@ public interface EngineChangeListener {
85
84
public void engineChanged (EngineChangeEvent event );
86
85
}
87
86
88
- private static EngineManager instance = new EngineManager ();
89
-
90
- /**
91
- * Gets the singleton instance of the manager.
92
- *
93
- * @return The manager singleton.
94
- */
95
- public static EngineManager getInstance () {
96
- return instance ;
97
- }
98
-
99
- public EngineManager () {
87
+ public EngineManager (Context context ) {
88
+ this .context = context ;
100
89
// Establish the default engine
101
- defaultEngine = new EngineConfig (INTERNAL_ENGINE_NAME , DATA_PATH
102
- + getInternalEngineFileName (), null , 0 );
90
+ defaultEngine = new EngineConfig (INTERNAL_ENGINE_NAME , context
91
+ . getFilesDir (). getPath () + getInternalEngineFileName (), null , 0 );
103
92
}
104
93
105
- /**
106
- * Sets the application context for the manager to use. The application
107
- * context is needed for displaying dialogs and accessing resource strings.
108
- *
109
- * @param context
110
- * The application context.
111
- */
112
- public void setContext (Context context ) {
113
- this .context = context ;
94
+ public String getFilesDir () {
95
+ return context .getFilesDir ().getPath ();
114
96
}
115
97
116
98
public void addEngineChangeListener (EngineChangeListener listener ) {
@@ -135,7 +117,7 @@ public void removeEngineChangeListener(EngineChangeListener listener) {
135
117
*
136
118
* @return The default EngineConfig.
137
119
*/
138
- public static EngineConfig getDefaultEngine () {
120
+ public EngineConfig getDefaultEngine () {
139
121
return defaultEngine ;
140
122
}
141
123
@@ -234,7 +216,7 @@ public boolean addEngine(String engineName, String executable,
234
216
String enginePackage , int engineVersion ) {
235
217
EngineConfig engine = getEnginesList ().get (engineName );
236
218
if (engine == null ) {
237
- File engineFile = new File (DATA_PATH + executable );
219
+ File engineFile = new File (context . getFilesDir (), executable );
238
220
String engineAbsPath = engineFile .getAbsolutePath ();
239
221
boolean engineExists = engineFile .exists ();
240
222
if (!engineExists ) {
@@ -290,7 +272,7 @@ private void addOpenExchangeEngine(String executable, String engineAbsPath,
290
272
found = true ;
291
273
try {
292
274
openEngine .copyToFiles (context .getContentResolver (),
293
- new File ( DATA_PATH ));
275
+ context . getFilesDir ( ));
294
276
Toast .makeText (
295
277
context ,
296
278
context .getString (R .string .engine_added_copied ,
@@ -429,7 +411,8 @@ private void saveEngineData(Map<String, EngineConfig> enginesList) {
429
411
if (Log .isLoggable ("SCID" , Log .DEBUG ))
430
412
Log .d ("SCID" , "Engine XML: " + writer .toString ());
431
413
432
- File engineDataFile = new File (DATA_PATH + ENGINE_DATA_FILE );
414
+ File engineDataFile = new File (context .getFilesDir (),
415
+ ENGINE_DATA_FILE );
433
416
fw = new FileWriter (engineDataFile );
434
417
fw .write (writer .toString ());
435
418
fw .close ();
@@ -464,7 +447,7 @@ private Map<String, EngineConfig> getEnginesList() {
464
447
*/
465
448
private void loadEngineData () {
466
449
TreeMap <String , EngineConfig > list = new TreeMap <String , EngineConfig >();
467
- File engineDataFile = new File (DATA_PATH + ENGINE_DATA_FILE );
450
+ File engineDataFile = new File (context . getFilesDir (), ENGINE_DATA_FILE );
468
451
if (engineDataFile .exists ()) {
469
452
FileReader fr = null ;
470
453
try {
@@ -584,7 +567,7 @@ protected Boolean doInBackground(File... params) {
584
567
if (!canceled ) {
585
568
if (Log .isLoggable ("SCID" , Log .INFO ))
586
569
Log .i ("SCID" , srcFile .getName () + " copied to "
587
- + DATA_PATH );
570
+ + context . getFilesDir (). getPath () );
588
571
result = Boolean .TRUE ;
589
572
}
590
573
} catch (IOException e ) {
0 commit comments