2016-11-17 18:32:08 +11:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2016-11-17 18:32:08 +11:00
|
|
|
*
|
|
|
|
* Copyright 2010-2016 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
2017-11-22 16:49:37 +11:00
|
|
|
#include "exe.hpp"
|
2016-10-10 16:23:07 +11:00
|
|
|
|
2018-08-13 14:51:33 +10:00
|
|
|
#include "win32/except.hpp"
|
2016-10-10 16:23:07 +11:00
|
|
|
|
2016-11-17 18:32:08 +11:00
|
|
|
#include <experimental/filesystem>
|
|
|
|
#include <vector>
|
2016-10-10 16:23:07 +11:00
|
|
|
#include <windows.h>
|
|
|
|
|
2016-11-17 18:32:08 +11:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2016-10-10 16:23:07 +11:00
|
|
|
std::experimental::filesystem::path
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::image_path (void)
|
2016-11-17 18:32:08 +11:00
|
|
|
{
|
2016-10-10 16:23:07 +11:00
|
|
|
std::vector<char> resolved (256);
|
|
|
|
|
|
|
|
retry:
|
2018-08-13 14:51:33 +10:00
|
|
|
const auto written = GetModuleFileName (nullptr, resolved.data (), static_cast<DWORD> (resolved.size ()));
|
2016-10-10 16:23:07 +11:00
|
|
|
if (written == 0)
|
2017-12-18 15:46:52 +11:00
|
|
|
win32::error::throw_code ();
|
2016-10-10 16:23:07 +11:00
|
|
|
|
|
|
|
if (written == resolved.size ()) {
|
|
|
|
resolved.resize (resolved.size () * 2);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::experimental::filesystem::path (resolved.data (), resolved.data () + written);
|
|
|
|
}
|