diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/CreateBudgetController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/CreateBudgetController.java index 5ae3fdc5f1dfb8c959318010e01a2a42995ff535..41b6d0425ba7f50e1bda34d1fd76e747e39a17c3 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/CreateBudgetController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/CreateBudgetController.java @@ -158,9 +158,13 @@ public class CreateBudgetController { boolean empty; try { + String path = System.getProperty("user.home"); + filePath = path + "/BudgetBuddyFiles/budgets"; + //TODO: Fiks at måned kommer med i navnet. empty = FileHandlingSelectedBudget.createBudgetDirectory( filePath + "/" + currentMonth + budgetName); + FileHandlingSelectedBudget.createNewIncomeFile(filePath + "/" + currentMonth + budgetName, "Income"); FileHandlingSelectedBudget.createNewExpenseFile(filePath + "/" + currentMonth + budgetName, @@ -184,9 +188,11 @@ public class CreateBudgetController { * @param budgetName The name of the budget. */ public void updateCurrentFile(String currentMonth, String budgetName) { + System.out.println(currentMonth + budgetName); try { + FileHandlingSelectedBudget.updateSelectedBudget(currentMonth + budgetName, - "budgets/SelectedBudget"); + filePath + "/SelectedBudget"); } catch (IOException ioe) { showErrorMsgBox(ioe.getMessage(), ioe.getMessage(), ioe.getMessage()); } diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/FirstMenuController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/FirstMenuController.java index cccb5f95a910fa8c423e7dde9ff4bdb416dab69f..495271623d0a6dcfdfdf88fc5aa2b5f016950fce 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/FirstMenuController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/FirstMenuController.java @@ -29,15 +29,21 @@ public class FirstMenuController { * Initializes as soon as the scene is loaded. */ @FXML - public void initialize() { + public void initialize() throws IOException { String path = System.getProperty("user.home"); - String buddyPath = path + "/BudgetBuddy"; + String buddyPath = path + "/BudgetBuddyFiles"; filePath = buddyPath + "/budgets"; File budget = new File(buddyPath + "/budgets"); if(!budget.exists()){ budget.mkdirs(); } + + File archive = new File(buddyPath + "/budgets/Archive.archive"); + if(!archive.exists()){ + archive.createNewFile(); + } + File economics = new File(buddyPath + "/economics"); if(!economics.exists()){ economics.mkdirs(); @@ -86,7 +92,7 @@ public class FirstMenuController { try { //Only proceeds to next scene if there is a budget selected if (FileHandlingSelectedBudget - .readSelectedBudget(filePath + "SelectedBudget") != null) { + .readSelectedBudget(filePath + "/SelectedBudget") != null) { switchNext(event); } } catch (IOException ioe) { @@ -156,7 +162,7 @@ public class FirstMenuController { try { //Only switches scenes if there is a budget that can be selected. if (FileHandlingSelectedBudget - .readSelectedBudget(filePath + "SelectedBudget") != null) { + .readSelectedBudget(filePath + "/SelectedBudget") != null) { switchChosenBudget(event); } } catch (IOException ioe) { diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/IncomeExpenseController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/IncomeExpenseController.java index 6550eda5154a3f77479c711a794df90b4f6dece5..c241fe7957205f93f66b86ad5bcb8050609f346d 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/IncomeExpenseController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/IncomeExpenseController.java @@ -150,7 +150,7 @@ public class IncomeExpenseController extends FinanceController { public void initialize() { String path = System.getProperty("user.home"); - filePath = path + "/BudgetBuddyFiles/budget/"; + filePath = path + "/BudgetBuddyFiles/budgets/"; //Initialize columns setColumns(); diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/MainMenuController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/MainMenuController.java index 5c38b30c2a411d2000cfd2c5630e962ac7ec1468..41dfe970b7fda563d4e432a60093bfedb3a56f83 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/MainMenuController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/MainMenuController.java @@ -91,7 +91,7 @@ public class MainMenuController { public void initialize() { String path = System.getProperty("user.home"); - filePath = path + "/BudgetBuddyFiles/budget"; + filePath = path + "/BudgetBuddyFiles/budgets"; //Initialize all registers + overview //TODO: instantiate sub-directories? diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/budget/FileHandlingSelectedBudget.java b/src/main/java/no/ntnu/idatt1002/demo/data/budget/FileHandlingSelectedBudget.java index 68a8fe91afd31de651033796791ae977d7bf918d..b0dd7c19e2ebe72465350675b2173c0d698b5682 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/budget/FileHandlingSelectedBudget.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/budget/FileHandlingSelectedBudget.java @@ -52,11 +52,13 @@ public class FileHandlingSelectedBudget { System.out.print("Updating current file to: " + fileDestination + selectedBudgetFileType + "->" + budgetName); +/* File file = new File(String.format("%s%s", fileDestination, selectedBudgetFileType)); +*/ - if (!file.exists()){ +/* if (!file.exists()){ file.createNewFile(); - } + }*/ try (BufferedWriter bw = new BufferedWriter(new FileWriter(fileDestination + selectedBudgetFileType))) { @@ -108,7 +110,8 @@ public class FileHandlingSelectedBudget { public static boolean createBudgetDirectory(String budgetId) { System.out.println("Creating directory: " + budgetId); File f = new File(budgetId); - return f.mkdir(); + //f.mkdirs(); + return f.mkdirs(); } /**