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

Removed redundant code and other refactoring #193

15 changes: 15 additions & 0 deletions .idea/checkstyle-idea.xml

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

31 changes: 31 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.

31 changes: 31 additions & 0 deletions .idea/sonarlint/issuestore/index.pb

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

10 changes: 5 additions & 5 deletions Website/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fetch(
});

function download_alert_window() {
var w = confirm("Do you want to download Drifty?");
if (w == true) {
let w = confirm("Do you want to download Drifty?");
if (w === true) {
alert("Thanks for Downloading");
window.open(
"https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty_CLI.exe"
Expand All @@ -25,8 +25,8 @@ function download_alert_window() {
}

function download_alert_apple() {
var a = confirm("Do you want to download Drifty?");
if (a == true) {
let a = confirm("Do you want to download Drifty?");
if (a === true) {
alert("Thanks for Downloading");
window.open(
"https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty.jar"
Expand Down Expand Up @@ -248,7 +248,7 @@ function toggleMore(btn, id) {
function renderAssets(assets) {
return assets.reduce((all, asset) => {
//check if it is for windows
let is_windows = asset.name.split(".").pop().toLocaleLowerCase() == "exe";
let is_windows = asset.name.split(".").pop().toLocaleLowerCase() === "exe";

if (is_windows) {
return `${all} <a href="${asset.browser_download_url}">Download <i class="fab fa-windows"></i></a>`;
Expand Down
12 changes: 8 additions & 4 deletions src/CheckDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@
import java.nio.file.Files;
import java.nio.file.Path;

import static constants.DriftyConstants.*;

/**
* This class checks if a directory exists or not. if it doesn't, the directory is created.
*/
class CheckDirectory {
/**
* This constructor creates the directory if it does not exist.
*
bharathkalyans marked this conversation as resolved.
Show resolved Hide resolved
* @param dir Name of the folder where the user wants to download the file.
* @throws IOException when creating the directory fails.
*/
CheckDirectory(String dir) throws IOException {
if (!(checkIfFolderExists(dir))){
if (!(checkIfFolderExists(dir))) {
Path directory = FileSystems.getDefault().getPath(dir);
Files.createDirectory(directory);
Drifty_CLI.logger.log("INFO", "Directory Created");
Drifty_CLI.logger.log(LOGGER_INFO, DIRECTORY_CREATED);
}
}

/**
* This function checks if a folder exists or not.
*
bharathkalyans marked this conversation as resolved.
Show resolved Hide resolved
* @param folderName Name of the folder where the user wants to download the file.
* @return true if the folder exists and false if the folder is missing.
*/
Expand All @@ -34,8 +38,8 @@ private static boolean checkIfFolderExists(String folderName) {
found = true;
}
} catch (Exception e) {
System.out.println("Error while checking for directory !");
Drifty_CLI.logger.log("ERROR", "Error while checking for directory !");
System.out.println(ERROR_WHILE_CHECKING_FOR_DIRECTORY);
Drifty_CLI.logger.log(LOGGER_ERROR, ERROR_WHILE_CHECKING_FOR_DIRECTORY);
}
return found;
}
Expand Down
14 changes: 7 additions & 7 deletions src/DownloaderThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

public class DownloaderThread extends Thread{
public class DownloaderThread extends Thread {

private URL url;
private FileOutputStream file;
private long start;
private long end;
private final URL url;
private final long start;
private final long end;
private final FileOutputStream file;

public DownloaderThread(URL url, FileOutputStream file, long start, long end) {
this.url=url;
this.url = url;
this.file = file;
this.start = start;
this.end = end;
Expand All @@ -24,7 +24,7 @@ public void run() {
ReadableByteChannel readableByteChannel;
try {
URLConnection con = url.openConnection();
con.setRequestProperty("Range", "bytes="+start+"-"+end);
con.setRequestProperty("Range", "bytes=" + start + "-" + end);
con.connect();
readableByteChannel = Channels.newChannel(con.getInputStream());
file.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
Expand Down
Loading