mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-08 16:28:00 -06:00
Add some comments
This commit is contained in:
@@ -134,19 +134,23 @@ public class HttpSync extends Thread {
|
||||
|
||||
TransferFile remoteFile = findInFileArray(remoteFiles, localFile.filename);
|
||||
|
||||
|
||||
// Check if the file is a meta file, and uploads it based off of the setting
|
||||
boolean sendField = (sendMetaFiles || !(localFile.filename.endsWith(".fields")));
|
||||
|
||||
boolean shouldUpload;
|
||||
boolean special;
|
||||
|
||||
// If there is no file on the sever, upload.
|
||||
if(remoteFile == null) {
|
||||
shouldUpload = true;
|
||||
special = false;
|
||||
}
|
||||
else {
|
||||
// If the remote file is the same as the local one, do nothing.
|
||||
boolean checksumsEqual = Objects.equals(localFile.checksum, remoteFile.checksum);
|
||||
// If the local file is a colabarray, give it a special propreties
|
||||
special = FileEditor.requiresSpecialInteraction(remoteFile.filename);
|
||||
// If the local file is updated after the remote file
|
||||
boolean after = after(localFile.updated, remoteFile.updated);
|
||||
|
||||
shouldUpload = !checksumsEqual && (special || after);
|
||||
@@ -172,11 +176,15 @@ public class HttpSync extends Thread {
|
||||
|
||||
boolean shouldUpload;
|
||||
|
||||
// If there is no file on the sever, upload.
|
||||
if(localFile == null) {
|
||||
shouldUpload = true;
|
||||
} else {
|
||||
// If the remote file is the same as the local one, do nothing.
|
||||
boolean checksumsEqual = !Objects.equals(localFile.checksum, remoteFile.checksum);
|
||||
// If the local file is updated after the remote file
|
||||
boolean after = after(remoteFile.updated, localFile.updated);
|
||||
// If the local file and remote file's upload dates are exactly the same
|
||||
boolean datesEqual = !localFile.updated.equals(remoteFile.updated);
|
||||
|
||||
shouldUpload = (!checksumsEqual && (after) && !datesEqual);
|
||||
@@ -195,7 +203,7 @@ public class HttpSync extends Thread {
|
||||
setUpdateIndicator("Downloading " + (Math.floor((double) (i * 1000) / remoteFiles.size()) / 10) + "%");
|
||||
}
|
||||
|
||||
|
||||
// Remove files marked for deletion
|
||||
ToDelete.deleteFiles();
|
||||
|
||||
setUpdateIndicator("Finished, " + upCount + " Up, " + downCount + " Down");
|
||||
@@ -206,6 +214,7 @@ public class HttpSync extends Thread {
|
||||
}
|
||||
|
||||
|
||||
// Find file based off of filename
|
||||
private TransferFile findInFileArray(List<TransferFile> files, String filename){
|
||||
for(TransferFile file : files) {
|
||||
if(file.filename.equals(filename))
|
||||
@@ -214,10 +223,12 @@ public class HttpSync extends Thread {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get teh last modified date of a file
|
||||
private Date getLocalFileUtcTimestamp(File file) {
|
||||
return new Date(file.lastModified());
|
||||
}
|
||||
|
||||
// Load the local metadata of files
|
||||
private void getLocalFileMetadata() {
|
||||
File localDir = new File(baseDir);
|
||||
File[] localFileNames = localDir.listFiles();
|
||||
@@ -273,9 +284,12 @@ public class HttpSync extends Thread {
|
||||
await();
|
||||
}
|
||||
|
||||
// Create HTTP request to upload file
|
||||
void uploadFile(TransferFile tf, String serverURL, String apiKey, boolean special) {
|
||||
runningRequest.set(false);
|
||||
|
||||
|
||||
// If the file is "special", download the server copy and merge the local and remote ColabArrays
|
||||
if(special) {
|
||||
HttpGetFile getTask = new HttpGetFile(serverURL + "/api/" + tf.filename, new File(baseDir + tf.filename), (stream, error) -> {
|
||||
if(error != null) {
|
||||
@@ -314,7 +328,7 @@ public class HttpSync extends Thread {
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
// Upload the file
|
||||
HttpPutFile uploadTask = new HttpPutFile(serverURL + "/api/" + tf.filename, new File(baseDir + tf.filename), error -> {
|
||||
if (error != null)
|
||||
AlertManager.error(error);
|
||||
@@ -333,6 +347,8 @@ public class HttpSync extends Thread {
|
||||
private void setLocalFileTimestamp(File file, Date date) {
|
||||
file.setLastModified(date.getTime());
|
||||
}
|
||||
|
||||
// Download a file from the remote server
|
||||
void downloadFile(TransferFile tf, String serverURL) {
|
||||
runningRequest.set(false);
|
||||
File f = new File(baseDir + tf.filename);
|
||||
|
||||
@@ -5,6 +5,7 @@ import static com.ridgebotics.ridgescout.utility.DataManager.match_values;
|
||||
import static com.ridgebotics.ridgescout.utility.DataManager.pit_transferValues;
|
||||
import static com.ridgebotics.ridgescout.utility.DataManager.pit_values;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
|
||||
import com.ridgebotics.ridgescout.scoutingData.ScoutingDataWriter;
|
||||
@@ -36,18 +37,17 @@ import java.util.zip.Inflater;
|
||||
|
||||
// Helper class for binary editing
|
||||
public final class FileEditor {
|
||||
@SuppressLint("SdCardPath")
|
||||
public final static String baseDir = "/data/data/com.ridgebotics.ridgescout/";
|
||||
public static final byte internalDataVersion = 0x01;
|
||||
public static final int maxCompressedBlockSize = 4096;
|
||||
public static final int lengthHeaderBytes = 3;
|
||||
|
||||
|
||||
public static final String TBAAddress = "https://www.thebluealliance.com/api/v3/";
|
||||
|
||||
// Hardcoded API key go brrr
|
||||
public static final String TBAHeader = "X-TBA-Auth-Key: tjEKSZojAU2pgbs2mBt06SKyOakVhLutj3NwuxLTxPKQPLih11aCIwRIVFXKzY4e";
|
||||
|
||||
// private TimeZone localTimeZone = TimeZone.getDefault();
|
||||
|
||||
|
||||
|
||||
public static String binaryVisualize(byte[] bytes){
|
||||
String returnStr = "";
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
// Class to download remote file.
|
||||
public class HttpGetFile extends AsyncTask<Void, Integer, File> {
|
||||
|
||||
public interface DownloadCallback {
|
||||
@@ -136,8 +137,7 @@ public class HttpGetFile extends AsyncTask<Void, Integer, File> {
|
||||
return response.toString();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
AlertManager.error(e);
|
||||
// Log.e(TAG, "Error reading error response", e);
|
||||
AlertManager.error("Error reading error response", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -145,9 +145,9 @@ public class HttpGetFile extends AsyncTask<Void, Integer, File> {
|
||||
private void deletePartialFile() {
|
||||
if (destinationFile != null && destinationFile.exists()) {
|
||||
if (destinationFile.delete()) {
|
||||
// Log.d(TAG, "Partial download file deleted");
|
||||
AlertManager.error("Partial download file deleted");
|
||||
} else {
|
||||
// Log.w(TAG, "Failed to delete partial download file");
|
||||
AlertManager.error("Failed to delete partial download file");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,15 +156,13 @@ public class HttpGetFile extends AsyncTask<Void, Integer, File> {
|
||||
try {
|
||||
if (inputStream != null) inputStream.close();
|
||||
} catch (IOException e) {
|
||||
AlertManager.error(e);
|
||||
// Log.e(TAG, "Error closing input stream", e);
|
||||
AlertManager.error("Error closing input stream", e);
|
||||
}
|
||||
|
||||
try {
|
||||
if (outputStream != null) outputStream.close();
|
||||
} catch (IOException e) {
|
||||
AlertManager.error(e);
|
||||
// Log.e(TAG, "Error closing output stream", e);
|
||||
AlertManager.error("Error closing output stream", e);
|
||||
}
|
||||
|
||||
if (connection != null) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
// Class to send HTTP PUT request to upload file
|
||||
public class HttpPutFile extends AsyncTask<Void, Integer, Boolean> {
|
||||
|
||||
// private static final String TAG = "FileUploadTask";
|
||||
@@ -102,8 +103,8 @@ public class HttpPutFile extends AsyncTask<Void, Integer, Boolean> {
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
AlertManager.error(e);
|
||||
errorMessage = "Upload error: " + e.getMessage();
|
||||
AlertManager.error(errorMessage, e);
|
||||
// Log.e(TAG, errorMessage, e);
|
||||
return false;
|
||||
} finally {
|
||||
@@ -140,25 +141,23 @@ public class HttpPutFile extends AsyncTask<Void, Integer, Boolean> {
|
||||
return response.toString();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
AlertManager.error(e);
|
||||
// Log.e(TAG, "Error reading error response", e);
|
||||
AlertManager.error("Error reading error response", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Clean up stream
|
||||
private void closeResources(InputStream inputStream, OutputStream outputStream, HttpURLConnection connection) {
|
||||
try {
|
||||
if (inputStream != null) inputStream.close();
|
||||
} catch (IOException e) {
|
||||
AlertManager.error(e);
|
||||
// Log.e(TAG, "Error closing input stream", e);
|
||||
AlertManager.error("Error closing input stream", e);
|
||||
}
|
||||
|
||||
try {
|
||||
if (outputStream != null) outputStream.close();
|
||||
} catch (IOException e) {
|
||||
AlertManager.error(e);
|
||||
// Log.e(TAG, "Error closing output stream", e);
|
||||
AlertManager.error("Error closing output stream", e);
|
||||
}
|
||||
|
||||
if (connection != null) {
|
||||
|
||||
Reference in New Issue
Block a user