app: Refactor palette loaders.

I specifically moved the file opening/closing logic to the common
code. This makes the code easier to understand for me since there
is less duplication. In fact, this commit removes more lines than
it adds.