Revision 10ae4f11
Added by david.sorber over 2 years ago
| src/main.cc | ||
|---|---|---|
|
// Important to understand: SDL_Renderer is an _optional_ component of SDL2.
|
||
|
// For a multi-platform app consider using e.g. SDL+DirectX on Windows and
|
||
|
// SDL+OpenGL on Linux/OSX.
|
||
|
|
||
|
#include <algorithm>
|
||
|
#include <cstdio>
|
||
|
#include <cstdint>
|
||
|
#include <cstring>
|
||
|
#include <filesystem>
|
||
|
#include <iostream>
|
||
|
#include <map>
|
||
|
#include <string>
|
||
|
#include <vector>
|
||
|
#include <string_view>
|
||
|
|
||
|
#include <SDL.h>
|
||
|
|
||
| ... | ... | |
|
#include "RobotoMedium.h"
|
||
|
|
||
|
|
||
|
namespace sfs = std::filesystem;
|
||
|
|
||
|
#if !SDL_VERSION_ATLEAST(2,0,17)
|
||
|
#error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function
|
||
|
#endif
|
||
|
|
||
|
const std::string APP_NAME("pwmgr");
|
||
|
const std::string VERSION("v0.1.3");
|
||
|
const std::string VERSION("v0.1.4");
|
||
|
const std::string DEFAULT_FILEPATH("/home/dsorber/Documents/chicken_soup/chicken_soup.txt.enc");
|
||
|
|
||
|
const std::string BOLD{"\033[1m"};
|
||
| ... | ... | |
|
const char* STR_EMPTY = "";
|
||
|
const char* STR_PWD = "enter password and click \"Load\"";
|
||
|
const char* STR_LOADING = "Loading...";
|
||
|
const char* STR_BAD_FILE = "specified input file does not exist";
|
||
|
|
||
|
static ImGuiInputTextFlags MULTILINE_TEXT_FLAGS =
|
||
|
ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_ReadOnly;
|
||
| ... | ... | |
|
bool loading = false;
|
||
|
char filterBuffer[128]{};
|
||
|
char filePathBuffer[BUFFER_SIZE]{};
|
||
|
std::memcpy(filePathBuffer, DEFAULT_FILEPATH.data(), DEFAULT_FILEPATH.size());
|
||
|
if (argc == 2)
|
||
|
{
|
||
|
// Use command line specified file path
|
||
|
std::string_view cmdLineFilePath(argv[1]);
|
||
|
size_t copySize = std::min(BUFFER_SIZE,
|
||
|
static_cast<uint32_t>(cmdLineFilePath.size()));
|
||
|
std::memcpy(filePathBuffer, argv[1], copySize);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Use default file path
|
||
|
std::memcpy(filePathBuffer, DEFAULT_FILEPATH.data(),
|
||
|
DEFAULT_FILEPATH.size());
|
||
|
}
|
||
|
const char* statusText = STR_PWD;
|
||
|
|
||
|
char passwdBuffer[BUFFER_SIZE]{};
|
||
| ... | ... | |
|
|
||
|
if (ImGui::Button("Load"))
|
||
|
{
|
||
|
loading = true;
|
||
|
statusText = STR_LOADING;
|
||
|
if (sfs::exists(filePathBuffer))
|
||
|
{
|
||
|
loading = true;
|
||
|
statusText = STR_LOADING;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
statusText = STR_BAD_FILE;
|
||
|
//TODO:
|
||
|
std::cerr << ERROR_MSG << "Input file: \""
|
||
|
<< filePathBuffer << "\" does not exist!"
|
||
|
<< std::endl;
|
||
|
}
|
||
|
}
|
||
|
ImGui::SameLine();
|
||
|
|
||
| ... | ... | |
|
iter.getValueBuffer(),
|
||
|
iter.getValueBufferSize(),
|
||
|
ImVec2(-FLT_MIN,
|
||
|
ImGui::GetTextLineHeight() * 5),
|
||
|
ImGui::GetTextLineHeight() * 5),
|
||
|
MULTILINE_TEXT_FLAGS);
|
||
|
}
|
||
|
}
|
||
Add the ability to specify the input file path as a command line argument. Bumping to v0.1.4.