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 support for updating Drifty #316

Closed
wants to merge 84 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
0792c2c
Added checkUpdate() for Drifty_CLI.
kmr-rohit Oct 22, 2023
ace9e17
Added checkUpdate() for Drifty_CLI.
kmr-rohit Oct 23, 2023
7555e8c
Added checkUpdate() for Drifty_CLI.
kmr-rohit Oct 23, 2023
2eb1def
Added checkUpdate() for Drifty_CLI.
kmr-rohit Oct 23, 2023
f169723
Merge remote-tracking branch 'origin/kmrrohit' into kmrrohit
kmr-rohit Oct 23, 2023
9fc3c11
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Oct 23, 2023
d5b1754
fix: Merge conflicts along with missing symbols fixed
SaptarshiSarkar12 Oct 23, 2023
791f523
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Oct 24, 2023
dfa36ce
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Oct 24, 2023
2501187
Updated Implementation as Suggested.
kmr-rohit Oct 25, 2023
bfdcfd1
Updated Implementation as Suggested.
kmr-rohit Oct 25, 2023
8d0a476
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Oct 25, 2023
aa81c94
fix: Fixed merge conflicts and removed redundancy from Updater class …
SaptarshiSarkar12 Oct 25, 2023
4e30a4c
fix(ci): Fixed wrong directory name for updater package
SaptarshiSarkar12 Oct 26, 2023
80c106a
fix: Fixed linter and build ci issues
SaptarshiSarkar12 Oct 26, 2023
0f813ca
Merge branch 'kmrrohit' of https://github.com/kmr-rohit/Drifty into k…
SaptarshiSarkar12 Oct 26, 2023
06f63d6
fix: Fixed CI build issues and renamed some method parameters
SaptarshiSarkar12 Oct 26, 2023
4211d08
Merge branch 'master' into kmrrohit
kmr-rohit Oct 26, 2023
77399b0
fix: Fixed null pointer and IO exception in Updater class for log fil…
SaptarshiSarkar12 Oct 26, 2023
4de0370
Merge branch 'kmrrohit' of https://github.com/kmr-rohit/Drifty into k…
SaptarshiSarkar12 Oct 26, 2023
e0c6b07
fix: Removed test parameter from updater class
SaptarshiSarkar12 Oct 26, 2023
6accde5
fix: Added old executable delete call
SaptarshiSarkar12 Oct 26, 2023
61ffe93
fix: Removed `java.awt` and added `process.waitFor()` to wait for the…
SaptarshiSarkar12 Oct 26, 2023
9c83ea6
fix: Fixed duplicate log lines
SaptarshiSarkar12 Oct 26, 2023
b8b94ce
fix: Update for Drifty CLI and GUI working now
SaptarshiSarkar12 Oct 27, 2023
caf91e7
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Oct 27, 2023
35fa35d
fix: Fixed linter issues
SaptarshiSarkar12 Oct 27, 2023
21cc2ff
fix: Fixed linter issues
SaptarshiSarkar12 Oct 27, 2023
3d3710e
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Oct 30, 2023
6325fc1
fix: Fixed maven build error
SaptarshiSarkar12 Oct 30, 2023
a4b6453
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Oct 30, 2023
61f2273
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Oct 30, 2023
b944038
Merge branch 'SaptarshiSarkar12:master' into kmrrohit
kmr-rohit Oct 31, 2023
7cea908
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Oct 31, 2023
5f20535
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Oct 31, 2023
0ea3d8e
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Oct 31, 2023
e7d9df9
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 10, 2023
65d40ec
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 18, 2023
f9281a5
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 18, 2023
c3df06a
fix: Fixed build issues
SaptarshiSarkar12 Nov 18, 2023
857057a
fix: Fixed build issues
SaptarshiSarkar12 Nov 18, 2023
3160303
chore: Updated comments in Mode enum
SaptarshiSarkar12 Nov 18, 2023
4fb45bc
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 19, 2023
fdaacba
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
dfee770
fix: Fixed compilation failure: "Final variable can not be re-assigned"
SaptarshiSarkar12 Nov 20, 2023
f12640e
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
3dee47f
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
27695ff
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
0148bbc
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
08d7a54
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
3322c02
Commit message
github-actions[bot] Nov 20, 2023
a41e997
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
4f17fb2
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
e143312
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
82dc774
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
c3fa99f
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
a754e19
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
c9890cc
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
5370a6a
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
f77d1d5
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
c829e02
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 20, 2023
c8615ea
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 21, 2023
eb9be77
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 21, 2023
29fb6aa
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 21, 2023
537ff4e
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 21, 2023
33916d2
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 23, 2023
a0f00cc
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 23, 2023
28ddff9
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 23, 2023
d233778
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 23, 2023
44797bc
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 23, 2023
d48b5a5
chore: Added some spaces in Utility class to test if formatter works
SaptarshiSarkar12 Nov 23, 2023
2e2eb48
style: Formatted Java files
github-actions[bot] Nov 23, 2023
62f5ec8
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 23, 2023
beee02d
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 24, 2023
5bf83d4
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 24, 2023
71101f7
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 24, 2023
13d1aa5
style: Formatted Java files
github-actions[bot] Nov 24, 2023
2024e90
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 27, 2023
d1e5557
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 28, 2023
03a896f
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 28, 2023
3e504e1
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Nov 29, 2023
76ec1c6
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Dec 2, 2023
03f2a28
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Dec 2, 2023
2a0d597
Merge branch 'master' into kmrrohit
SaptarshiSarkar12 Dec 7, 2023
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
5 changes: 2 additions & 3 deletions .idea/misc.xml

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

Binary file added Drifty_GUI.exe
Binary file not shown.
125 changes: 108 additions & 17 deletions src/main/java/CLI/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import Backend.FileDownloader;
import Enums.MessageType;
import Enums.OS;
import GUI.Support.Job;
import GUI.Support.JobHistory;
import Preferences.AppSettings;
import Utils.*;
import org.yaml.snakeyaml.Yaml;
import Updater.Updater;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -29,15 +31,13 @@
public class Main {
public static final Logger LOGGER = Logger.getInstance();
protected static final Scanner SC = ScannerFactory.getInstance();
protected static JobHistory jobHistory;
protected static boolean isYoutubeURL;
protected static boolean isInstagramLink;
protected static boolean isSpotifyLink;
protected static boolean isInstagramImage;
private static MessageBroker messageBroker;
private static String link;
private static String downloadsFolder;
private static Utility utility;
private static String directory;
private static String fileName = null;
private static boolean batchDownloading;
private static String batchDownloadingFile;
Expand All @@ -48,12 +48,16 @@ public static void main(String[] args) {
LOGGER.log(MessageType.INFO, CLI_APPLICATION_STARTED);
messageBroker = new MessageBroker(System.out);
Environment.setMessageBroker(messageBroker);
if (checkUpdate()){
return;
};
messageBroker.msgInitInfo("Initializing environment...");
Environment.initializeEnvironment();
messageBroker.msgInitInfo("Environment initialized successfully!");
utility = new Utility();
jobHistory = AppSettings.GET.jobHistory();
printBanner();
String downloadsFolder;
if (args.length > 0) {
link = args[0];
String name = null;
Expand Down Expand Up @@ -93,12 +97,15 @@ public static void main(String[] args) {
messageBroker.msgLinkError("Link is invalid!");
}
if (isUrlValid) {
isYoutubeURL = isYoutube(link);
isInstagramLink = isInstagram(link);
if (name == null) {
if (fileName == null || fileName.isEmpty()) {
messageBroker.msgFilenameInfo("Retrieving filename from link...");
fileName = findFilenameInLink(link);
}
}
renameFilenameIfRequired(false);
downloadsFolder = location;
downloadsFolder = getProperDownloadsFolder(downloadsFolder);
Job job = new Job(link, downloadsFolder, fileName, false);
Expand Down Expand Up @@ -134,7 +141,7 @@ public static void main(String[] args) {
}
if (!batchDownloading) {
System.out.print(ENTER_FILE_LINK);
link = SC.next();
String link = SC.next();
SC.nextLine();
System.out.println("Validating link...");
if (Utility.isURL(link)) {
Expand All @@ -148,7 +155,6 @@ public static void main(String[] args) {
downloadsFolder = getProperDownloadsFolder(downloadsFolder);
isYoutubeURL = isYoutube(link);
isInstagramLink = isInstagram(link);
isSpotifyLink = isSpotify(link);
messageBroker.msgFilenameInfo("Retrieving filename from link...");
fileName = findFilenameInLink(link);
Job job = new Job(link, downloadsFolder, fileName, false);
Expand Down Expand Up @@ -189,16 +195,16 @@ private static void batchDownloader() {
if (data.containsKey("directory")) {
numberOfDirectories = 1;
if (data.get("directory").get(0).isEmpty()) {
downloadsFolder = ".";
directory = ".";
} else {
downloadsFolder = data.get("directory").get(0);
directory = data.get("directory").get(0);
}
} else if (data.containsKey("directories")) {
numberOfDirectories = data.get("directories").size();
} else {
messageBroker.msgDirInfo("No directory specified. Default downloads folder will be used.");
numberOfDirectories = 0;
downloadsFolder = ".";
directory = ".";
}
String linkMessage;
if (numberOfLinks == 1) {
Expand All @@ -225,7 +231,6 @@ private static void batchDownloader() {
messageBroker.msgLinkInfo("[" + (i + 1) + "/" + numberOfLinks + "] " + "Processing link : " + link);
isYoutubeURL = isYoutube(link);
isInstagramLink = isInstagram(link);
isSpotifyLink = isSpotify(link);
if (data.containsKey("fileNames") && !data.get("fileNames").get(i).isEmpty()) {
fileName = data.get("fileNames").get(i);
} else {
Expand All @@ -239,7 +244,7 @@ private static void batchDownloader() {
downloadsFolder = AppSettings.GET.lastDownloadFolder();
} else if (downloadsFolder.isEmpty()) {
try {
downloadsFolder = data.get("directories").get(i);
directory = data.get("directories").get(i);
} catch (Exception e) {
downloadsFolder = AppSettings.GET.lastDownloadFolder();
}
Expand All @@ -253,7 +258,7 @@ private static void batchDownloader() {
}

private static void renameFilenameIfRequired(boolean removeInputBufferFirst) { // Asks the user if the detected filename is to be used or not. If not, then the user is asked to enter a filename.
if ((fileName == null || (fileName.isEmpty())) && (!isYoutubeURL && !isInstagramLink && !isSpotifyLink)) {
if ((fileName == null || (fileName.isEmpty())) && (!isYoutubeURL && !isInstagramLink)) {
System.out.print(ENTER_FILE_NAME_WITH_EXTENSION);
if (removeInputBufferFirst) {
SC.nextLine();
Expand Down Expand Up @@ -330,7 +335,94 @@ public static void printBanner() {
System.out.println(ANSI_PURPLE + BANNER_BORDER + ANSI_RESET);
}

private static void checkHistoryAddJobsAndDownload(Job job, boolean removeInputBufferFirst) {
public static boolean checkUpdate() throws URISyntaxException {
SaptarshiSarkar12 marked this conversation as resolved.
Show resolved Hide resolved
SaptarshiSarkar12 marked this conversation as resolved.
Show resolved Hide resolved
String latestVersion = getLatestVersion();
if(isNewerVersion(latestVersion , VERSION_NUMBER)){
String Link = "";
String oldFilePath = String.valueOf(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
String newFilePath = "";
String OS_NAME = OS.getOSName();
if (OS_NAME.contains("win")) {
Link = "https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-CLI.exe";
String fileName = "Drifty_CLI.exe";
String dirPath = String.valueOf(Paths.get(System.getenv("LOCALAPPDATA"), "Drifty", "updates"));
FileDownloader downloader = new FileDownloader(Link , fileName , dirPath);
downloader.run();
newFilePath = dirPath +'\\' + fileName;
} else if (OS_NAME.contains("mac")) {
Link = "https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-CLI_macos";
String fileName = "Drifty-CLI_macos";
String dirPath = ".drifty/updates";
FileDownloader downloader = new FileDownloader(Link , fileName , dirPath);
downloader.run();
newFilePath = dirPath +'\\' + fileName;
} else if (OS_NAME.contains("linux")) {
Link = "https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-CLI_linux";
String fileName = "Drifty-CLI_linux";
String dirPath = ".drifty/updates";
FileDownloader downloader = new FileDownloader(Link, fileName, dirPath);
downloader.run();
newFilePath = dirPath +'\\' + fileName;
}
Updater.replaceUpdate(oldFilePath , newFilePath);
return true;
}
return false;
}

private static String getLatestVersion() {
try {
URL url = new URL("https://api.github.com/repos/SaptarshiSarkar12/Drifty/releases/latest");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");

BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String response = reader.readLine();
reader.close();

// Parse JSON response to get the "tag_name"
// For simplicity, we're assuming the tag_name is a string enclosed in double quotes
int start = response.indexOf("\"tag_name\":\"") + 12;
SaptarshiSarkar12 marked this conversation as resolved.
Show resolved Hide resolved
int end = response.indexOf("\"", start);
System.out.println( response.substring(start, end));
return response.substring(start, end);
} catch (Exception e) {
e.printStackTrace();
return null;
SaptarshiSarkar12 marked this conversation as resolved.
Show resolved Hide resolved
}
}

private static boolean isNewerVersion(String newVersion, String currentVersion) {
// Split version strings into arrays of integers
String[] newVersionParts = newVersion.replaceAll("[^\\d.]", "").split("\\.");
String[] currentVersionParts = currentVersion.replaceAll("[^\\d.]", "").split("\\.");

// Convert parts to integers
int[] newVersionNumbers = new int[newVersionParts.length];
int[] currentVersionNumbers = new int[currentVersionParts.length];

for (int i = 0; i < newVersionParts.length; i++) {
newVersionNumbers[i] = Integer.parseInt(newVersionParts[i]);
}

for (int i = 0; i < currentVersionParts.length; i++) {
currentVersionNumbers[i] = Integer.parseInt(currentVersionParts[i]);
}

// Compare version numbers
for (int i = 0; i < Math.min(newVersionNumbers.length, currentVersionNumbers.length); i++) {
if (newVersionNumbers[i] > currentVersionNumbers[i]) {
return true; // New version is greater
} else if (newVersionNumbers[i] < currentVersionNumbers[i]) {
return false; // Current version is greater
}
}

// If all compared parts are equal, consider the longer version as newer
return newVersionNumbers.length > currentVersionNumbers.length;
}

private static void checkHistoryAddJobsAndDownload(Job job, boolean removeInputBufferFirst) {
boolean doesFileExist = job.fileExists();
boolean hasHistory = jobHistory.exists(link);
boolean fileExistsHasHistory = doesFileExist && hasHistory;
Expand Down Expand Up @@ -371,8 +463,7 @@ private static void checkHistoryAddJobsAndDownload(Job job, boolean removeInputB
if (isSpotifyLink) {
link = Utility.getSpotifyDownloadLink(link);
}
FileDownloader downloader = new FileDownloader(link, fileName, downloadsFolder);
downloader.run();
}
}
}

}
Loading
Loading