Revision f16b75e3
Added by david.sorber over 2 years ago
| src/main.cpp | ||
|---|---|---|
|
|
||
|
#include <cstdio>
|
||
|
#include <cstdint>
|
||
|
#include <cstring>
|
||
|
#include <iostream>
|
||
|
#include <map>
|
||
|
#include <string>
|
||
| ... | ... | |
|
#endif
|
||
|
|
||
|
const std::string APP_NAME("pwmgr");
|
||
|
const std::string VERSION("v0.0.1");
|
||
|
const std::string VERSION("v0.1.0");
|
||
|
const std::string DEFAULT_FILEPATH("/home/dsorber/Documents/chicken_soup/chicken_soup.txt.enc");
|
||
|
|
||
|
const std::string BOLD{"\033[1m"};
|
||
|
const std::string ENDC{"\033[0m"};
|
||
| ... | ... | |
|
const std::string LBLUE{"\033[1;34m"};
|
||
|
const std::string UP_ONE = "\033[1A";
|
||
|
|
||
|
const uint32_t BUFFER_SIZE{2048};
|
||
|
|
||
|
|
||
|
#define ERROR_MSG BOLD << RED << "ERROR: " << ENDC
|
||
|
|
||
| ... | ... | |
|
}
|
||
|
|
||
|
// Debuggery
|
||
|
// std::cout << "BUFFER: " << data->Buf << std::endl;
|
||
|
// std::cout << "BUFFER: " << data->Buf << std::endl;
|
||
|
|
||
|
// Now filter the catalog
|
||
|
catalog.filter(data->Buf);
|
||
| ... | ... | |
|
|
||
|
// Main loop
|
||
|
bool done = false;
|
||
|
bool dataLoaded = false;
|
||
|
bool loading = false;
|
||
|
bool showOptionsWin = false;
|
||
|
char filterBuffer[128]{};
|
||
|
char filePathBuffer[BUFFER_SIZE]{};
|
||
|
std::memcpy(filePathBuffer, DEFAULT_FILEPATH.data(), DEFAULT_FILEPATH.size());
|
||
|
|
||
|
char passwdBuffer[BUFFER_SIZE]{};
|
||
|
while (! done)
|
||
|
{
|
||
|
// Poll and handle events (inputs, window resize, etc.)
|
||
| ... | ... | |
|
#endif
|
||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||
|
ImGui::Begin("inner_window", nullptr,
|
||
|
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_MenuBar);
|
||
|
ImGuiWindowFlags_NoDecoration |
|
||
|
ImGuiWindowFlags_MenuBar |
|
||
|
ImGuiWindowFlags_NoSavedSettings);
|
||
|
|
||
|
|
||
|
ImGui::PushFont(font);
|
||
|
{
|
||
|
//---[Menu bar]-----------------------------------------------------
|
||
|
if (ImGui::BeginMenuBar())
|
||
|
if (! dataLoaded)
|
||
|
{
|
||
|
if (ImGui::BeginMenu("File"))
|
||
|
//---Data loading screen----------------------------------------
|
||
|
ImGui::Text("Hello from the loading screen");
|
||
|
ImGui::InputText("Input file", filePathBuffer,
|
||
|
IM_ARRAYSIZE(filePathBuffer));
|
||
|
|
||
|
// Set default focus on the password text box
|
||
|
// See: https://github.com/ocornut/imgui/issues/455
|
||
|
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
|
||
|
!ImGui::IsAnyItemActive() &&
|
||
|
!ImGui::IsMouseClicked(0))
|
||
|
{
|
||
|
if (ImGui::MenuItem("Close", "Ctrl+W"))
|
||
|
{
|
||
|
std::cerr << ERROR_MSG << "Closing it out" << std::endl;
|
||
|
done = true;
|
||
|
}
|
||
|
ImGui::EndMenu();
|
||
|
ImGui::SetKeyboardFocusHere(0);
|
||
|
}
|
||
|
ImGui::EndMenuBar();
|
||
|
}
|
||
|
|
||
|
//---[Left side]----------------------------------------------------
|
||
|
static int selected = 0;
|
||
|
{
|
||
|
ImGui::BeginChild("left_pane", ImVec2(150, 0),
|
||
|
ImGuiChildFlags_Border | ImGuiChildFlags_ResizeX);
|
||
|
if (ImGui::InputText("Password", passwdBuffer,
|
||
|
IM_ARRAYSIZE(passwdBuffer),
|
||
|
ImGuiInputTextFlags_Password |
|
||
|
ImGuiInputTextFlags_EnterReturnsTrue))
|
||
|
{
|
||
|
loading = true;
|
||
|
}
|
||
|
|
||
|
|
||
|
if (ImGui::Button("Exit"))
|
||
|
{
|
||
|
done = true;
|
||
|
}
|
||
|
ImGui::SameLine();
|
||
|
|
||
|
for (auto& iter : catalog)
|
||
|
if (ImGui::Button("Load"))
|
||
|
{
|
||
|
// ImGuiInputTextFlags_ReadOnly
|
||
|
if (iter.visible() &&
|
||
|
ImGui::CollapsingHeader(iter.getKey().c_str()))
|
||
|
loading = true;
|
||
|
}
|
||
|
ImGui::SameLine();
|
||
|
|
||
|
if (loading)
|
||
|
{
|
||
|
ImGui::Text("Loading...");
|
||
|
|
||
|
// Load the catalog from the encrypted file
|
||
|
int rc = catalog.load(filePathBuffer,
|
||
|
passwdBuffer,
|
||
|
BUFFER_SIZE,
|
||
|
nullptr);
|
||
|
|
||
|
// ImGui::ProgressBar(
|
||
|
// sinf((float) ImGui::GetTime()) * 0.5f + 0.5f,
|
||
|
// ImVec2(ImGui::GetFontSize() * 25, 0.0f));
|
||
|
|
||
|
// Switch modes once loaded
|
||
|
if (rc == 0 && catalog.getLoaded())
|
||
|
{
|
||
|
dataLoaded = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// ImGui::Text("%s", iter.second.c_str());
|
||
|
ImGui::InputTextMultiline(
|
||
|
iter.getLcKey().c_str(),
|
||
|
iter.getValueBuffer(),
|
||
|
iter.getValueBufferSize(),
|
||
|
ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 4),
|
||
|
MULTILINE_TEXT_FLAGS);
|
||
|
// Display error
|
||
|
std::cerr << ERROR_MSG << Catalog::errToString(rc) << std::endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ImGui::EndChild();
|
||
|
}
|
||
|
ImGui::SameLine();
|
||
|
|
||
|
//---[Right side]---------------------------------------------------
|
||
|
else
|
||
|
{
|
||
|
ImGui::BeginGroup();
|
||
|
ImGui::BeginChild("item view",
|
||
|
ImVec2(0, -ImGui::GetFrameHeightWithSpacing()));
|
||
|
|
||
|
char filterBuffer[128]{};
|
||
|
ImGui::InputText("Filter", filterBuffer,
|
||
|
IM_ARRAYSIZE(filterBuffer),
|
||
|
ImGuiInputTextFlags_CallbackEdit,
|
||
|
catalogFilterCallback);
|
||
|
|
||
|
ImGui::Separator();
|
||
|
if (ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None))
|
||
|
//---[Menu bar]-----------------------------------------------------
|
||
|
if (ImGui::BeginMenuBar())
|
||
|
{
|
||
|
if (ImGui::BeginTabItem("Options"))
|
||
|
if (ImGui::BeginMenu("File"))
|
||
|
{
|
||
|
ImGui::TextWrapped(
|
||
|
"Lorem ipsum dolor sit amet, consectetur adipiscing "
|
||
|
"elit, sed do eiusmod tempor incididunt ut labore et"
|
||
|
" dolore magna aliqua. ");
|
||
|
ImGui::EndTabItem();
|
||
|
if (ImGui::MenuItem("Close", "Ctrl+W"))
|
||
|
{
|
||
|
std::cerr << ERROR_MSG << "Closing it out"
|
||
|
<< std::endl;
|
||
|
done = true;
|
||
|
}
|
||
|
ImGui::EndMenu();
|
||
|
}
|
||
|
|
||
|
if (ImGui::BeginTabItem("About"))
|
||
|
// Experimental.. maybe make this the "About" window?
|
||
|
if (ImGui::BeginMenu("Misc"))
|
||
|
{
|
||
|
ImGui::Text("%s version: %s", APP_NAME.c_str(),
|
||
|
VERSION.c_str());
|
||
|
ImGui::Text("Compiled on: %s ", __TIMESTAMP__);
|
||
|
ImGui::Text("Created by: dsorber");
|
||
|
ImGui::EndTabItem();
|
||
|
if (ImGui::MenuItem("About", "Ctrl+M"))
|
||
|
{ ;
|
||
|
}
|
||
|
ImGui::EndMenu();
|
||
|
}
|
||
|
ImGui::EndTabBar();
|
||
|
ImGui::EndMenuBar();
|
||
|
}
|
||
|
ImGui::EndChild();
|
||
|
|
||
|
if (ImGui::Button("Revert")) {}
|
||
|
//---[Left side]----------------------------------------------------
|
||
|
static int selected = 0;
|
||
|
{
|
||
|
ImGui::BeginChild("left_pane", ImVec2(150, 0),
|
||
|
ImGuiChildFlags_Border |
|
||
|
ImGuiChildFlags_ResizeX);
|
||
|
|
||
|
for (auto &iter: catalog)
|
||
|
{
|
||
|
// ImGuiInputTextFlags_ReadOnly
|
||
|
if (iter.visible() &&
|
||
|
ImGui::CollapsingHeader(iter.getKey().c_str()))
|
||
|
{
|
||
|
ImGui::InputTextMultiline(
|
||
|
iter.getLcKey().c_str(),
|
||
|
iter.getValueBuffer(),
|
||
|
iter.getValueBufferSize(),
|
||
|
ImVec2(-FLT_MIN,
|
||
|
ImGui::GetTextLineHeight() * 4),
|
||
|
MULTILINE_TEXT_FLAGS);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ImGui::EndChild();
|
||
|
}
|
||
|
ImGui::SameLine();
|
||
|
|
||
|
if (ImGui::Button("Save")) {}
|
||
|
ImGui::EndGroup();
|
||
|
//---[Right side]---------------------------------------------------
|
||
|
{
|
||
|
ImGui::BeginGroup();
|
||
|
ImGui::BeginChild("item view",
|
||
|
ImVec2(0,
|
||
|
-ImGui::GetFrameHeightWithSpacing()));
|
||
|
|
||
|
ImGui::InputText("Filter", filterBuffer,
|
||
|
IM_ARRAYSIZE(filterBuffer),
|
||
|
ImGuiInputTextFlags_CallbackEdit,
|
||
|
catalogFilterCallback);
|
||
|
|
||
|
ImGui::Separator();
|
||
|
if (ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None))
|
||
|
{
|
||
|
if (ImGui::BeginTabItem("Options"))
|
||
|
{
|
||
|
ImGui::TextWrapped(
|
||
|
"Lorem ipsum dolor sit amet, consectetur adipiscing "
|
||
|
"elit, sed do eiusmod tempor incididunt ut labore et"
|
||
|
" dolore magna aliqua. ");
|
||
|
ImGui::EndTabItem();
|
||
|
}
|
||
|
|
||
|
if (ImGui::BeginTabItem("About"))
|
||
|
{
|
||
|
ImGui::Text("%s version: %s", APP_NAME.c_str(),
|
||
|
VERSION.c_str());
|
||
|
ImGui::Text("Compiled on: %s ", __TIMESTAMP__);
|
||
|
ImGui::Text("Created by: dsorber");
|
||
|
ImGui::EndTabItem();
|
||
|
}
|
||
|
ImGui::EndTabBar();
|
||
|
}
|
||
|
ImGui::EndChild();
|
||
|
|
||
|
if (ImGui::Button("Clear Filter"))
|
||
|
{
|
||
|
filterBuffer[0] = 0;
|
||
|
}
|
||
|
ImGui::SameLine();
|
||
|
|
||
|
if (ImGui::Button("Save"))
|
||
|
{}
|
||
|
ImGui::EndGroup();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
Significant improvements including reading input from encrypted file.
Also added crypto utility to en/decrypt a file.