Saving and File System - Hamster339/Piping-Tool-Java GitHub Wiki

Intro

As shown in the user stories document, for the program to meet the minimum viable product, a user must be able to save their repertoire of tunes between different running of the program.

It has been decided that the best way to do this is to save the lists and tunes to a file, and to read that file back in on the next run of the program. This document will lay out how this has been implemented.

Repertoire method

While the program is running, the user's repertory will be stored as an object called Repertoire. This object contains attributes for the master list, and the other lists in the repository.

The master list is a list of all the tunes in the repertoire. A tune cannot be in another list and not the master list, and all tunes in other lists point to the objects stored in the master list. This reduces the number of duplicate objects. this si enforced in the load method and through the UI

This object is responsible for saving and loading the repertoire from the disk

File Organization

The user's piping repertoire will be stored in files with the custom extension .prl

Each file will contain one piping list, and all the tunes in it

There is a special default piping list, containing all the tunes added to the program. This enables the functionality of tunes being able to exist outside lists.

A list file will have the following structure:
N:<nameOfList>/n //other metadata may be added with later features
N:<nameoftune>T:<TIMESIGS>S:<STYLE>L:<SheetMusicLocation>"/n
N:<nameoftune>T:<TIMESIGS>S:<STYLE>L:<SheetMusicLocation>/n //new line for every tune on the list

  • A capital letter followed by an : designates an attribute
  • a string enclosed in <> represents the content of the attribute
  • /n is the end of a line

Load()

What it does

All tune and list objects stored in the files are read and created in the program

If the directory does not exist, or the master file does not exist, the program will skip loading. if a malformed file that causes an error is read, that file will be removed.

Load assumes Files alrady exist to load, if they dont loading is skipped. It is the responsibility of save to ensure directory and master file exist.

Error prevention

  • If any file has a defect that doesn't fit the format, that file will be removed.
  • If a list contains a tune that is not in the master list, it will be removed
  • Reporting of errors to be dealt with when UI is made in a later iteration

Save()

What it does

All the lists stored in the repertoire attribute will be written to files.

Error prevention

  • If the file cannot be saved, the user is notified
  • If Directory does not exist, it will be created
  • If Master file does not exist, it will be created
  • All files in directory are removed and re-written (may change later)
  • any unrecognized files are removed
⚠️ **GitHub.com Fallback** ⚠️