Skip to content

Commit

Permalink
Added hiding feature for --hide
Browse files Browse the repository at this point in the history
  • Loading branch information
Stjepan Bakrac authored and Stjepan Bakrac committed Oct 24, 2017
1 parent 84b9a42 commit d1afc6e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
56 changes: 56 additions & 0 deletions xiloader/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ This file is part of DarkStar-server source code.

#include "console.h"

#include <ShObjIdl.h>

/* Global Externs */
extern CRITICAL_SECTION g_CriticalSection;
extern bool g_Hide;

namespace xiloader
{
Expand Down Expand Up @@ -134,4 +137,57 @@ namespace xiloader
LeaveCriticalSection(&g_CriticalSection);
}

/**
* @brief Shows or hides the console based on the provided argument.
*
* @param visible "true" to show the console, "false" to hide it.
*/
void console::visible(bool visible)
{
if (!g_Hide)
return;

HWND console = GetConsoleWindow();

// Adjust the task bar
ITaskbarList* taskbar = nullptr;
HRESULT hr = CoCreateInstance(
CLSID_TaskbarList,
nullptr,
CLSCTX_INPROC_SERVER,
IID_ITaskbarList,
reinterpret_cast<void**>(&taskbar));
if (SUCCEEDED(hr))
{
if (visible)
{
taskbar->AddTab(console);
}
else
{
taskbar->DeleteTab(console);
}
taskbar->Release();
}

// Adjust the window's visibility
ShowWindow(console, visible ? SW_SHOW : SW_HIDE);
}

/**
* @brief Hides the console window.
*/
void console::hide()
{
visible(false);
}

/**
* @brief Shows the console window.
*/
void console::show()
{
visible(true);
}

}; // namespace xiloader
19 changes: 19 additions & 0 deletions xiloader/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ namespace xiloader
*/
class console
{
private:

/**
* @brief Shows or hides the console based on the provided argument.
*
* @param visible "true" to show the console, "false" to hide it.
*/
static void visible(bool visible);

public:

/**
Expand All @@ -119,6 +128,16 @@ namespace xiloader
* @param ... The arguments to fill the format.
*/
static void output(const xiloader::color::colors& c, const char* format, ...);

/**
* @brief Hides the console window.
*/
static void hide();

/**
* @brief Shows the console window.
*/
static void show();
};

}; // namespace xiloader
Expand Down
10 changes: 10 additions & 0 deletions xiloader/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ std::string g_Username = ""; // The username being logged in with.
std::string g_Password = ""; // The password being logged in with.
char* g_CharacterList = NULL; // Pointer to the character list data being sent from the server.
bool g_IsRunning = false; // Flag to determine if the network threads should hault.
bool g_Hide = false; // Determines whether or not to hide the console window after FFXI starts.
CRITICAL_SECTION g_CriticalSection; // Critical section object to prevent console logging issues from threads.

/* Hairpin Fix Variables */
Expand Down Expand Up @@ -294,6 +295,13 @@ int __cdecl main(int argc, char* argv[])
continue;
}

/* Hide Argument */
if (!_strnicmp(argv[x], "--hide", 6))
{
g_Hide = true;
continue;
}

xiloader::console::output(xiloader::color::warning, "Found unknown command argument: %s", argv[x]);
}

Expand Down Expand Up @@ -368,7 +376,9 @@ int __cdecl main(int argc, char* argv[])
{
/* Attempt to start Final Fantasy.. */
IUnknown* message = NULL;
xiloader::console::hide();
ffxi->GameStart(polcore, &message);
xiloader::console::show();
ffxi->Release();
}

Expand Down

0 comments on commit d1afc6e

Please sign in to comment.