Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added feature to perform in-place update of Drifty #562

Merged
merged 50 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b9c1406
feat: Added ability to perform in-place update of drifty
SaptarshiSarkar12 Jul 5, 2024
394539b
fix: fixed Linter issue
SaptarshiSarkar12 Jul 5, 2024
7e1ae44
fix: fixed Drifty GUI downloading wrong update file and also fixed so…
SaptarshiSarkar12 Jul 6, 2024
150655b
fix: fixed CWE-248 - NumberFormatException raised by CodeQL
SaptarshiSarkar12 Jul 6, 2024
951cff3
Merge branch 'master' into 217-drifty-update-feature
SaptarshiSarkar12 Jul 6, 2024
6a5f473
Merge branch 'master' of github.com:SaptarshiSarkar12/Drifty into 217…
SaptarshiSarkar12 Aug 16, 2024
22bab34
feat: Added support for updating Drifty GUI and CLI based on architec…
SaptarshiSarkar12 Aug 18, 2024
c73c17c
style: format codebase
github-actions[bot] Aug 18, 2024
da19c3b
fix(CI): Fixed linter issue
SaptarshiSarkar12 Aug 18, 2024
79e3401
Merge branch '217-drifty-update-feature' of github.com:SaptarshiSarka…
SaptarshiSarkar12 Aug 18, 2024
6e5cec5
debug: Added debug window to pop-up for windows msi if there's a lack…
SaptarshiSarkar12 Aug 19, 2024
2bac14b
debug: Added debug window to pop-up for windows msi if there's a lack…
SaptarshiSarkar12 Aug 19, 2024
297ece2
fix: Fixed delay in updating Drifty GUI when the download queue is no…
SaptarshiSarkar12 Aug 19, 2024
d163df3
fix: Fixed delay in updating Drifty GUI when the download queue is no…
SaptarshiSarkar12 Aug 19, 2024
c6eed7c
Merge branch 'master' of github.com:SaptarshiSarkar12/Drifty into 217…
SaptarshiSarkar12 Aug 19, 2024
bc80b71
debug: Added debug window to pop-up for windows msi if there's a lack…
SaptarshiSarkar12 Aug 19, 2024
9240fd4
debug: Removed debug window as write permissions are apparently avail…
SaptarshiSarkar12 Aug 20, 2024
9dff7c2
fix: Fixed the usage of temporary drifty update directory for future …
SaptarshiSarkar12 Aug 20, 2024
28ddd7c
debug: Moved log file to a visible area for better monitoring of upda…
SaptarshiSarkar12 Aug 20, 2024
300de23
debug: Moved log file to a visible area for better monitoring of upda…
SaptarshiSarkar12 Aug 20, 2024
b04674b
debug: Narrow down the update failure to the code for replacing execu…
SaptarshiSarkar12 Aug 20, 2024
f6d5d59
debug: Narrow down the update failure to the code for replacing execu…
SaptarshiSarkar12 Aug 20, 2024
ada0206
debug: Added log instructions to get an idea of the permissions avail…
SaptarshiSarkar12 Aug 20, 2024
ea97819
fix: Fixed permission detection for windows msi
SaptarshiSarkar12 Aug 20, 2024
7f94067
fix: Fixed permission detection for windows, linux and mac (for mac, …
SaptarshiSarkar12 Aug 20, 2024
cafd6d8
fix(CI): Fixed linter issue
SaptarshiSarkar12 Aug 20, 2024
bf01672
style: format codebase
github-actions[bot] Aug 20, 2024
b33becf
fix: Fixed NullPointerException while creating log during initialization
SaptarshiSarkar12 Aug 20, 2024
5b435fa
Merge branch '217-drifty-update-feature' of github.com:SaptarshiSarka…
SaptarshiSarkar12 Aug 20, 2024
8666990
fix: Fixed unchecked admin privileges during initialization period of…
SaptarshiSarkar12 Aug 20, 2024
8318490
Merge branch 'master' into 217-drifty-update-feature
SaptarshiSarkar12 Aug 29, 2024
2a48dcc
Merge branch 'master' of github.com:SaptarshiSarkar12/Drifty into 217…
SaptarshiSarkar12 Aug 31, 2024
8f8ecc5
fix: Added a copy instead of move for Windows update check
SaptarshiSarkar12 Aug 31, 2024
edd0144
Merge branch '217-drifty-update-feature' of github.com:SaptarshiSarka…
SaptarshiSarkar12 Aug 31, 2024
0d21287
Merge branch 'master' into 217-drifty-update-feature
SaptarshiSarkar12 Sep 4, 2024
010989d
fix: Added `deleteOnExit()` command to delete '.old' executable for w…
SaptarshiSarkar12 Sep 4, 2024
c34abbf
Merge branch 'master' of github.com:SaptarshiSarkar12/Drifty into 217…
SaptarshiSarkar12 Sep 5, 2024
818da97
fix: Added a fix for exe update in windows
SaptarshiSarkar12 Sep 5, 2024
f6dbbca
fix(CI): Fixed linter issues
SaptarshiSarkar12 Sep 5, 2024
7eed5c9
Merge branch 'master' into 217-drifty-update-feature
SaptarshiSarkar12 Sep 5, 2024
92d81d3
fix: the old exe will get deleted now and added check for update menu…
SaptarshiSarkar12 Sep 6, 2024
f247169
chore: Removed the resizability of confirmation dialog
SaptarshiSarkar12 Sep 6, 2024
320ef2e
chore: Removed unnecessary code lines previously added for debug purp…
SaptarshiSarkar12 Sep 6, 2024
a097918
style: format codebase
github-actions[bot] Sep 6, 2024
fb404cb
fix: Fixed CoderabbitAI's reviews
SaptarshiSarkar12 Sep 6, 2024
6c7d831
Merge branch 'master' of github.com:SaptarshiSarkar12/Drifty into 217…
SaptarshiSarkar12 Sep 7, 2024
e13a1ab
fix: Fixed CoderabbitAI's reviews
SaptarshiSarkar12 Sep 7, 2024
3f5e869
chore: Removed the version number modification previously made solely…
SaptarshiSarkar12 Sep 7, 2024
b8e6204
Merge branch 'master' into 217-drifty-update-feature
SaptarshiSarkar12 Sep 7, 2024
667f592
Merge branch 'master' into 217-drifty-update-feature
SaptarshiSarkar12 Sep 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions CLI/src/main/java/cli/support/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ public class Constants extends support.Constants {
public static final String HELP_FLAG = "--help";
public static final String NAME_FLAG = "--name";
public static final String VERSION_FLAG = "--version";
public static final String UPDATE_FLAG = "--update";
public static final String EARLY_ACCESS_FLAG = "--early-access";
public static final String LOCATION_FLAG = "--location";
public static final String BATCH_FLAG = "--batch";
public static final String HELP_FLAG_SHORT = "-h";
public static final String NAME_FLAG_SHORT = "-n";
public static final String VERSION_FLAG_SHORT = "-v";
public static final String UPDATE_FLAG_SHORT = "-u";
public static final String EARLY_ACCESS_FLAG_SHORT = "-ea";
public static final String LOCATION_FLAG_SHORT = "-l";
public static final String BATCH_FLAG_SHORT = "-b";
public static final String REMOVE_ALL_URL_CONFIRMATION = "Are you sure you wish to delete ALL links? (Y/N): ";
Expand Down
28 changes: 28 additions & 0 deletions CLI/src/main/java/cli/updater/CLIUpdateExecutor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cli.updater;

import java.io.File;

public class CLIUpdateExecutor extends updater.UpdateExecutor {
public CLIUpdateExecutor(File currentExecutableFile, File latestExecutableFile) {
super(currentExecutableFile, latestExecutableFile);
}

@Override
public boolean execute() {
M.msgLogInfo("Setting executable permission for the latest version of Drifty...");
if (setLatestExecutablePermissions()) {
M.msgLogInfo("Executable permission set! Executing update...");
} else {
M.msgUpdateError("Failed to set executable permission for the latest version of Drifty!");
return false;
}
cleanup(true); // This will delete the old executable created previously
if (renameCurrentExecutable()) {
if (replaceCurrentExecutable()) {
cleanup(false);
return true;
}
}
return false;
}
}
4 changes: 4 additions & 0 deletions CLI/src/main/java/cli/utils/MessageBroker.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ public void msgHistoryWarning(String message, boolean endWithNewLine) {
this.endWithNewLine = endWithNewLine;
sendMessage(message, MessageType.WARN, MessageCategory.HISTORY);
}

public void msgUpdateWarning(String message) {
sendMessage(message, MessageType.WARN, MessageCategory.UPDATE);
}
}
28 changes: 16 additions & 12 deletions CLI/src/main/java/cli/utils/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,40 @@ public static String findFilenameInLink(String link) {
for (String json : Objects.requireNonNull(linkMetadataList)) {
filename = Utility.getFilenameFromJson(json);
}
if (filename.isEmpty()) {
msgBroker.msgFilenameError("Filename detection failed: No filename found in metadata!");
return null;
}
} else {
// Example: "example.com/file.txt" prints "Filename detected: file.txt"
// example.com/file.json -> file.json
String file = link.substring(link.lastIndexOf("/") + 1);
if (file.isEmpty()) {
M.msgFilenameError(FILENAME_DETECTION_ERROR);
msgBroker.msgFilenameError(FILENAME_DETECTION_ERROR);
return null;
}
int index = file.lastIndexOf(".");
if (index < 0) {
M.msgFilenameError(FILENAME_DETECTION_ERROR);
msgBroker.msgFilenameError(FILENAME_DETECTION_ERROR);
return null;
}
String extension = file.substring(index);
// edge case 1: "example.com/."
if (extension.length() == 1) {
M.msgFilenameError(FILENAME_DETECTION_ERROR);
msgBroker.msgFilenameError(FILENAME_DETECTION_ERROR);
return null;
}
// file.png?width=200 -> file.png
filename = file.split("([?])")[0];
M.msgFilenameInfo(FILENAME_DETECTED + "\"" + filename + "\"");
msgBroker.msgFilenameInfo(FILENAME_DETECTED + "\"" + filename + "\"");
}
return filename;
}

public boolean yesNoValidation(String input, String printMessage) {
while (input.isEmpty()) {
Environment.getMessageBroker().msgInputError(ENTER_Y_OR_N, true);
M.msgLogError(ENTER_Y_OR_N);
msgBroker.msgLogError(ENTER_Y_OR_N);
Environment.getMessageBroker().msgInputInfo(printMessage, false);
input = SC.nextLine().toLowerCase();
}
Expand All @@ -62,7 +66,7 @@ public boolean yesNoValidation(String input, String printMessage) {
return false;
} else {
Environment.getMessageBroker().msgInputError("Invalid input!", true);
M.msgLogError("Invalid input!");
msgBroker.msgLogError("Invalid input!");
Environment.getMessageBroker().msgInputInfo(printMessage, false);
input = SC.nextLine().toLowerCase();
return yesNoValidation(input, printMessage);
Expand All @@ -82,26 +86,26 @@ public static String getSpotifyDownloadLink(String spotifyMetadataJson) {
ArrayList<HashMap<String, Object>> searchResults = getYoutubeSearchResults(query, true);
boolean searchedWithFilters = true;
if (searchResults == null) {
M.msgLogError("Failed to get search results for the song with filters! Trying without filters ...");
msgBroker.msgLogError("Failed to get search results for the song with filters! Trying without filters ...");
SaptarshiSarkar12 marked this conversation as resolved.
Show resolved Hide resolved
searchResults = getYoutubeSearchResults(query, false);
searchedWithFilters = false;
if (searchResults == null) {
M.msgDownloadError("Song is exclusive to Spotify and cannot be downloaded!");
msgBroker.msgDownloadError("Song is exclusive to Spotify and cannot be downloaded!");
return null;
}
}
String matchedId = getMatchingVideoID(Objects.requireNonNull(searchResults), duration, artistNames);
if (matchedId.isEmpty()) {
if (searchedWithFilters) {
M.msgLogError("Failed to get a matching video ID for the song with filters! Trying without filters ...");
msgBroker.msgLogError("Failed to get a matching video ID for the song with filters! Trying without filters ...");
searchResults = getYoutubeSearchResults(query, false);
matchedId = getMatchingVideoID(Objects.requireNonNull(searchResults), duration, artistNames);
if (matchedId.isEmpty()) {
M.msgDownloadError("Song is exclusive to Spotify and cannot be downloaded!");
msgBroker.msgDownloadError("Song is exclusive to Spotify and cannot be downloaded!");
return null;
}
} else {
M.msgDownloadError("Song is exclusive to Spotify and cannot be downloaded!");
msgBroker.msgDownloadError("Song is exclusive to Spotify and cannot be downloaded!");
return null;
}
}
Expand All @@ -114,7 +118,7 @@ public static Yaml getYamlParser() {
loaderOptions.setAllowRecursiveKeys(false);
loaderOptions.setProcessComments(false);
Yaml yamlParser = new Yaml(new SafeConstructor(loaderOptions));
M.msgLogInfo("YAML parser initialized successfully");
msgBroker.msgLogInfo("YAML parser initialized successfully");
return yamlParser;
}
}
Loading
Loading