♻️ Bunch of refactoring and clean up for release.

dev v1.1.0
Nichole Mattera 3 years ago
parent 1d28746e9e
commit e60c899cc0
  1. 2
      Makefile
  2. 123
      RomFS/chocolate-doom.cfg
  3. 42
      RomFS/default.cfg
  4. 31
      Source/Main.cpp
  5. 18
      Source/Scenes/GameSelection.cpp
  6. 1
      Source/Scenes/GameSelection.hpp
  7. 25
      Source/Scenes/Update.cpp
  8. 1
      Source/Scenes/Update.hpp
  9. 82
      Source/Services/File.cpp
  10. 5
      Source/Services/File.hpp
  11. 4
      Source/Services/Web.cpp

@ -44,7 +44,7 @@ ROMFS := RomFS
APP_TITLE := Chocolate Doom Launcher
APP_AUTHOR := Nichole Mattera (Port: MVG)
APP_VERSION := 1.0.0
APP_VERSION := 1.1.0
#---------------------------------------------------------------------------------
# options for code generation

@ -0,0 +1,123 @@
aspect_ratio_correct 1
integer_scaling 1
vga_porch_flash 0
force_software_renderer 0
max_scaling_buffer_pixels 16000000
show_endoom 1
show_diskicon 1
png_screenshots 0
snd_samplerate 44100
snd_cachesize 67108864
snd_maxslicetime_ms 28
snd_pitchshift 0
snd_musiccmd ""
snd_dmxoption ""
opl_io_port 0x388
music_pack_path ""
timidity_cfg_path ""
vanilla_savegame_limit 1
vanilla_demo_limit 1
vanilla_keyboard_mapping 1
player_name "Player"
novert 0
mouse_acceleration 2.000000
mouse_threshold 10
mouseb_strafeleft -1
mouseb_straferight -1
mouseb_use -1
mouseb_backward -1
mouseb_prevweapon -1
mouseb_nextweapon -1
dclick_use 0
joystick_guid ""
joystick_index -1
joystick_x_axis 2
joystick_x_invert 0
joystick_y_axis 1
joystick_y_invert 0
joystick_strafe_axis 0
joystick_strafe_invert 0
joystick_look_axis -1
joystick_look_invert 0
joystick_physical_button0 0
joystick_physical_button1 1
joystick_physical_button2 2
joystick_physical_button3 3
joystick_physical_button4 4
joystick_physical_button5 5
joystick_physical_button6 6
joystick_physical_button7 7
joystick_physical_button8 8
joystick_physical_button9 9
joystick_physical_button10 10
joystick_physical_button11 11
joystick_physical_button12 12
joystick_physical_button13 13
joystick_physical_button14 14
joystick_physical_button15 15
joyb_menu_up 13
joyb_menu_down 15
joyb_menu_left 12
joyb_menu_right 14
joyb_forward 13
joyb_backward 15
joyb_strafeleft 12
joyb_straferight 14
joyb_menu_activate 10
joyb_toggle_automap 2
joyb_prevweapon 6
joyb_nextweapon 7
key_pause 69
key_menu_activate 1
key_menu_up 72
key_menu_down 80
key_menu_left 75
key_menu_right 77
key_menu_back 14
key_menu_forward 28
key_menu_confirm 21
key_menu_abort 49
key_menu_help 59
key_menu_save 60
key_menu_load 61
key_menu_volume 62
key_menu_detail 63
key_menu_qsave 64
key_menu_endgame 65
key_menu_messages 66
key_menu_qload 67
key_menu_quit 68
key_menu_gamma 87
key_spy 88
key_menu_incscreen 13
key_menu_decscreen 12
key_menu_screenshot 0
key_map_toggle 15
key_map_north 72
key_map_south 80
key_map_east 77
key_map_west 75
key_map_zoomin 13
key_map_zoomout 12
key_map_maxzoom 11
key_map_follow 33
key_map_grid 34
key_map_mark 50
key_map_clearmark 46
key_weapon1 2
key_weapon2 3
key_weapon3 4
key_weapon4 5
key_weapon5 6
key_weapon6 7
key_weapon7 8
key_weapon8 9
key_prevweapon 0
key_nextweapon 0
key_message_refresh 28
key_demo_quit 16
key_multi_msg 20
key_multi_msgplayer1 34
key_multi_msgplayer2 23
key_multi_msgplayer3 48
key_multi_msgplayer4 19

@ -0,0 +1,42 @@
mouse_sensitivity 5
sfx_volume 8
music_volume 8
show_messages 1
key_right -1
key_left -1
key_up -1
key_down -1
key_strafeleft -1
key_straferight -1
key_fire -1
key_use -1
key_strafe -1
key_speed -1
mouseb_fire -1
mouseb_strafe -1
mouseb_forward -1
use_joystick 1
joyb_fire 9
joyb_strafe 2
joyb_use 1
joyb_speed 8
screenblocks 10
detaillevel 0
snd_channels 8
snd_musicdevice 3
snd_sfxdevice 3
snd_sbport 0
snd_sbirq 0
snd_sbdma 0
snd_mport 0
usegamma 0
chatmacro0 "No"
chatmacro1 "I'm ready to kick butt!"
chatmacro2 "I'm OK."
chatmacro3 "I'm not looking too good!"
chatmacro4 "Help!"
chatmacro5 "You suck!"
chatmacro6 "Next time, scumbag..."
chatmacro7 "Come here!"
chatmacro8 "I'll take care of it."
chatmacro9 "Yes"

@ -26,37 +26,14 @@
int main(int argc, char *argv[]) {
auto * app = new ChocolateDoomLauncher::Application(argc, argv);
// Make sure our folder structure is in place.
if (!ChocolateDoomLauncher::Services::File::directoryExists("./dehs")) {
ChocolateDoomLauncher::Services::File::createDirectories("./dehs");
}
if (!ChocolateDoomLauncher::Services::File::directoryExists("./mods")) {
ChocolateDoomLauncher::Services::File::createDirectories("./mods");
}
if (!ChocolateDoomLauncher::Services::File::directoryExists("./savegames")) {
ChocolateDoomLauncher::Services::File::createDirectories("./savegames");
}
if (!ChocolateDoomLauncher::Services::File::directoryExists("./wads")) {
ChocolateDoomLauncher::Services::File::createDirectories("./wads");
}
ChocolateDoomLauncher::Services::File::initialSetup();
// Start our first scene.
int val;
if (!app->hasArgument("-do-not-update") && ChocolateDoomLauncher::Services::Web::hasInternetConnection()) {
val = app->start(new ChocolateDoomLauncher::Scenes::Update());
if (ChocolateDoomLauncher::Services::File::fileExists("./doom.nro")) {
val = app->start(new ChocolateDoomLauncher::Scenes::GameSelection());
} else {
// Check if Chocolate Doom exists.
auto exists = ChocolateDoomLauncher::Services::File::fileExists("./doom.nro");
if (exists) {
val = app->start(new ChocolateDoomLauncher::Scenes::GameSelection());
} else {
val = app->start(new ChocolateDoomLauncher::Scenes::Error("Chocolate Doom NX is missing, please download Chocolate Doom NX and install it into:\n \n" + ChocolateDoomLauncher::Services::File::currentWorkingDirectory()));
}
val = app->start(new ChocolateDoomLauncher::Scenes::Error("Chocolate Doom NX is missing, please download Chocolate Doom NX and install it into:\n \n" + ChocolateDoomLauncher::Services::File::currentWorkingDirectory()));
}
// Clean up.

@ -22,12 +22,14 @@
#include "Error.hpp"
#include "GameSelection.hpp"
#include "Update.hpp"
#include "../Application.hpp"
#include "../Constants.hpp"
#include "../Models/FooterAction.hpp"
#include "../Services/Doom.hpp"
#include "../Services/File.hpp"
#include "../Services/Theme.hpp"
#include "../Services/Web.hpp"
namespace ChocolateDoomLauncher::Scenes {
GameSelection::GameSelection() {
@ -42,7 +44,7 @@ namespace ChocolateDoomLauncher::Scenes {
_background->frame = { 0, 0, 1280, 720 };
addSubView(_background);
_header = new Views::Header("Choose a game", true);
_header = new Views::Header("Choose a Game", true);
_header->frame = { 0, 0, 1280, 88 };
addSubView(_header);
@ -58,9 +60,18 @@ namespace ChocolateDoomLauncher::Scenes {
auto openIWADAction = new Models::FooterAction();
openIWADAction->button = A_BUTTON;
openIWADAction->text = "Start game";
openIWADAction->text = "Start Game";
_footer->addAction(openIWADAction);
if (Services::Web::hasInternetConnection()) {
_canUpdate = true;
auto updateAction = new Models::FooterAction();
updateAction->button = Y_BUTTON;
updateAction->text = "Check for Updates";
_footer->addAction(updateAction);
}
auto quitAction = new Models::FooterAction();
quitAction->button = B_BUTTON;
quitAction->text = "Quit";
@ -102,6 +113,9 @@ namespace ChocolateDoomLauncher::Scenes {
Application::switchScene(new Error("Unable to start Chocolate Doom."));
}
}
else if (buttons & KEY_Y && _canUpdate) {
Application::switchScene(new Update());
}
else if (buttons & KEY_B) {
Application::switchScene(NULL);
}

@ -43,6 +43,7 @@ namespace ChocolateDoomLauncher::Scenes {
private:
SDL_Texture * _backgroundTexture = NULL;
std::vector<Models::Game> _games;
bool _canUpdate = false;
Views::Image * _background = NULL;
Views::Header * _header = NULL;

@ -42,7 +42,7 @@ namespace ChocolateDoomLauncher::Scenes {
_background->frame = { 0, 0, 1280, 720 };
addSubView(_background);
_header = new Views::Header("Chocolate Doom Launcher", true);
_header = new Views::Header("Checking for Updates", true);
_header->frame = { 0, 0, 1280, 88 };
addSubView(_header);
@ -58,8 +58,6 @@ namespace ChocolateDoomLauncher::Scenes {
_footer = new Views::Footer();
_footer->frame = { 0, 647, 1280, 73 };
addSubView(_footer);
}
Update::~Update() {
@ -90,9 +88,9 @@ namespace ChocolateDoomLauncher::Scenes {
if (!restartRequired) {
Application::switchScene(new Scenes::GameSelection());
} else {
// Need to restart the launcher if it was updated.
auto path = Application::currentApplication->getPath();
auto args = path + " -do-not-update";
envSetNextLoad(path.c_str(), args.c_str());
envSetNextLoad(path.c_str(), path.c_str());
Application::switchScene(NULL);
}
@ -100,20 +98,17 @@ namespace ChocolateDoomLauncher::Scenes {
}
}
void Update::buttonsDown(u32 buttons, double dTime) {
}
bool Update::_updateLauncher() {
Application::currentApplication->render();
// Get the latest version from the server.
auto latestVersion = Services::Web::getLatestVersion(
"NicholeMattera",
"Chocolate-Doom-Launcher",
std::bind(&Update::_onProgressUpdate, this, std::placeholders::_1)
);
// If there isn't a newer version
// Bail out if there isn't a newer version.
if (!Services::Version::isNewerVersion(Services::Version::getCurrentVersion(), Services::Version::sanitizeVersion(latestVersion))) {
return false;
}
@ -121,6 +116,7 @@ namespace ChocolateDoomLauncher::Scenes {
_text->setText("Getting latest release of Chocolate Doom Launcher...");
Application::currentApplication->render();
// Get the latest release URL from the server.
auto latestReleaseURL = Services::Web::getLatestReleaseURL(
"NicholeMattera",
"Chocolate-Doom-Launcher",
@ -132,6 +128,7 @@ namespace ChocolateDoomLauncher::Scenes {
Application::currentApplication->render();
Application::currentApplication->closeRomFS();
// Download the latest release.
std::string appPath = Application::currentApplication->getPath();
auto launcher = Services::Web::downloadFile(
latestReleaseURL,
@ -139,6 +136,7 @@ namespace ChocolateDoomLauncher::Scenes {
std::bind(&Update::_onProgressUpdate, this, std::placeholders::_1)
);
// Overwrite the file if we were successful.
if (launcher[0] == '1') {
Services::File::deleteFile(appPath);
rename((appPath + ".tmp").c_str(), appPath.c_str());
@ -153,16 +151,19 @@ namespace ChocolateDoomLauncher::Scenes {
auto doomExists = Services::File::fileExists("./doom.nro");
auto newVersionAvailable = false;
// If for some reason we don't have it then just download the latest.
if (doomExists) {
_text->setText("Checking for updates of Chocolate Doom NX...");
Application::currentApplication->render();
// Get the latest version from the server.
auto latestVersion = Services::Web::getLatestVersion(
"NicholeMattera",
"chocolate-doom-nx",
std::bind(&Update::_onProgressUpdate, this, std::placeholders::_1)
);
// Bail out if there isn't a newer version.
newVersionAvailable = Services::Version::isNewerVersion(
Services::Version::getVersionOfApp("./doom.nro"),
Services::Version::sanitizeVersion(latestVersion)
@ -174,6 +175,7 @@ namespace ChocolateDoomLauncher::Scenes {
_text->setText("Getting latest release of Chocolate Doom NX...");
Application::currentApplication->render();
// Get the latest release URL from the server.
auto latestReleaseURL = Services::Web::getLatestReleaseURL(
"NicholeMattera",
"chocolate-doom-nx",
@ -184,12 +186,15 @@ namespace ChocolateDoomLauncher::Scenes {
_text->setText("Downloading latest release of Chocolate Doom NX...");
Application::currentApplication->render();
// Download the latest release.
auto game = Services::Web::downloadFile(
latestReleaseURL,
"./doom.nro.tmp",
std::bind(&Update::_onProgressUpdate, this, std::placeholders::_1)
);
// Overwrite the file if we were successful.
if (game[0] == '1') {
Services::File::deleteFile("./doom.nro");
rename("./doom.nro.tmp", "./doom.nro");

@ -34,7 +34,6 @@ namespace ChocolateDoomLauncher::Scenes {
Update();
~Update();
void tick(SDL_Rect rect, double dTime);
void buttonsDown(u32 buttons, double dTime);
private:
SDL_Texture * _backgroundTexture = NULL;

@ -19,7 +19,9 @@
#include <dirent.h>
#include <iostream>
#include <fstream>
#include <limits.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/unistd.h>
@ -27,6 +29,41 @@
#include "File.hpp"
namespace ChocolateDoomLauncher::Services {
void File::initialSetup() {
// Make sure our folder structure is in place.
if (!directoryExists("./dehs"))
createDirectories("./dehs");
if (!directoryExists("./mods"))
createDirectories("./mods");
if (!directoryExists("./savegames"))
createDirectories("./savegames");
if (!directoryExists("./wads"))
createDirectories("./wads");
if (!fileExists("./chocolate-doom.cfg"))
copyFile("romfs:/chocolate-doom.cfg", "./chocolate-doom.cfg");
if (!fileExists("./default.cfg"))
copyFile("romfs:/default.cfg", "./default.cfg");
// I messed up with 1.0.0 and Chocolate Doom NX had the root SD as
// the current working directory. Lets clean up our mess.
if (directoryExists("sdmc:/savegames")) {
recursiveMove("sdmc:/savegames", "./savegames");
}
if (fileExists("sdmc:/chocolate-doom.cfg")) {
deleteFile("sdmc:/chocolate-doom.cfg");
}
if (fileExists("sdmc:/default.cfg")) {
deleteFile("sdmc:/default.cfg");
}
}
std::string File::currentWorkingDirectory() {
char path[PATH_MAX];
getcwd(path, PATH_MAX);
@ -90,6 +127,25 @@ namespace ChocolateDoomLauncher::Services {
return result;
}
bool File::copyFile(std::string source, std::string destination) {
std::ifstream sourceStream(source, std::ios::binary);
if (!sourceStream.is_open())
return false;
std::ofstream destinationStream(destination, std::ios::binary);
if (!destinationStream.is_open())
return false;
destinationStream << sourceStream.rdbuf();
sourceStream.close();
destinationStream.flush();
destinationStream.close();
return true;
}
bool File::deleteFile(std::string path) {
if (fileExists(path)) {
return remove(path.c_str()) == 0;
@ -120,4 +176,30 @@ namespace ChocolateDoomLauncher::Services {
return files;
}
void File::recursiveMove(std::string source, std::string destination) {
struct stat info;
stat(source.c_str(), &info);
if (S_ISDIR(info.st_mode)) {
if (!directoryExists(destination)) {
createDirectories(destination);
}
auto directory = opendir(source.c_str());
struct dirent * entry;
while ((entry = readdir(directory)) != NULL) {
if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) {
continue;
}
recursiveMove(source + "/" + entry->d_name, destination + "/" + entry->d_name);
}
closedir(directory);
rmdir(source.c_str());
} else {
rename(source.c_str(), destination.c_str());
}
}
}

@ -25,16 +25,19 @@
namespace ChocolateDoomLauncher::Services {
class File {
public:
static void initialSetup();
static std::string currentWorkingDirectory();
static bool directoryExists(std::string path);
static bool createDirectories(std::string path);
static std::string sanitizeDirectoryName(std::string name);
static bool copyFile(std::string source, std::string destination);
static bool deleteFile(std::string path);
static bool fileExists(std::string path);
static std::vector<std::string> filenamesInDirectory(std::string path);
private:
static void recursiveMove(std::string source, std::string destination);
};
}

@ -76,6 +76,10 @@ namespace ChocolateDoomLauncher::Services {
if (!path.empty()) {
file.open(path, std::ios::out | std::ios::binary | std::ios::trunc);
if (!file.is_open()) {
buffer.push_back('0');
return buffer;
}
}
CURL * curl = curl_easy_init();

Loading…
Cancel
Save