mirror of https://github.com/AxioDL/nod.git
Todo1 finally done right
Re-enabled exceptions to implement the best-of-all-worlds solution for the progFunc lambda.
This commit is contained in:
parent
5ecd8595c9
commit
839dbe364c
|
@ -12,9 +12,6 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|||
/wd4267 /wd4244 /wd4200 /wd4305 /wd4067 /wd4146 /wd4309 /wd4805 ${VS_OPTIONS})
|
||||
|
||||
add_compile_options(
|
||||
# Disable exceptions
|
||||
$<$<COMPILE_LANGUAGE:CXX>:/EHsc->
|
||||
|
||||
# Disable RTTI
|
||||
$<$<COMPILE_LANGUAGE:CXX>:/GR->
|
||||
|
||||
|
@ -30,7 +27,6 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|||
# Use latest C++ standard.
|
||||
$<$<COMPILE_LANGUAGE:CXX>:/std:c++latest>
|
||||
)
|
||||
add_compile_definitions(FMT_EXCEPTIONS=0 _HAS_EXCEPTIONS=0)
|
||||
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
# Flags for MSVC (not clang-cl)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <locale>
|
||||
|
||||
#include <logvisor/logvisor.hpp>
|
||||
|
||||
|
@ -66,12 +67,23 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
auto progFunc = [&](float prog, nod::SystemStringView name, size_t bytes) {
|
||||
nod::SystemShiftJISConv shiftjis_name(name);
|
||||
fmt::print(FMT_STRING("\r "));
|
||||
if (bytes != SIZE_MAX)
|
||||
fmt::print(FMT_STRING("\r{:g}% {} {} B"), prog * 100.f, shiftjis_name.shiftjis_str(), bytes);
|
||||
else
|
||||
fmt::print(FMT_STRING("\r{:g}% {}"), prog * 100.f, shiftjis_name.shiftjis_str());
|
||||
fmt::print(FMT_STRING(_SYS_STR("\r ")));
|
||||
FMT_TRY {
|
||||
if (bytes != SIZE_MAX)
|
||||
fmt::print(FMT_STRING(_SYS_STR("\r{:g}% {} {} B")), prog * 100.f, name, bytes);
|
||||
else
|
||||
fmt::print(FMT_STRING(_SYS_STR("\r{:g}% {}")), prog * 100.f, name);
|
||||
}
|
||||
// Windows Command Prompt does not support Unicode.
|
||||
FMT_CATCH(const fmt::system_error& e) {
|
||||
std::string narrow_name(name.size(), '\0');
|
||||
std::locale loc;
|
||||
std::use_facet<std::ctype<nod::SystemChar>>(loc).narrow(name.data(), name.data()+name.size()+1, '?', narrow_name.data());
|
||||
if (bytes != SIZE_MAX)
|
||||
fmt::print(FMT_STRING("\r{:g}% {} {} B"), prog * 100.f, narrow_name, bytes);
|
||||
else
|
||||
fmt::print(FMT_STRING("\r{:g}% {}"), prog * 100.f, narrow_name);
|
||||
}
|
||||
fflush(stdout);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue