Skip to content
Snippets Groups Projects
Commit b6619f03 authored by HSoreide's avatar HSoreide
Browse files

Refactor towards external persistent storage

parent f89fd40a
No related branches found
No related tags found
1 merge request!61Hs master pom file for executable jar
Pipeline #222402 passed
......@@ -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());
}
......
......@@ -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) {
......
......@@ -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();
......
......@@ -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?
......
......@@ -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();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment