I am making a program that is a launcher for a private server of a game. If i change the server, i have to change the client, so I want it to download only the changed files, and dont overwrite the old files. I am using dropbox to store the files. How can I do this?
-
create entry in database, set status to modified and access file with modified status – Nandkumar Tekale Aug 29 '12 at 09:40
-
there are like 1000 files, I cant do that – Aug 29 '12 at 09:41
-
you can store millions entries in db – Nandkumar Tekale Aug 29 '12 at 09:43
-
Yes, putting them in manually.. – Aug 29 '12 at 09:43
-
Could it be easier to generate a text files with the changes on the server, download the file, interpret it and then download the necesary files? – Aug 29 '12 at 09:53
3 Answers
In Java 7 you can get Notifications using WatchService
Using this API you can register to various events
ENTRY_CREATE – A directory entry is created.
ENTRY_DELETE – A directory entry is deleted.
ENTRY_MODIFY – A directory entry is modified.
OVERFLOW – Indicates that events might have been lost or discarded. You do not have to register for the OVERFLOW event to receive it.
The following code snippet shows how to register a Path instance for all three event types:
import static java.nio.file.StandardWatchEventKinds.*;
Path dir = ...;
try {
WatchKey key = dir.register(watcher,
ENTRY_CREATE,
ENTRY_DELETE,
ENTRY_MODIFY);
} catch (IOException x) {
System.err.println(x);
}
Using WatchEvent you can then call appropriate notification to your application that file is changed and download it

- 19,001
- 4
- 46
- 72
Maintain version of file on server side using DB or go for checksum to identify the modified file

- 237,923
- 42
- 401
- 438
-
+1 using the file size and modification date can be faster than computing a checksum. – Peter Lawrey Aug 29 '12 at 09:45
-
But these values are less reliable. Modification dates can be effected by touch, installers or other factors outside the developers control – MadProgrammer Aug 29 '12 at 09:49
I'd start by taking a look at the Dropbox SDK
I'd also make sure that each file on the server has a MD5 (other checksum) associated with it. You could download these checksums and compare them to the files you have installed on your local machine. If any of the checksums are different, then you can download the file you need.
Have a look at How can I generate an MD5 hash? and How do I generate an MD5 digest for a file

- 1
- 1

- 343,457
- 22
- 230
- 366