4
4
import java .nio .file .Path ;
5
5
import java .nio .file .Paths ;
6
6
import java .util .ArrayList ;
7
- import java .util .HashMap ;
8
7
import java .util .List ;
9
8
10
9
import com .superzanti .serversync .util .FileIgnoreMatcher ;
11
10
import com .superzanti .serversync .util .FileIncludeMatcher ;
12
11
import com .superzanti .serversync .util .Logger ;
12
+ import com .superzanti .serversync .util .MinecraftModInformation ;
13
13
import com .superzanti .serversync .util .PathUtils ;
14
14
import com .superzanti .serversync .util .Server ;
15
15
import com .superzanti .serversync .util .SyncFile ;
@@ -82,6 +82,10 @@ private void closeWorker() {
82
82
}
83
83
84
84
private void populateClientFiles (ArrayList <String > directories ) {
85
+ populateClientFiles (directories , false );
86
+ }
87
+
88
+ private void populateClientFiles (ArrayList <String > directories , boolean ignoreRules ) {
85
89
List <Path > clientFilePaths = new ArrayList <>();
86
90
List <Path > clientConfigPaths = PathUtils .fileListDeep (Paths .get ("config/" ));
87
91
clientFiles = new ArrayList <SyncFile >(200 );
@@ -101,7 +105,7 @@ private void populateClientFiles(ArrayList<String> directories) {
101
105
FileIgnoreMatcher ignoredFiles = new FileIgnoreMatcher ();
102
106
103
107
for (Path path : clientFilePaths ) {
104
- if (ignoredFiles .matches (path )) {
108
+ if (! ignoreRules && ignoredFiles .matches (path )) {
105
109
Logger .log (Main .strings .getString ("ignoring" ) + " " + path .toString ());
106
110
} else {
107
111
clientFiles .add (SyncFile .StandardSyncFile (path ));
@@ -113,7 +117,7 @@ private void populateClientFiles(ArrayList<String> directories) {
113
117
FileIncludeMatcher includedFiles = new FileIncludeMatcher ();
114
118
115
119
for (Path path : clientConfigPaths ) {
116
- if (includedFiles .matches (path )) {
120
+ if (ignoreRules || includedFiles .matches (path )) {
117
121
clientFiles .add (SyncFile .ConfigSyncFile (path ));
118
122
}
119
123
}
@@ -150,19 +154,10 @@ public void run() {
150
154
151
155
populateClientFiles (syncableDirectories );
152
156
153
- Logger .log (Main .strings .getString ("config_check" ));
154
-
155
- // TODO is this needed now? check against last updated perhaps
156
- if (!server .getConfig ()) {
157
- Logger .error ("Failed to obtain config from server" );
158
- errorInUpdates = true ;
159
- closeWorker ();
160
- return ;
161
- }
162
-
163
157
Logger .debug ("Checking Server.isUpdateNeeded()" );
164
158
Logger .debug (clientFiles .toString ());
165
159
updateNeeded = server .isUpdateNeeded (clientFiles );
160
+ updateNeeded = true ; // TEMP
166
161
167
162
/* MAIN PROCESSING CHUNK */
168
163
if (updateNeeded ) {
@@ -245,9 +240,8 @@ public void run() {
245
240
Logger .debug (e );
246
241
}
247
242
} else {
248
- // only need to check for ignore here as we are working
249
- // on the servers file tree
250
- if (serverFile .matchesIgnoreListPattern () && !serverFile .isClientSideOnlyFile ) {
243
+ // Ignore support for client only files, users may wish to not allow some mods out of personal preference
244
+ if (serverFile .isClientSideOnlyFile && serverFile .matchesIgnoreListPattern ()) {
251
245
Logger .log ("<>" + Main .strings .getString ("ignoring" ) + " " + serverFile .getFileName ());
252
246
} else {
253
247
Logger .debug (serverFile .getFileName () + " " + Main .strings .getString ("does_not_exist" ));
@@ -268,31 +262,8 @@ public void run() {
268
262
Logger .debug (Main .strings .getString ("ignoring" ) + " " + clientFile .getFileName ());
269
263
} else {
270
264
Logger .debug (Main .strings .getString ("client_check" ) + " " + clientFile .getFileName ());
271
-
272
- boolean servedByServer = false ;
273
- for (SyncFile ignoredClientFile : ignoredClientSideFiles ) {
274
- // Client side files provided by the server
275
- try {
276
- if (clientFile .equals (ignoredClientFile )) {
277
- servedByServer = true ;
278
- break ;
279
- }
280
- } catch (InvalidSyncFileException e ) {
281
- //TODO stub invalid sync file handling
282
- e .printStackTrace ();
283
- }
284
- }
285
- if (servedByServer ) {
286
- Logger .debug (Main .strings .getString ("ignoring" ) + " " + clientFile .getFileName ());
287
- continue ;
288
- }
289
-
290
- boolean exists = server .modExists (clientFile );
291
-
292
- if (!exists ) {
293
- Logger .debug (clientFile .getFileName () + " " + Main .strings .getString ("does_not_match" )
294
- + Main .strings .getString ("delete_attempt" ));
295
-
265
+
266
+ if (!serverFiles .contains (clientFile )) {
296
267
if (clientFile .delete ()) {
297
268
Logger .log (
298
269
"<>" + clientFile .getFileName () + " " + Main .strings .getString ("delete_success" ));
@@ -301,26 +272,34 @@ public void run() {
301
272
}
302
273
updateHappened = true ;
303
274
}
275
+
304
276
Main .clientGUI .updateProgress ((int ) (currentPercent / percentScale ));
305
277
}
306
278
}
307
279
308
280
//TODO complete this with user prompt to pick which duplicate to keep
309
281
/* DUPLICATE CHECK */
310
- populateClientFiles (syncableDirectories );
311
- HashMap <String , SyncFile > modList = new HashMap <String , SyncFile >(200 );
282
+ populateClientFiles (syncableDirectories , true );
283
+ ArrayList <String > modNames = new ArrayList <>(200 );
284
+ ArrayList <String > modHashes = new ArrayList <>(200 );
312
285
ArrayList <SyncFile > dupes = new ArrayList <SyncFile >(10 );
313
286
for (SyncFile clientFile : clientFiles ) {
314
- if ( clientFile .getModInformation () != null ) {
315
- System . out . println ( clientFile . getFileName ());
316
- if (modList . get ( clientFile . getModInformation (). name ) != null ) {
317
- Logger .log ("<!> Potential duplicate: " + clientFile .getFileName () + " - " + clientFile . getModInformation () .name );
287
+ MinecraftModInformation modInfo = clientFile .getModInformation ();
288
+ if ( modInfo != null ) {
289
+ if (modNames . contains ( modInfo . name )) {
290
+ Logger .log ("<!> Potential duplicate: " + clientFile .getFileName () + " - " + modInfo .name );
318
291
dupes .add (clientFile );
319
292
} else {
320
- modList . put ( clientFile . getModInformation (). name , clientFile );
293
+ modNames . add ( modInfo . name );
321
294
}
322
295
} else {
323
- //TODO what to do when the file has no mod information available
296
+ String hash = clientFile .getFileHash ();
297
+ if (modHashes .contains (hash )) {
298
+ Logger .log ("<!> Potential duplicate: " + clientFile .getFileName () + " - " + hash );
299
+ dupes .add (clientFile );
300
+ } else {
301
+ modHashes .add (hash );
302
+ }
324
303
}
325
304
}
326
305
System .out .println (dupes );
0 commit comments