fix: migration of old dir structure. Fixes to menu layout.
This commit is contained in:
parent
e5f13c93dc
commit
d40674abf3
|
@ -7,7 +7,9 @@ import java.awt.GraphicsEnvironment;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.ToolTipManager;
|
||||
|
@ -45,16 +47,18 @@ public class PCUAEManager
|
|||
{
|
||||
ExceptionHandler.handleException(e, "Startup failure");
|
||||
}
|
||||
|
||||
|
||||
//Make sure all folders are available
|
||||
try
|
||||
{
|
||||
Files.createDirectories(Paths.get("./screens/"));
|
||||
Files.createDirectories(Paths.get("./covers/"));
|
||||
Files.createDirectories(Paths.get("./games/"));
|
||||
Files.createDirectories(Paths.get("./saves/"));
|
||||
Files.createDirectories(Paths.get("./databases/"));
|
||||
Files.createDirectories(Paths.get("./pcuae-install/"));
|
||||
Files.createDirectories(Paths.get("./extradisks/"));
|
||||
|
||||
if (!Files.list(Paths.get("./databases/")).findAny().isPresent() && Paths.get("./games/").toFile().exists())
|
||||
{
|
||||
//Migrate to version 3.x
|
||||
migrateDirectories();
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
@ -79,7 +83,7 @@ public class PCUAEManager
|
|||
if (!FileManager.getPcuVersionFromManifest().isEmpty())
|
||||
{
|
||||
PreferencesModel prefModel = new PreferencesModel();
|
||||
|
||||
|
||||
if (prefModel.isCheckManagerVersionAtStartup())
|
||||
{
|
||||
ManagerVersionChecker.fetchLatestVersionFromGithub();
|
||||
|
@ -104,4 +108,23 @@ public class PCUAEManager
|
|||
});
|
||||
}
|
||||
|
||||
private static void migrateDirectories()
|
||||
{
|
||||
try
|
||||
{
|
||||
Path mainDb = Paths.get("./databases/MainDb");
|
||||
Files.createDirectories(mainDb);
|
||||
Files.move(Paths.get("./pcusb.db"), mainDb.resolve("pcusb.db"), StandardCopyOption.ATOMIC_MOVE);
|
||||
Files.move(Paths.get("./games/"), mainDb.resolve("games"), StandardCopyOption.ATOMIC_MOVE);
|
||||
Files.move(Paths.get("./screens/"), mainDb.resolve("screens"), StandardCopyOption.ATOMIC_MOVE);
|
||||
Files.move(Paths.get("./covers/"), mainDb.resolve("covers"), StandardCopyOption.ATOMIC_MOVE);
|
||||
Files.move(Paths.get("./saves/"), mainDb.resolve("saves"), StandardCopyOption.ATOMIC_MOVE);
|
||||
Files.move(Paths.get("./extradisks/"), mainDb.resolve("extradisks"), StandardCopyOption.ATOMIC_MOVE);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ExceptionHandler.handleException(e, "Could not move main Db");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import javax.swing.JPopupMenu;
|
|||
import javax.swing.JSplitPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import se.lantz.gui.menu.InsetsMenuItem;
|
||||
import se.lantz.model.MainViewModel;
|
||||
import se.lantz.model.data.GameListData;
|
||||
import se.lantz.util.ExceptionHandler;
|
||||
|
@ -40,6 +41,7 @@ public class MainPanel extends JPanel
|
|||
|
||||
uiModel.addSaveChangeListener(e -> {
|
||||
listPanel.checkSaveChangeStatus();
|
||||
setEnablementOfTabs();
|
||||
});
|
||||
|
||||
uiModel.addRequiredFieldsListener(e -> showRequiredFieldsDialog((List<String>) e.getNewValue()));
|
||||
|
@ -115,12 +117,15 @@ public class MainPanel extends JPanel
|
|||
if (tabNumber > -1 && (tabNumber < tabbedPane.getTabCount() - 1))
|
||||
{
|
||||
JPopupMenu menu = new JPopupMenu();
|
||||
JMenuItem renameTabItem = new JMenuItem("Rename database");
|
||||
InsetsMenuItem renameTabItem = new InsetsMenuItem("Rename database");
|
||||
renameTabItem.addActionListener(ev -> renameTab(tabNumber));
|
||||
JMenuItem deleteTabItem = new JMenuItem("Delete database");
|
||||
deleteTabItem.addActionListener(ev -> deleteTab(tabNumber));
|
||||
menu.add(renameTabItem);
|
||||
menu.add(deleteTabItem);
|
||||
if (tabbedPane.getTabCount() > 2)
|
||||
{
|
||||
InsetsMenuItem deleteTabItem = new InsetsMenuItem("Delete database");
|
||||
deleteTabItem.addActionListener(ev -> deleteTab(tabNumber));
|
||||
menu.add(deleteTabItem);
|
||||
}
|
||||
menu.show(tabbedPane, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
|
@ -129,6 +134,11 @@ public class MainPanel extends JPanel
|
|||
}
|
||||
return tabbedPane;
|
||||
}
|
||||
|
||||
private void setEnablementOfTabs()
|
||||
{
|
||||
tabbedPane.setEnabled(!uiModel.isDataChanged());
|
||||
}
|
||||
|
||||
private void renameTab(int tabIndex)
|
||||
{
|
||||
|
@ -180,7 +190,6 @@ public class MainPanel extends JPanel
|
|||
|
||||
private void createNewTab(String name)
|
||||
{
|
||||
//TODO: Check name here, do not add one with same name as existing, or null, or empty
|
||||
if (name == null || name.isEmpty() || name.isBlank())
|
||||
{
|
||||
//Do nothing
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,15 @@
|
|||
package se.lantz.gui.menu;
|
||||
|
||||
import java.awt.Insets;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
public class InsetsMenu extends JMenu
|
||||
{
|
||||
public InsetsMenu(String s)
|
||||
{
|
||||
super(s);
|
||||
setMargin(new Insets(2, -20, 2, 2));
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package se.lantz.gui;
|
||||
package se.lantz.gui.menu;
|
||||
|
||||
import java.awt.Insets;
|
||||
|
||||
|
@ -6,15 +6,15 @@ import javax.swing.Action;
|
|||
import javax.swing.Icon;
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
public class CustomMenuItem extends JMenuItem
|
||||
public class InsetsMenuItem extends JMenuItem
|
||||
{
|
||||
|
||||
public CustomMenuItem()
|
||||
public InsetsMenuItem()
|
||||
{
|
||||
setMargin(new Insets(2, -20, 2, 2));
|
||||
}
|
||||
|
||||
public CustomMenuItem(String text)
|
||||
public InsetsMenuItem(String text)
|
||||
{
|
||||
super(text);
|
||||
setMargin(new Insets(2, -20, 2, 2));
|
|
@ -111,8 +111,20 @@ public class MainViewModel extends AbstractModel
|
|||
{
|
||||
ExceptionHandler.handleException(ex, "Could not read databases");
|
||||
}
|
||||
|
||||
if (availableDatabases.size() > 0)
|
||||
|
||||
if (availableDatabases.isEmpty())
|
||||
{
|
||||
try
|
||||
{
|
||||
//We need at least one database. Create a "MainDb" folder with an empty db
|
||||
addTab("MainDb");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ExceptionHandler.handleException(e, "Could not create MainDb");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Read preferences for tab order
|
||||
Properties configuredProperties = FileManager.getConfiguredProperties();
|
||||
|
|
Loading…
Reference in New Issue