@@ -52,6 +52,7 @@ public class TTRUpdater extends JFrame {
5252 public final Logger logger = LogManager .getLogger (this );
5353
5454 public TTRUpdater (String title , Path installLocation ) throws IOException {
55+ // setup the window elements
5556 JFrame frame = new JFrame (title );
5657 frame .setSize (370 , 150 );
5758 frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
@@ -83,6 +84,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
8384 frame .setVisible (true );
8485 frame .setLocationRelativeTo (null );
8586
87+ // don't run the updater if the folder doesn't exist
8688 if (!installLocation .toFile ().exists ()) {
8789 JOptionPane .showMessageDialog (
8890 frame ,
@@ -95,6 +97,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
9597
9698 logger .info ("We are checking for TTR updates!" );
9799 String patchesJSONRaw = null ;
100+ // read the TTR api to get the files the game needs
98101 URL url = new URL (PATCHES_URL );
99102 URLConnection conn = url .openConnection ();
100103 conn .setRequestProperty (
@@ -118,6 +121,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
118121 frame .dispose ();
119122 }
120123
124+ // if the patchmanifest.txt is empty, it most likely won't be but just in case
121125 if (patchesJSONRaw == null ) {
122126 JFrame errorWindow = new ErrorWindow ("patchmanifest.txt returned empty." );
123127 logger .error (
@@ -132,6 +136,10 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
132136
133137 String osType = null ;
134138
139+ // set which OS we are using
140+ // ttr labels all files for which OS they will be attached to
141+ // windows = win32/win64
142+ // linux = linux/linux2
135143 if (SystemUtils .IS_OS_WINDOWS ) {
136144 osType = "win32" ;
137145 }
@@ -148,14 +156,19 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
148156 }
149157
150158 progressBar .setMaximum (patches .length ());
159+
160+ // this loops through the JSON
161+ // key is the file name
151162 for (String key : patches .keySet ()) {
152163 progressBar .setValue (progressBar .getValue () + 1 );
153164 JSONObject currentFile = (JSONObject ) patches .get (key );
154165 String onlineHash = currentFile .getString ("hash" );
166+ // get the list of OS's the file is for
155167 List <String > only =
156168 currentFile .getJSONArray ("only" ).toList ().stream ()
157169 .map (object -> Objects .toString (object , null ))
158170 .collect (Collectors .toList ());
171+ // if we are running the OS the file is for, check it
159172 if (only .contains (osType )) {
160173 File localFile = new File (installLocation + File .separator + key );
161174 updateStatus .setText ("Checking file " + localFile .getName ());
@@ -170,6 +183,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
170183 continue ;
171184 }
172185
186+ // the file exists locally, check the SHA1 and compare it to TTR's
173187 String localHash ;
174188 try {
175189 localHash = calcSHA1 (localFile );
@@ -205,6 +219,9 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
205219 "-----------------------------------------------------------------------" );
206220 }
207221 }
222+
223+ // we store files we need to download in filesToDownload
224+ // if there are files in that list, download them
208225 if (filesToDownload .size () > 0 ) {
209226 File tempFolder = new File ("temp" );
210227 if (!tempFolder .exists () && !tempFolder .mkdirs ()) {
@@ -219,6 +236,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
219236
220237 progressBar .setValue (0 ); //reset
221238
239+ // download each file
222240 for (String fileToDownload : filesToDownload ) {
223241 progressBar .setMaximum (fileToDownload .length ());
224242 JSONObject file = patches .getJSONObject (fileToDownload );
@@ -251,7 +269,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
251269 updateStatus .setText ("Extracting file " + dl );
252270 progressBar .setVisible (false );
253271 try {
254- extractFile (dl , fileToDownload );
272+ extractFile (dl , fileToDownload ); // extract the file to the new location
255273 } catch (IOException e ) {
256274 logger .error ("Unable to extract file" + dl , e );
257275 JFrame errorWindow =
@@ -272,6 +290,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
272290 System .nanoTime () - startTime , TimeUnit .NANOSECONDS )
273291 + " seconds." );
274292 }
293+ // delete the temp folder is there are files in there
275294 File [] tempFolderFiles = tempFolder .listFiles ();
276295 if (tempFolderFiles != null ) {
277296 for (File currentFile : tempFolderFiles ) {
0 commit comments