Updater now works with spaces in file paths
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.seibel.distanthorizons.coreapi.util.jar;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.file.Files;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -19,13 +20,18 @@ public class DeleteOnUnlock
|
||||
|
||||
|
||||
/**
|
||||
* @param args Takes whatever the first argument is, treats it as a file, and deletes it once a process lock is lifted from it
|
||||
* @param args Takes whatever the first argument is, treats it as a file, and deletes it once a process lock is lifted from it <br>
|
||||
* Note: This argument should also be encoded in UTF-8
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
File file = new File(args[0]);
|
||||
try
|
||||
{
|
||||
File file = new File(
|
||||
URLDecoder.decode(args[0], "UTF-8")
|
||||
);
|
||||
|
||||
|
||||
for (int i = 0; i < (60 / ((float) attemptSpeed/1000) ) * timeout; i++)
|
||||
{
|
||||
if (file.renameTo(file)) // If it is able to be renamed, then it is unlocked and can be deleted
|
||||
@@ -41,10 +47,5 @@ public class DeleteOnUnlock
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Deletion failed");
|
||||
}
|
||||
|
||||
|
||||
// If it isn't deleted by the end, crash
|
||||
if (Files.exists(file.toPath()))
|
||||
throw new RuntimeException("File still exist. So it was not able to be deleted");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,18 +19,17 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.jar.updater;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.config.EUpdateBranch;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.jar.JarUtils;
|
||||
import com.seibel.distanthorizons.core.jar.ModGitInfo;
|
||||
import com.seibel.distanthorizons.core.jar.Platform;
|
||||
import com.seibel.distanthorizons.core.jar.installer.GitlabGetter;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.jar.installer.ModrinthGetter;
|
||||
import com.seibel.distanthorizons.core.jar.installer.WebDownloader;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import com.seibel.distanthorizons.coreapi.util.jar.DeleteOnUnlock;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -38,12 +37,9 @@ import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
@@ -315,15 +311,15 @@ public class SelfUpdater
|
||||
}
|
||||
else
|
||||
{
|
||||
/* // If we want the user to delete it manually
|
||||
System.setProperty("java.awt.headless", "false"); // Required to make it work
|
||||
JOptionPane.showMessageDialog(null, "As you are on Windows, DH can not update fully by itself\nPlease delete ["+ JarUtils.jarFile.getAbsolutePath() +"] manually\nClick OK once ready.", ModInfo.READABLE_NAME, JOptionPane.INFORMATION_MESSAGE);
|
||||
|
||||
Runtime.getRuntime().exec("explorer.exe /select," + JarUtils.jarFile.getAbsolutePath());
|
||||
*/
|
||||
|
||||
// Execute the new jar, to delete the old jar once it detects the lock has been lifted
|
||||
Runtime.getRuntime().exec("java -cp "+ newFileLocation.getAbsolutePath() +" "+ DeleteOnUnlock.class.getCanonicalName() +" "+ JarUtils.jarFile.getAbsolutePath());
|
||||
Runtime.getRuntime().exec(
|
||||
"java -cp "+
|
||||
newFileLocation.getAbsolutePath()
|
||||
+" "+
|
||||
DeleteOnUnlock.class.getCanonicalName()
|
||||
+" "+
|
||||
URLEncoder.encode(JarUtils.jarFile.getAbsolutePath(), "UTF-8") // Encode the file location so that it doesnt have any spaces
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
Reference in New Issue
Block a user