feat: installation of mode packs

This commit is contained in:
lantzelot-swe 2021-12-06 22:48:58 +01:00
parent 33a37968f1
commit 2276152b96
15 changed files with 568 additions and 193 deletions

2
.gitignore vendored
View File

@ -30,6 +30,8 @@ covers/
backup/
vice/
images/
saves/
pcuae-install/
pcu.properties

View File

@ -11,7 +11,7 @@ import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import se.lantz.gui.MainWindow;
import se.lantz.gui.install.VersionDownloadDialog;
import se.lantz.gui.install.ManagerDownloadDialog;
import se.lantz.util.ExceptionHandler;
import se.lantz.util.FileManager;
import se.lantz.util.ManagerVersionChecker;
@ -71,7 +71,7 @@ public class PCUAEManager
ManagerVersionChecker.fetchLatestVersionFromGithub();
if (ManagerVersionChecker.isNewVersionAvailable())
{
VersionDownloadDialog dialog = new VersionDownloadDialog(MainWindow.getInstance());
ManagerDownloadDialog dialog = new ManagerDownloadDialog(MainWindow.getInstance());
dialog.pack();
dialog.setLocationRelativeTo(MainWindow.getInstance());
if (dialog.showDialog())

View File

@ -42,13 +42,18 @@ import se.lantz.gui.imports.ImportOptionsDialog;
import se.lantz.gui.imports.ImportProgressDialog;
import se.lantz.gui.imports.ImportSavedStatesDialog;
import se.lantz.gui.imports.ImportSavedStatesWorker;
import se.lantz.gui.install.VersionDownloadDialog;
import se.lantz.gui.install.ManagerDownloadDialog;
import se.lantz.manager.BackupManager;
import se.lantz.manager.ExportManager;
import se.lantz.manager.ImportManager;
import se.lantz.manager.RestoreManager;
import se.lantz.manager.SavedStatesManager;
import se.lantz.manager.pcuae.AmigaModeInstallManager;
import se.lantz.manager.pcuae.AtariModeInstallManager;
import se.lantz.manager.pcuae.LinuxModeInstallManager;
import se.lantz.manager.pcuae.PCUAEInstallManager;
import se.lantz.manager.pcuae.RetroarchModeInstallManager;
import se.lantz.manager.pcuae.ViceModeInstallManager;
import se.lantz.model.MainViewModel;
import se.lantz.model.data.GameListData;
import se.lantz.model.data.GameView;
@ -64,6 +69,7 @@ public class MenuManager
private JMenu editMenu;
private JMenu toolsMenu;
private JMenu pcuaeMenu;
private JMenu pcuaeModeMenu;
private JMenu helpMenu;
private JMenuItem addGameItem;
@ -109,6 +115,11 @@ public class MenuManager
private JMenuItem palNtscFixItem;
private JMenuItem installPCUAEItem;
private JMenuItem installAmigaModeItem;
private JMenuItem installAtariModeItem;
private JMenuItem installLinuxModeItem;
private JMenuItem installRetroarchModeItem;
private JMenuItem installViceModeItem;
private JMenuItem helpItem;
private JMenuItem aboutItem;
@ -123,6 +134,11 @@ public class MenuManager
private RestoreManager restoreManager;
private SavedStatesManager savedStatesManager;
private PCUAEInstallManager installPCUAEManager;
private AmigaModeInstallManager installAmigaManager;
private AtariModeInstallManager installAtariManager;
private LinuxModeInstallManager installLinuxManager;
private RetroarchModeInstallManager installRetroarchManager;
private ViceModeInstallManager installViceManager;
private MainWindow mainWindow;
public MenuManager(final MainViewModel uiModel, MainWindow mainWindow)
@ -136,6 +152,11 @@ public class MenuManager
this.restoreManager = new RestoreManager(uiModel);
this.savedStatesManager = new SavedStatesManager(uiModel, getPalNtscFixMenuItem());
this.installPCUAEManager = new PCUAEInstallManager(getExportItem());
this.installAmigaManager = new AmigaModeInstallManager();
this.installAtariManager = new AtariModeInstallManager();
this.installLinuxManager = new LinuxModeInstallManager();
this.installRetroarchManager = new RetroarchModeInstallManager();
this.installViceManager = new ViceModeInstallManager();
uiModel.setSavedStatesManager(savedStatesManager);
setupMenues();
}
@ -208,6 +229,13 @@ public class MenuManager
pcuaeMenu = new JMenu("PCUAE");
pcuaeMenu.add(getInstallPCUAEItem());
pcuaeModeMenu = new JMenu("Mode Packs");
pcuaeModeMenu.add(getInstallAmigaModeItem());
pcuaeModeMenu.add(getInstallAtariModeItem());
pcuaeModeMenu.add(getInstallLinuxModeItem());
pcuaeModeMenu.add(getInstallRetroarchModeItem());
pcuaeModeMenu.add(getInstallViceModeItem());
pcuaeMenu.add(pcuaeModeMenu);
helpMenu = new JMenu("Help");
helpMenu.setMnemonic('H');
@ -697,6 +725,62 @@ public class MenuManager
return installPCUAEItem;
}
private JMenuItem getInstallAmigaModeItem()
{
if (installAmigaModeItem == null)
{
installAmigaModeItem = new JMenuItem("Install Amiga mode...");
installAmigaModeItem.setMnemonic('a');
installAmigaModeItem.addActionListener(e -> installAmigaMode());
}
return installAmigaModeItem;
}
private JMenuItem getInstallAtariModeItem()
{
if (installAtariModeItem == null)
{
installAtariModeItem = new JMenuItem("Install Atari mode...");
installAtariModeItem.setMnemonic('t');
installAtariModeItem.addActionListener(e -> installAtariMode());
}
return installAtariModeItem;
}
private JMenuItem getInstallLinuxModeItem()
{
if (installLinuxModeItem == null)
{
installLinuxModeItem = new JMenuItem("Install Linux mode...");
installLinuxModeItem.setMnemonic('l');
installLinuxModeItem.addActionListener(e -> installLinuxMode());
}
return installLinuxModeItem;
}
private JMenuItem getInstallRetroarchModeItem()
{
if (installRetroarchModeItem == null)
{
installRetroarchModeItem = new JMenuItem("Install Retroarch mode...");
installRetroarchModeItem.setMnemonic('r');
installRetroarchModeItem.addActionListener(e -> installRetroarchMode());
}
return installRetroarchModeItem;
}
private JMenuItem getInstallViceModeItem()
{
if (installViceModeItem == null)
{
installViceModeItem = new JMenuItem("Install Vice mode...");
installViceModeItem.setMnemonic('v');
installViceModeItem.addActionListener(e -> installViceMode());
}
return installViceModeItem;
}
private JMenuItem getHelpItem()
{
helpItem = new JMenuItem("Help");
@ -1034,6 +1118,31 @@ public class MenuManager
installPCUAEManager.installPCUAE();
}
private void installAmigaMode()
{
installAmigaManager.installAmigaMode();
}
private void installAtariMode()
{
installAtariManager.installAtariMode();
}
private void installLinuxMode()
{
installLinuxManager.installLinuxMode();
}
private void installRetroarchMode()
{
installRetroarchManager.installRetroarchMode();
}
private void installViceMode()
{
installViceManager.installViceMode();
}
private JEditorPane getPalNtscEditorPane()
{
String message =
@ -1082,7 +1191,7 @@ public class MenuManager
ManagerVersionChecker.fetchLatestVersionFromGithub();
if (ManagerVersionChecker.isNewVersionAvailable())
{
VersionDownloadDialog dialog = new VersionDownloadDialog(MainWindow.getInstance());
ManagerDownloadDialog dialog = new ManagerDownloadDialog(MainWindow.getInstance());
dialog.pack();
dialog.setLocationRelativeTo(MainWindow.getInstance());
if (dialog.showDialog())

View File

@ -6,11 +6,11 @@ import java.awt.Frame;
import se.lantz.gui.BaseDialog;
import se.lantz.util.ManagerVersionChecker;
public class VersionDownloadDialog extends BaseDialog
public class ManagerDownloadDialog extends BaseDialog
{
private VersionDownloadPanel panel;
private ManagerDownloadPanel panel;
public VersionDownloadDialog(Frame owner)
public ManagerDownloadDialog(Frame owner)
{
super(owner);
setTitle("New version available");
@ -22,12 +22,12 @@ public class VersionDownloadDialog extends BaseDialog
getCancelButton().setPreferredSize(new Dimension(73, 23));
}
private VersionDownloadPanel getVersionDownloadPanel() {
private ManagerDownloadPanel getVersionDownloadPanel() {
if (panel == null) {
String downloadUrl = ManagerVersionChecker.getDownloadUrl();
String message = "<html>There is a new version of PCUAE Manager available: <a href='" + downloadUrl + "'>" +
ManagerVersionChecker.getLatestVersion() + "</a><p>" + "Do you want to update to the new version now?</html>";
panel = new VersionDownloadPanel(message);
panel = new ManagerDownloadPanel(message);
}
return panel;
}

View File

@ -15,12 +15,12 @@ import javax.swing.event.HyperlinkEvent;
import se.lantz.util.ExceptionHandler;
import se.lantz.util.ManagerVersionChecker;
public class VersionDownloadPanel extends JPanel
public class ManagerDownloadPanel extends JPanel
{
private JEditorPane editorPane;
private String message;
public VersionDownloadPanel(String message)
public ManagerDownloadPanel(String message)
{
this.message = message;
GridBagLayout gridBagLayout = new GridBagLayout();

View File

@ -0,0 +1,54 @@
package se.lantz.gui.install;
import java.awt.Dimension;
import se.lantz.gui.BaseDialog;
import se.lantz.gui.MainWindow;
import se.lantz.manager.pcuae.BaseInstallManger;
public class PCUAEProductDownloadDialog extends BaseDialog
{
private ManagerDownloadPanel panel;
private boolean firstDownload;
private String productText;
private BaseInstallManger manager;
public PCUAEProductDownloadDialog(final boolean firstDownload, final BaseInstallManger manager, String productName)
{
super(MainWindow.getInstance());
this.firstDownload = firstDownload;
this.manager = manager;
this.productText = productName;
setTitle(firstDownload ? "Download " + productName : "New version available");
addContent(getVersionDownloadPanel());
this.setResizable(false);
getOkButton().setText("Yes");
getCancelButton().setText("No");
getOkButton().setPreferredSize(new Dimension(73, 23));
getCancelButton().setPreferredSize(new Dimension(73, 23));
}
private ManagerDownloadPanel getVersionDownloadPanel()
{
if (panel == null)
{
String downloadUrl = manager.getDownloadUrl();
String message = "";
if (firstDownload)
{
message = "<html>You have to download " + productText + " before installing it. The latest version is <a href='" +
downloadUrl + "'>" + manager.getLatestVersion() + "</a><p>Do you want to download now?</html>";
}
else
{
message = "<html>PCUAE <a href='" + downloadUrl + "'>" + manager.getLatestVersion() +
"</a> is available.<p>(Current install file: " + manager.getLatestInInstallFolder() +
").<br>Do you want to download and install the new version?</html>";
}
panel = new ManagerDownloadPanel(message);
}
return panel;
}
}

View File

@ -1,50 +0,0 @@
package se.lantz.gui.install;
import java.awt.Dimension;
import java.awt.Frame;
import se.lantz.gui.BaseDialog;
import se.lantz.manager.pcuae.PCUAEInstallManager;
public class PCUAEVersionDownloadDialog extends BaseDialog
{
private VersionDownloadPanel panel;
private boolean firstDownload;
public PCUAEVersionDownloadDialog(Frame owner, boolean firstDownload)
{
super(owner);
this.firstDownload = firstDownload;
setTitle(firstDownload ? "Download PCUAE" : "New version available");
addContent(getVersionDownloadPanel());
this.setResizable(false);
getOkButton().setText("Yes");
getCancelButton().setText("No");
getOkButton().setPreferredSize(new Dimension(73, 23));
getCancelButton().setPreferredSize(new Dimension(73, 23));
}
private VersionDownloadPanel getVersionDownloadPanel()
{
if (panel == null)
{
String downloadUrl = PCUAEInstallManager.getDownloadUrl();
String message = "";
if (firstDownload)
{
message = "<html>You have to download PCUAE before installing it. The latest version is <a href='" +
downloadUrl + "'>" + PCUAEInstallManager.getLatestVersion() + "</a><p>Do you want to download now?</html>";
}
else
{
message = "<html>PCUAE <a href='" + downloadUrl + "'>" + PCUAEInstallManager.getLatestVersion() +
"</a> is available.<p>(Current install file: " + PCUAEInstallManager.getLatestInInstallFolder() +
").<br>Do you want to download and install the new version?</html>";
}
panel = new VersionDownloadPanel(message);
}
return panel;
}
}

View File

@ -0,0 +1,36 @@
package se.lantz.manager.pcuae;
import javax.swing.JOptionPane;
import se.lantz.gui.MainWindow;
public class AmigaModeInstallManager extends BaseInstallManger
{
private static final String PRODUCT_NAME = "Amiga mode";
public AmigaModeInstallManager()
{
}
public void installAmigaMode()
{
readVersionFromInstallFolder(AMIGA_MODE_INSTALL_NAME);
if (isNewVersionAvailable(AMIGA_MODE_INSTALL_NAME))
{
askAndStartDownload(PRODUCT_NAME);
}
else
{
askToInstallExistingVersion(PRODUCT_NAME);
}
}
@Override
protected void executeAfterInstallation()
{
JOptionPane.showMessageDialog(MainWindow.getInstance(),
PRODUCT_NAME + " installed successfully.",
"Installation complete",
JOptionPane.INFORMATION_MESSAGE);
}
}

View File

@ -0,0 +1,36 @@
package se.lantz.manager.pcuae;
import javax.swing.JOptionPane;
import se.lantz.gui.MainWindow;
public class AtariModeInstallManager extends BaseInstallManger
{
private static final String PRODUCT_NAME = "Atari mode";
public AtariModeInstallManager()
{
}
public void installAtariMode()
{
readVersionFromInstallFolder(ATARI_MODE_INSTALL_NAME);
if (isNewVersionAvailable(ATARI_MODE_INSTALL_NAME))
{
askAndStartDownload(PRODUCT_NAME);
}
else
{
askToInstallExistingVersion(PRODUCT_NAME);
}
}
@Override
protected void executeAfterInstallation()
{
JOptionPane.showMessageDialog(MainWindow.getInstance(),
PRODUCT_NAME + " installed successfully.",
"Installation complete",
JOptionPane.INFORMATION_MESSAGE);
}
}

View File

@ -19,9 +19,11 @@ import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@ -31,15 +33,28 @@ import dyorgio.runtime.out.process.CallableSerializable;
import dyorgio.runtime.run.as.root.RootExecutor;
import se.lantz.gui.MainWindow;
import se.lantz.gui.download.DownloadDialog;
import se.lantz.gui.install.PCUAEProductDownloadDialog;
import se.lantz.util.ExceptionHandler;
import se.lantz.util.ManagerVersionChecker;
public abstract class BaseInstallManger implements AWTEventListener
{
public static final String INSTALL_FOLDER = "./pcuae-install/";
protected static final String PCUAE_INSTALL_NAME = "pcuae";
protected static final String AMIGA_MODE_INSTALL_NAME = "amiga";
protected static final String ATARI_MODE_INSTALL_NAME = "atari";
protected static final String LINUX_MODE_INSTALL_NAME = "linux";
protected static final String RETROARCH_MODE_INSTALL_NAME = "retroarch";
protected static final String VICE_MODE_INSTALL_NAME = "vice";
private boolean blockEvents = false;
protected ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
protected String latestInInstallFolder = "";
protected GithubAssetInformation gitHubReleaseInformation = new GithubAssetInformation();
protected volatile boolean downloadIterrupted = false;
public BaseInstallManger()
@ -91,15 +106,25 @@ public abstract class BaseInstallManger implements AWTEventListener
frame.getGlassPane().setVisible(false);
}
protected String readVersionFromInstallFolder(String installFileName)
protected void readVersionFromInstallFolder(String installFileName)
{
String latestInInstallFolder = "";
latestInInstallFolder = "";
FilenameFilter filter = new FilenameFilter()
{
@Override
public boolean accept(File f, String name)
{
return name.contains(installFileName) && name.endsWith(".exe");
if (PCUAE_INSTALL_NAME.equals(installFileName))
{
//Check so that no other is part of the name
return !(name.contains(AMIGA_MODE_INSTALL_NAME) || name.contains(ATARI_MODE_INSTALL_NAME) ||
name.contains(LINUX_MODE_INSTALL_NAME) || name.contains(RETROARCH_MODE_INSTALL_NAME) ||
name.contains(VICE_MODE_INSTALL_NAME)) && name.endsWith(".exe");
}
else
{
return name.contains(installFileName) && name.endsWith(".exe");
}
}
};
File installFolder = new File(INSTALL_FOLDER);
@ -120,7 +145,6 @@ public abstract class BaseInstallManger implements AWTEventListener
{
latestInInstallFolder = latestFile.getName();
}
return latestInInstallFolder;
}
public GithubAssetInformation fetchLatestVersionFromGithub(String assetsName)
@ -131,7 +155,7 @@ public abstract class BaseInstallManger implements AWTEventListener
//TODO: To get all releases, use "https://CommodoreOS@api.github.com/repos/CommodoreOS/PCUAE/releases"-
//Get all releases, check which one contains the latest file with assetName (part of the name)
URL url = new URL("https://CommodoreOS@api.github.com/repos/CommodoreOS/PCUAE/releases/latest");
URL url = new URL("https://CommodoreOS@api.github.com/repos/CommodoreOS/PCUAE/releases");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("accept", "application/vnd.github.v3+json");
@ -148,14 +172,89 @@ public abstract class BaseInstallManger implements AWTEventListener
JsonReader reader = new JsonReader(new StringReader(builder.toString()));
reader.setLenient(true);
JsonElement root = new JsonParser().parse(reader);
JsonObject jsonObject = root.getAsJsonObject();
githubInfo.setLatestVersion(jsonObject.get("tag_name").getAsString());
githubInfo.setReleaseTagUrl(jsonObject.get("html_url").getAsString());
//TODO: fix
String downloadUrl =
jsonObject.get("assets").getAsJsonArray().get(0).getAsJsonObject().get("browser_download_url").getAsString();
githubInfo.setDownloadUrl(downloadUrl);
githubInfo.setInstallFile(downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1));
JsonArray releases = root.getAsJsonArray();
//Find the latest one containing in assetName. Releases seem to be return in the right order (latest first)
boolean foundRelease = false;
for (JsonElement release : releases)
{
if (foundRelease)
{
break;
}
JsonObject jsonObject = release.getAsJsonObject();
JsonArray assets = jsonObject.get("assets").getAsJsonArray();
String downloadUrl = "";
for (JsonElement asset : assets)
{
String assetName = asset.getAsJsonObject().get("name").getAsString();
switch (assetsName)
{
case AMIGA_MODE_INSTALL_NAME:
{
if (assetName.contains(AMIGA_MODE_INSTALL_NAME))
{
downloadUrl = asset.getAsJsonObject().get("browser_download_url").getAsString();
}
break;
}
case ATARI_MODE_INSTALL_NAME:
{
if (assetName.contains(ATARI_MODE_INSTALL_NAME))
{
downloadUrl = asset.getAsJsonObject().get("browser_download_url").getAsString();
}
break;
}
case LINUX_MODE_INSTALL_NAME:
{
if (assetName.contains(LINUX_MODE_INSTALL_NAME))
{
downloadUrl = asset.getAsJsonObject().get("browser_download_url").getAsString();
}
break;
}
case RETROARCH_MODE_INSTALL_NAME:
{
if (assetName.contains(RETROARCH_MODE_INSTALL_NAME))
{
downloadUrl = asset.getAsJsonObject().get("browser_download_url").getAsString();
}
break;
}
case VICE_MODE_INSTALL_NAME:
{
if (assetName.contains(VICE_MODE_INSTALL_NAME))
{
downloadUrl = asset.getAsJsonObject().get("browser_download_url").getAsString();
}
break;
}
case PCUAE_INSTALL_NAME:
{
if (!(assetName.contains(AMIGA_MODE_INSTALL_NAME) || assetName.contains(ATARI_MODE_INSTALL_NAME) ||
assetName.contains(LINUX_MODE_INSTALL_NAME) || assetName.contains(RETROARCH_MODE_INSTALL_NAME) ||
assetName.contains(VICE_MODE_INSTALL_NAME)))
{
downloadUrl = asset.getAsJsonObject().get("browser_download_url").getAsString();
}
break;
}
default:
throw new IllegalArgumentException("Unexpected value: " + assetsName);
}
if (!downloadUrl.isEmpty())
{
githubInfo.setLatestVersion(release.getAsJsonObject().get("tag_name").getAsString());
githubInfo.setReleaseTagUrl(release.getAsJsonObject().get("html_url").getAsString());
githubInfo.setInstallFile(assetName);
githubInfo.setDownloadUrl(downloadUrl);
foundRelease = true;
break;
}
}
}
}
catch (IOException ex)
{
@ -164,7 +263,7 @@ public abstract class BaseInstallManger implements AWTEventListener
return githubInfo;
}
protected void runAndWaitForInstallation(String fileToInstall)
protected void runAndWaitForInstallation()
{
switchToBusyCursor(MainWindow.getInstance());
RootExecutor rootExecutor;
@ -172,19 +271,19 @@ public abstract class BaseInstallManger implements AWTEventListener
{
rootExecutor = new RootExecutor("-Xmx64m");
// Execute privileged action without return
CallableSerializable<Integer> installCallable = new InstallCallable(fileToInstall);
CallableSerializable<Integer> installCallable = new InstallCallable(latestInInstallFolder);
int value = rootExecutor.call(installCallable);
//0 -> installed
//255 -> aborted
if (value == 0)
{
executeAfterInstallation();
SwingUtilities.invokeLater(() -> executeAfterInstallation());
}
}
catch (Exception e1)
{
ExceptionHandler.logException(e1, "Could not execute RootExecutor");
ExceptionHandler.handleException(e1, "Something went wrong during install.");
}
finally
{
@ -241,14 +340,14 @@ public abstract class BaseInstallManger implements AWTEventListener
}
}
protected void cleanupInterruptedDownload(String fileName)
protected void cleanupInterruptedDownload()
{
downloadIterrupted = true;
//Make sure this executes after the downloading has been interrupted
singleThreadExecutor.execute(() -> {
try
{
Files.deleteIfExists(new File(INSTALL_FOLDER + fileName).toPath());
Files.deleteIfExists(new File(INSTALL_FOLDER + gitHubReleaseInformation.getInstallFile()).toPath());
}
catch (IOException e)
{
@ -257,5 +356,82 @@ public abstract class BaseInstallManger implements AWTEventListener
});
}
protected void askToInstallExistingVersion(String productName)
{
int value =
JOptionPane.showConfirmDialog(MainWindow.getInstance(),
"Do you want to install " + productName + " (" + latestInInstallFolder + ") now?",
"Install " + productName,
JOptionPane.YES_NO_OPTION);
if (value == JOptionPane.YES_OPTION)
{
singleThreadExecutor.execute(() -> runAndWaitForInstallation());
}
}
protected boolean isNewVersionAvailable(String installName)
{
gitHubReleaseInformation = fetchLatestVersionFromGithub(installName);
return ManagerVersionChecker.getIntVersion(latestInInstallFolder) < ManagerVersionChecker
.getIntVersion(gitHubReleaseInformation.getInstallFile());
}
public String getLatestInInstallFolder()
{
return latestInInstallFolder;
}
public String getLatestVersion()
{
return gitHubReleaseInformation.getLatestVersion();
}
public String getDownloadUrl()
{
return gitHubReleaseInformation.getDownloadUrl();
}
protected void askAndStartDownload(String productName)
{
PCUAEProductDownloadDialog dialog =
new PCUAEProductDownloadDialog(latestInInstallFolder.isEmpty(), this, productName);
dialog.pack();
dialog.setLocationRelativeTo(MainWindow.getInstance());
if (dialog.showDialog())
{
downloadLatestVersion(productName);
}
else if (!latestInInstallFolder.isEmpty())
{
askToInstallExistingVersion(productName);
}
}
protected void downloadLatestVersion(String productName)
{
DownloadDialog progressDialog =
new DownloadDialog("Downloading " + productName + " version " + gitHubReleaseInformation.getLatestVersion());
singleThreadExecutor.execute(() -> startDownload(progressDialog, gitHubReleaseInformation));
progressDialog.pack();
progressDialog.setLocationRelativeTo(MainWindow.getInstance());
if (progressDialog.showDialog())
{
latestInInstallFolder = gitHubReleaseInformation.getInstallFile();
int value = JOptionPane.showConfirmDialog(MainWindow.getInstance(),
"Download completed, do you want to install " + productName + " " +
gitHubReleaseInformation.getLatestVersion() + " now?",
"Download Complete",
JOptionPane.YES_NO_OPTION);
if (value == JOptionPane.YES_OPTION)
{
singleThreadExecutor.execute(() -> runAndWaitForInstallation());
}
}
else
{
cleanupInterruptedDownload();
}
}
protected abstract void executeAfterInstallation();
}

View File

@ -1,7 +1,6 @@
package se.lantz.manager.pcuae;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import dyorgio.runtime.out.process.CallableSerializable;
@ -20,24 +19,10 @@ class InstallCallable implements CallableSerializable<Integer>
public Integer call() throws Exception
{
int returnValue = 0;
try
{
File fileDir = new File("./pcuae-install/");
//Read file from dir and see if we can extract it
Path installFilePath = new File("./pcuae-install/" + installFileName).toPath();
returnValue = Runtime.getRuntime().exec(installFilePath.toString(), null, fileDir).waitFor();
System.out.println("ExitValue = " + returnValue);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
File fileDir = new File("./pcuae-install/");
//Read file from dir and see if we can extract it
Path installFilePath = new File("./pcuae-install/" + installFileName).toPath();
returnValue = Runtime.getRuntime().exec(installFilePath.toString(), null, fileDir).waitFor();
return returnValue;
}
}

View File

@ -0,0 +1,36 @@
package se.lantz.manager.pcuae;
import javax.swing.JOptionPane;
import se.lantz.gui.MainWindow;
public class LinuxModeInstallManager extends BaseInstallManger
{
private static final String PRODUCT_NAME = "Linux mode";
public LinuxModeInstallManager()
{
}
public void installLinuxMode()
{
readVersionFromInstallFolder(LINUX_MODE_INSTALL_NAME);
if (isNewVersionAvailable(LINUX_MODE_INSTALL_NAME))
{
askAndStartDownload(PRODUCT_NAME);
}
else
{
askToInstallExistingVersion(PRODUCT_NAME);
}
}
@Override
protected void executeAfterInstallation()
{
JOptionPane.showMessageDialog(MainWindow.getInstance(),
PRODUCT_NAME + " installed successfully.",
"Installation complete",
JOptionPane.INFORMATION_MESSAGE);
}
}

View File

@ -2,28 +2,12 @@ package se.lantz.manager.pcuae;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import se.lantz.gui.MainWindow;
import se.lantz.gui.download.DownloadDialog;
import se.lantz.gui.install.PCUAEVersionDownloadDialog;
import se.lantz.util.ManagerVersionChecker;
public class PCUAEInstallManager extends BaseInstallManger
{
public static final String INSTALL_FOLDER = "./pcuae-install/";
private static final String PCUAE_INSTALL_NAME = "pcuae";
// private static final String AMIGA_MODE_INSTALL_NAME = "amiga";
// private static final String ATARI_MODE_INSTALL_NAME = "atari";
// private static final String LINUX_MODE_INSTALL_NAME = "linux";
// private static final String RETROARCH_MODE_INSTALL_NAME = "retroarch";
// private static final String VICE_MODE_INSTALL_NAME = "vice";
private static String pcuaeLatestInInstallFolder = "";
private static GithubAssetInformation gitHubReleaseInformation = new GithubAssetInformation();
private static final String PRODUCT_NAME = "PCUAE";
private JMenuItem exportMenuItem;
@ -34,95 +18,30 @@ public class PCUAEInstallManager extends BaseInstallManger
public void installPCUAE()
{
pcuaeLatestInInstallFolder = readVersionFromInstallFolder(PCUAE_INSTALL_NAME);
if (isNewVersionAvailable())
readVersionFromInstallFolder(PCUAE_INSTALL_NAME);
if (isNewVersionAvailable(PCUAE_INSTALL_NAME))
{
askAndStartDownload(pcuaeLatestInInstallFolder.isEmpty());
askAndStartDownload(PRODUCT_NAME);
}
else
{
askToInstallExistingVersion();
askToInstallExistingVersion(PRODUCT_NAME);
}
}
private void askAndStartDownload(boolean firstDownload)
{
PCUAEVersionDownloadDialog dialog = new PCUAEVersionDownloadDialog(MainWindow.getInstance(), firstDownload);
dialog.pack();
dialog.setLocationRelativeTo(MainWindow.getInstance());
if (dialog.showDialog())
{
downloadLatestPCUAE();
}
else if (!firstDownload)
{
askToInstallExistingVersion();
}
}
private void askToInstallExistingVersion()
{
int value = JOptionPane.showConfirmDialog(MainWindow.getInstance(),
"Do you want to install PCUAE (" + pcuaeLatestInInstallFolder + ") now?",
"Install PCUAE",
JOptionPane.YES_NO_OPTION);
if (value == JOptionPane.YES_OPTION)
{
singleThreadExecutor.execute(() -> runAndWaitForInstallation(pcuaeLatestInInstallFolder));
}
}
private boolean isNewVersionAvailable()
{
gitHubReleaseInformation = fetchLatestVersionFromGithub(PCUAE_INSTALL_NAME);
return ManagerVersionChecker.getIntVersion(pcuaeLatestInInstallFolder) < ManagerVersionChecker
.getIntVersion(gitHubReleaseInformation.getInstallFile());
}
@Override
protected void executeAfterInstallation()
{
SwingUtilities.invokeLater(() -> exportMenuItem.doClick());
}
private void downloadLatestPCUAE()
{
DownloadDialog progressDialog =
new DownloadDialog("Downloading PCUAE version " + gitHubReleaseInformation.getLatestVersion());
singleThreadExecutor.execute(() -> startDownload(progressDialog, gitHubReleaseInformation));
progressDialog.pack();
progressDialog.setLocationRelativeTo(MainWindow.getInstance());
if (progressDialog.showDialog())
int value =
JOptionPane.showConfirmDialog(MainWindow.getInstance(),
PRODUCT_NAME + " installed successfully.\nDo you want to export games now?",
"Installation complete",
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE);
if (value == JOptionPane.YES_OPTION)
{
pcuaeLatestInInstallFolder = gitHubReleaseInformation.getInstallFile();
int value = JOptionPane.showConfirmDialog(MainWindow.getInstance(),
"Download completed, do you want to install PCUAE " +
gitHubReleaseInformation.getLatestVersion() + " now?",
"Download Complete",
JOptionPane.YES_NO_OPTION);
if (value == JOptionPane.YES_OPTION)
{
singleThreadExecutor.execute(() -> runAndWaitForInstallation(pcuaeLatestInInstallFolder));
}
}
else
{
cleanupInterruptedDownload(gitHubReleaseInformation.getInstallFile());
exportMenuItem.doClick();
}
}
public static String getLatestInInstallFolder()
{
return pcuaeLatestInInstallFolder;
}
public static String getLatestVersion()
{
return gitHubReleaseInformation.getLatestVersion();
}
public static String getDownloadUrl()
{
return gitHubReleaseInformation.getDownloadUrl();
}
}

View File

@ -0,0 +1,36 @@
package se.lantz.manager.pcuae;
import javax.swing.JOptionPane;
import se.lantz.gui.MainWindow;
public class RetroarchModeInstallManager extends BaseInstallManger
{
private static final String PRODUCT_NAME = "Retroarch mode";
public RetroarchModeInstallManager()
{
}
public void installRetroarchMode()
{
readVersionFromInstallFolder(RETROARCH_MODE_INSTALL_NAME);
if (isNewVersionAvailable(RETROARCH_MODE_INSTALL_NAME))
{
askAndStartDownload(PRODUCT_NAME);
}
else
{
askToInstallExistingVersion(PRODUCT_NAME);
}
}
@Override
protected void executeAfterInstallation()
{
JOptionPane.showMessageDialog(MainWindow.getInstance(),
PRODUCT_NAME + " installed successfully.",
"Installation complete",
JOptionPane.INFORMATION_MESSAGE);
}
}

View File

@ -0,0 +1,36 @@
package se.lantz.manager.pcuae;
import javax.swing.JOptionPane;
import se.lantz.gui.MainWindow;
public class ViceModeInstallManager extends BaseInstallManger
{
private static final String PRODUCT_NAME = "Vice mode";
public ViceModeInstallManager()
{
}
public void installViceMode()
{
readVersionFromInstallFolder(VICE_MODE_INSTALL_NAME);
if (isNewVersionAvailable(VICE_MODE_INSTALL_NAME))
{
askAndStartDownload(PRODUCT_NAME);
}
else
{
askToInstallExistingVersion(PRODUCT_NAME);
}
}
@Override
protected void executeAfterInstallation()
{
JOptionPane.showMessageDialog(MainWindow.getInstance(),
PRODUCT_NAME + " installed successfully.",
"Installation complete",
JOptionPane.INFORMATION_MESSAGE);
}
}