Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ include $(DEVKITARM)/3ds_rules
# Your values.
APP_TITLE := WifiManager
APP_DESCRIPTION := Backup and restore your WiFi slots!
APP_AUTHOR := LiquidFenrir
APP_AUTHOR := LiquidFenrir and Zakary2841


TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
Expand Down Expand Up @@ -87,7 +87,7 @@ ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft

CFLAGS := -g -Wall -Wextra -O2 -mword-relocations \
-ffunction-sections \
$(ARCH)
$(ARCH) -Wno-cpp

CFLAGS += $(INCLUDE) -DARM11 -D_3DS -D_GNU_SOURCE -DTITLE="\"$(APP_TITLE)\""

Expand Down
111 changes: 101 additions & 10 deletions source/blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern "C" {
#include "keyboard.h"
}
#include "drawing.h"
bool confirm_dialog(const char* message);

wifi_slot::wifi_slot()
{
Expand Down Expand Up @@ -83,7 +84,19 @@ Result wifi_slot::read_slot(void)
{
this->password = "(not available)";
}
}
if(this->id == -1)
{
size_t lastSlash = this->path.find_last_of("/\\");
if (lastSlash != std::string::npos) {
std::string fullFilename = this->path.substr(lastSlash + 1);
if (fullFilename.length() > 4 && fullFilename.substr(fullFilename.length() - 4) == ".bin") {
this->filename = fullFilename.substr(0, fullFilename.length() - 4);
} else {
this->filename = fullFilename;
}
}
}
}

return ret;
}
Expand Down Expand Up @@ -164,7 +177,44 @@ void wifi_slot::draw_info(bool to_the_right, bool hide_password)
if(hide_password)
pp2d_draw_text(text_x, text_y, text_scale_x, text_scale_y, COLOR_BLACK, "Password:\n(hidden)");
else
{
pp2d_draw_textf(text_x, text_y, text_scale_x, text_scale_y, COLOR_BLACK, "Password:\n%s", this->password.c_str());
}

text_y += 40;
if(this->slot_data.enable_autoDNS)
{
pp2d_draw_text(text_x, text_y, text_scale_x, text_scale_y, COLOR_BLACK, "DNS:\nAuto");
}
else
{
char primary_ip[16];
char secondary_ip[16];

snprintf(primary_ip, 16, "%u.%u.%u.%u",
this->slot_data.dns_primary[0],
this->slot_data.dns_primary[1],
this->slot_data.dns_primary[2],
this->slot_data.dns_primary[3]);

snprintf(secondary_ip, 16, "%u.%u.%u.%u",
this->slot_data.dns_secondary[0],
this->slot_data.dns_secondary[1],
this->slot_data.dns_secondary[2],
this->slot_data.dns_secondary[3]);

pp2d_draw_textf(
text_x,
text_y,
text_scale_x,
text_scale_y,
COLOR_BLACK,
"DNS:\nPri: %s\nSec: %s",
primary_ip,
secondary_ip
);
}

}

slots_list::slots_list()
Expand Down Expand Up @@ -239,6 +289,7 @@ void slots_list::draw_top(void)
}
void slots_list::draw_list(void)
{
pp2d_set_screen_color(GFX_BOTTOM, COLOR_WHITE);
pp2d_draw_on(GFX_BOTTOM, GFX_LEFT);
int x_offset = 15;
int y_offset = 81;
Expand Down Expand Up @@ -283,10 +334,26 @@ void slots_list::draw_list(void)
current_slot = this->backups[i-1];
}

if(i == this->selected_backup)
pp2d_draw_rectangle(x_offset+2, text_y-2, bg_width-4, pp2d_get_text_height(current_slot.name.c_str(), 0.6, 0.6)+2, COLOR_CURSOR);
pp2d_draw_text(text_x, text_y, 0.6, 0.6, COLOR_BLACK, current_slot.name.c_str());
std::string label = (!current_slot.filename.empty()) ? current_slot.filename : current_slot.name;

float scale = 0.6;
float max_width = bg_width - 10;

while (pp2d_get_text_width(label.c_str(), scale, scale) > max_width && label.length() > 4) {
label = label.substr(0, label.length() - 1);
}
if (label != current_slot.name && label != current_slot.filename) {
label = label.substr(0, label.length() - 2) + "...";
}
if(i == this->selected_backup)
pp2d_draw_rectangle(x_offset+2, text_y-2, bg_width-4, pp2d_get_text_height(label.c_str(), 0.6, 0.6)+2, COLOR_CURSOR);
pp2d_draw_text(text_x, text_y, 0.6, 0.6, COLOR_BLACK, label.c_str());
}
float scale = 0.5f;
float text_width = pp2d_get_text_width("Press START to exit", scale, scale);
float x_pos = (320.0f / 2.0f) - (text_width / 2.0f);
pp2d_draw_text(x_pos, 225, scale, scale, COLOR_BLACK, "Press START to exit");

}
void slots_list::draw_interface(void)
{
Expand All @@ -295,6 +362,11 @@ void slots_list::draw_interface(void)
this->backups[this->selected_backup-1].draw_info(true, this->passwords_hidden);
this->draw_top();
this->draw_list();
pp2d_draw_on(GFX_TOP, GFX_LEFT);
float scale = 0.5f;
float text_width = pp2d_get_text_width("Hold SELECT for instructions.", scale, scale);
float x_pos = (400.0f / 2.0f) - (text_width / 2.0f);
pp2d_draw_text(x_pos, 225, scale, scale, COLOR_BLACK, "Hold SELECT for instructions.");
}

void slots_list::next_slot_right(void)
Expand Down Expand Up @@ -332,8 +404,17 @@ void slots_list::select_slot(int id)

void slots_list::write_to(int id)
{
if(this->selected_backup != 0)
if(this->selected_backup == 0) return;
{
std::string targetSSID = this->slots[id].name;
std::string sourceProfile = this->backups[this->selected_backup-1].filename;
if (sourceProfile.empty()) sourceProfile = this->backups[this->selected_backup-1].name;
char msg[256];
snprintf(msg, sizeof(msg), "Overwrite Slot %i?\n%s\nwith %s?",
id+1, targetSSID.c_str(), sourceProfile.c_str());
if(!confirm_dialog(msg)) return;
this->slots[id].copy_slot(this->backups[this->selected_backup-1]);
}
}
void slots_list::save_from(int id)
{
Expand Down Expand Up @@ -363,7 +444,14 @@ void slots_list::save_from(int id)
free(file_name);
}
else
{
std::string targetProfile = this->backups[this->selected_backup-1].filename;
if (targetProfile.empty()) targetProfile = this->backups[this->selected_backup-1].name;
char msg[256];
snprintf(msg, sizeof(msg), "Overwrite backup:\n%s?", targetProfile.c_str());
if(!confirm_dialog(msg)) return;
this->backups[this->selected_backup-1].copy_slot(this->slots[id]);
}
}
}

Expand All @@ -378,11 +466,14 @@ void slots_list::save_from_selected(void)

void slots_list::delete_selected_backup(void)
{
if(this->selected_backup != 0)
{
this->backups[this->selected_backup-1].delete_slot();
this->backups.erase(this->backups.begin()+(--this->selected_backup));
}
if(this->selected_backup == 0) return;
wifi_slot slot = this->backups[this->selected_backup - 1];
std::string target = slot.filename.empty() ? slot.name : slot.filename;
char msg[128];
snprintf(msg, sizeof(msg), "Delete \"%s\" backup?", target.c_str());
if(!confirm_dialog(msg)) return;
this->backups[this->selected_backup - 1].delete_slot();
this->backups.erase(this->backups.begin() + (--this->selected_backup));
}

void slots_list::toggle_password_visibility(void)
Expand Down
1 change: 1 addition & 0 deletions source/blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class wifi_slot
bool exists;

std::string name;
std::string filename;
std::string password;

wifi_encryption_type encryption;
Expand Down
65 changes: 64 additions & 1 deletion source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@

#include "drawing.h"

#include <sstream>
#include <vector>
#include <string>

FS_Archive sdmcArchive;
touchPosition touch;

slots_list list;
const u32 COLOR_GRAY = 0xFF888888;

void draw_instructions(void)
{
Expand All @@ -25,6 +30,63 @@ void draw_instructions(void)
pp2d_draw_text_center(GFX_TOP, y_offset, 0.6, 0.6, COLOR_BLACK, "Press \uE002 to delete the highlighted backup.");
y_offset += 20;
pp2d_draw_text_center(GFX_TOP, y_offset, 0.6, 0.6, COLOR_BLACK, "Press \uE003 to toggle the passwords visibility.");
y_offset += 20;
pp2d_draw_text_center(GFX_TOP, y_offset, 0.6, 0.6, COLOR_BLACK, "Press START to exit.");
}

bool confirm_dialog(const char* message)
{
std::vector<std::string> lines;
std::string current_line;
std::stringstream ss(message);
std::string word;
float max_width = 260.0f;
float scale = 0.5f;
while(ss >> word)
{
std::string test_line = current_line.empty() ? word : current_line + " " + word;
float test_width = pp2d_get_text_width(test_line.c_str(), scale, scale);

if(test_width > max_width)
{
if(current_line.empty()) lines.push_back(word);
else {
lines.push_back(current_line);
current_line = word;
}
}
else
{
current_line = test_line;
}
}
if(!current_line.empty()) lines.push_back(current_line);

while(aptMainLoop())
{
hidScanInput();
u32 kDown = hidKeysDown();

pp2d_begin_draw(GFX_BOTTOM, GFX_LEFT);
pp2d_set_screen_color(GFX_BOTTOM, COLOR_WHITE);
pp2d_draw_rectangle(20, 80, 280, 80, COLOR_GRAY);

int current_y = 85;
for(auto &line : lines)
{
float text_width = pp2d_get_text_width(line.c_str(), scale, scale);
pp2d_draw_text(160 - (text_width / 2), current_y, 0.5, 0.5, COLOR_WHITE, line.c_str());
current_y += 12;
}

pp2d_draw_text(40, 130, 0.5, 0.5, COLOR_WHITE, "A : Yes B : No");

pp2d_end_draw();

if(kDown & KEY_A) return true;
if(kDown & KEY_B) return false;
}
return false;
}

int main(int argc, char ** argv)
Expand All @@ -33,7 +95,7 @@ int main(int argc, char ** argv)
romfsInit();
pp2d_init();
consoleDebugInit(debugDevice_SVC);

aptSetHomeAllowed(false);
pp2d_set_screen_color(GFX_TOP, COLOR_BACKGROUND);
pp2d_set_screen_color(GFX_BOTTOM, COLOR_BACKGROUND);
pp2d_load_texture_png(TEXTURE_SAVE, "romfs:/save.png");
Expand All @@ -56,6 +118,7 @@ int main(int argc, char ** argv)
u32 kHeld = hidKeysHeld();

pp2d_begin_draw(GFX_TOP, GFX_LEFT);
pp2d_set_screen_color(GFX_TOP, COLOR_WHITE);
if(kHeld & KEY_SELECT)
draw_instructions();
else
Expand Down
Loading