This repository has been archived by the owner on Mar 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/me/micrusa/autoscreensettings/utils/AppInstaller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package me.micrusa.autoscreensettings.utils; | ||
|
||
import com.google.common.io.Files; | ||
import com.sun.jna.platform.win32.Advapi32Util; | ||
import com.sun.jna.platform.win32.WinReg; | ||
import me.micrusa.autoscreensettings.Constants; | ||
import me.micrusa.autoscreensettings.Main; | ||
import me.micrusa.autoscreensettings.MainService; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
|
||
public class AppInstaller { | ||
|
||
public static void openDialog(){ | ||
int install; | ||
if(!new File(Constants.APP_PATH).exists()){ | ||
install = JOptionPane.showConfirmDialog((Component) null, "Do you want to install AutoScreenSettings?", | ||
"AutoScreenSettings installation", JOptionPane.OK_CANCEL_OPTION); | ||
} else { | ||
install = JOptionPane.showConfirmDialog((Component) null, "Do you want to update AutoScreenSettings?", | ||
"AutoScreenSettings update", JOptionPane.OK_CANCEL_OPTION); | ||
} | ||
if(install != 0){ | ||
System.exit(0); | ||
} | ||
File appFile; | ||
try { | ||
appFile = new File(Main.class.getProtectionDomain(). | ||
getCodeSource(). | ||
getLocation() | ||
.toURI()); | ||
Files.copy(appFile, new File(Constants.APP_PATH)); | ||
Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, | ||
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "AutoScreenSettings", Constants.START_SCRIPT); | ||
Runtime.getRuntime().exec(Constants.START_SCRIPT + " update"); | ||
System.exit(1); | ||
} catch (URISyntaxException | IOException e) { | ||
utils.showException("Error in installation", e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters