Skip to content

Commit b687872

Browse files
committed
added current version checking
1 parent 4d4ddfc commit b687872

File tree

10 files changed

+79
-35
lines changed

10 files changed

+79
-35
lines changed

bin/comp110/Controller.class

282 Bytes
Binary file not shown.

bin/comp110/Parser.class

447 Bytes
Binary file not shown.

bin/comp110/Storage$1.class

0 Bytes
Binary file not shown.

bin/comp110/Storage$2.class

0 Bytes
Binary file not shown.

bin/comp110/Storage.class

165 Bytes
Binary file not shown.

bin/tests/ParserTest.class

12 Bytes
Binary file not shown.

src/comp110/Controller.java

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Controller(UI ui) {
2020
public void cleanup() {
2121
this.m_storage.delete_storage();
2222
}
23-
23+
2424
public void uiUsernamePasswordCallback(Credentials credentials) {
2525
// save username and password for github
2626
this.m_storage.set_username(credentials.getUsername());
@@ -29,46 +29,55 @@ public void uiUsernamePasswordCallback(Credentials credentials) {
2929
// pull files from github
3030
this.m_storage.get_files();
3131
}
32-
33-
public void storage_get_files_complete(boolean success, String message){
32+
33+
public void storage_get_files_complete(boolean success, String message) {
3434
// let the ui know of success or failure
3535
Platform.runLater(() -> this.m_ui.githubPullResult(success, message));
36-
36+
// check version
37+
Platform.runLater(() -> {
38+
this.m_ui.checkVersion(
39+
this.m_parser.parseCurrentVersion(this.m_storage.get_shift_overflow_version_filename()));
40+
});
3741
// go ahead and give them the schedule immediately for use
38-
try{
39-
Schedule schedule = this.m_parser.parseSchedule(this.m_storage.get_schedule_json_filename(), this.m_storage.get_path_to_onyen_csv_directory(), this.m_storage.get_schedule_leads_filename());
42+
try {
43+
Schedule schedule = this.m_parser.parseSchedule(this.m_storage.get_schedule_json_filename(),
44+
this.m_storage.get_path_to_onyen_csv_directory(), this.m_storage.get_schedule_leads_filename());
4045
this.m_ui.setSchedule(schedule);
41-
} catch (Exception e){
46+
} catch (Exception e) {
4247
// tell the ui things suck
4348
this.m_ui.setSchedule(null);
44-
Platform.runLater(() -> this.m_ui.displayMessage("Controller::storage_get_files_complete(): " + e.toString()));
49+
Platform.runLater(
50+
() -> this.m_ui.displayMessage("Controller::storage_get_files_complete(): " + e.toString()));
4551
}
46-
}
47-
48-
public void storage_save_files_complete(boolean success, String message){
52+
}
53+
54+
public void storage_save_files_complete(boolean success, String message) {
4955
// let the ui know
50-
Platform.runLater(() -> this.m_ui.githubPushResult(success, message));
51-
}
56+
Platform.runLater(() -> this.m_ui.githubPushResult(success, message));
57+
}
5258

5359
public void uiRequestSchedule() {
54-
// tell the ui to show the schedule...this can/will be null if there was an exception
60+
// tell the ui to show the schedule...this can/will be null if there was
61+
// an exception
5562
// ui needs to be ready to handle null schedule
56-
try{
57-
Schedule schedule = this.m_parser.parseSchedule(this.m_storage.get_schedule_json_filename(), this.m_storage.get_path_to_onyen_csv_directory(), this.m_storage.get_schedule_leads_filename());
63+
try {
64+
Schedule schedule = this.m_parser.parseSchedule(this.m_storage.get_schedule_json_filename(),
65+
this.m_storage.get_path_to_onyen_csv_directory(), this.m_storage.get_schedule_leads_filename());
5866
this.m_ui.setSchedule(schedule);
5967
Platform.runLater(() -> this.m_ui.displaySchedule(schedule));
60-
} catch (Exception e){
68+
} catch (Exception e) {
6169
Platform.runLater(() -> this.m_ui.displayMessage("Controller::uiRequestSchedule(): " + e.toString()));
6270
}
6371
}
6472

6573
public void uiRequestEmployeeAvailability(String onyen) {
6674
// parse the employee
67-
try{
68-
Employee employee = this.m_parser.parseEmployee(this.m_storage.get_availability_csv_filename_from_onyen(onyen));
69-
//display available object on ui
70-
Platform.runLater(() -> this.m_ui.displayAvailable(employee));
71-
} catch (Exception e){
75+
try {
76+
Employee employee = this.m_parser
77+
.parseEmployee(this.m_storage.get_availability_csv_filename_from_onyen(onyen));
78+
// display available object on ui
79+
Platform.runLater(() -> this.m_ui.displayAvailable(employee));
80+
} catch (Exception e) {
7281
this.m_ui.createNewEmployeeCSV(onyen);
7382
}
7483
}
@@ -78,33 +87,34 @@ public void uiRequestSwaps() {
7887
}
7988

8089
public void uiRequestSaveAvailability(Employee employee, String commit_message) {
81-
// need to tell parser to save this employee object and what filename to save it as
82-
if (employee == null){
90+
// need to tell parser to save this employee object and what filename to
91+
// save it as
92+
if (employee == null) {
8393
// unable to save
8494
this.m_ui.displayMessage("Controller::uiRequestSaveAvailability(): Employee is null");
8595
return;
8696
}
87-
97+
8898
String filename = this.m_storage.get_availability_csv_filename_from_onyen(employee.getOnyen());
89-
try{
99+
try {
90100
// have the parser write out the file
91101
this.m_parser.writeFile(employee, filename);
92102
// have storage push to the repo
93103
this.m_storage.save_files(commit_message);
94-
} catch (Exception e){
104+
} catch (Exception e) {
95105
this.m_ui.displayMessage("Controller::uiRequestSaveAvailability(): " + e.toString());
96106
}
97107
}
98-
99-
public void uiRequestChangeSchedule(Schedule schedule, String commit_message){
100-
try{
101-
this.m_parser.writeScheduleToJson(schedule, this.m_storage.get_schedule_json_filename());
102-
this.m_storage.save_files(commit_message);
103-
} catch (Exception e){
108+
109+
public void uiRequestChangeSchedule(Schedule schedule, String commit_message) {
110+
try {
111+
this.m_parser.writeScheduleToJson(schedule, this.m_storage.get_schedule_json_filename());
112+
this.m_storage.save_files(commit_message);
113+
} catch (Exception e) {
104114
this.m_ui.displayMessage("Controller::uiRequestChangeSchedule(): " + e.toString());
105115
}
106116
}
107-
117+
108118
public void displayMessage(String message) {
109119
this.m_ui.displayMessage(message);
110120
}

src/comp110/Parser.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,22 @@ public void writeScheduleToJson(Schedule schedule, String path) throws Exception
278278
throw new Exception("Parser::writeScheduleToJson(): Unable to open file=" + path);
279279
}
280280
}
281+
282+
public String parseCurrentVersion(String versionPath) {
283+
BufferedReader reader = null;
284+
try {
285+
reader = new BufferedReader(new FileReader(versionPath));
286+
} catch (FileNotFoundException e) {
287+
return ""; //if we can't find the file just carry on
288+
}
289+
String currentVersion = null;
290+
try {
291+
currentVersion = reader.readLine();
292+
reader.close();
293+
} catch (IOException e) { //This should never happen
294+
System.err.println("lol this should never happen");
295+
e.printStackTrace();
296+
}
297+
return currentVersion;
298+
}
281299
}

src/comp110/Storage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public String get_schedule_json_filename(){
7070
public String get_schedule_leads_filename(){
7171
return this.m_application_directory + DEFAULT_LOCAL_REPO_FOLDER + "/data/leads.csv";
7272
}
73+
74+
public String get_shift_overflow_version_filename(){
75+
return this.m_application_directory + DEFAULT_LOCAL_REPO_FOLDER + "/data/currentShiftOverflowVersion.txt";
76+
}
7377

7478
public String get_path_to_onyen_csv_directory(){
7579
return this.m_application_directory + DEFAULT_LOCAL_REPO_FOLDER + "/data/fall-17/staff/";

src/ui/UI.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class UI extends Application {
3434
private boolean _scheduleStageIsOpen;
3535
private ScheduleStage _scheduleStage;
3636
private ViewSwapsStage _viewSwapsStage;
37+
38+
private static final String VERSION = "0.3.1";
3739

3840

3941
@Override
@@ -119,7 +121,7 @@ public void displayAvailable(Employee employee) {
119121
if (_availabilityStage != null){
120122
_availabilityStage.close();
121123
}
122-
_availabilityStage = new AvailabilityStage("ShiftOverflow v0.3.1", _controller, this);
124+
_availabilityStage = new AvailabilityStage("ShiftOverflow v" + VERSION, _controller, this);
123125
_availabilityStage.show();
124126
}
125127

@@ -275,6 +277,16 @@ public List<String> getHoursList(String day) {
275277
}
276278
return hoursList;
277279
}
280+
281+
public void checkVersion(String currentVersion) {
282+
if (currentVersion.equals("")) { //if we couldn't find version file just don't worry about it
283+
return;
284+
}
285+
if (currentVersion != UI.VERSION) {
286+
// tell user they need to update
287+
displayMessage("You are not using the current version of ShiftOverflow. The current version is v" + currentVersion + ". Please close and update by visiting\ngithub.com/comp110/ShiftOverflow/releases/tag/v" + currentVersion + " before continuing.", false);
288+
}
289+
}
278290

279291
public void githubPullResult(boolean success, String message) {
280292
if (success == true) {

0 commit comments

Comments
 (0)