2

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?

3 Answers3

3

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

Amit Deshpande
  • 19,001
  • 4
  • 46
  • 72
1

Maintain version of file on server side using DB or go for checksum to identify the modified file

jmj
  • 237,923
  • 42
  • 401
  • 438
0

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

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366