Functions: added vargs to LMsg
This commit is contained in:
parent
9ae1896b22
commit
5e9f27ae4a
@ -14,6 +14,7 @@
|
||||
|
||||
#include <codecvt>
|
||||
#include <shlobj.h>
|
||||
#include "resources_windows.h"
|
||||
|
||||
#define cout std::wcout
|
||||
#define cerr std::wcerr
|
||||
@ -51,14 +52,31 @@ std::wstring utf8_to_wstring( const std::string &utf8 ) {
|
||||
return wconv.from_bytes( utf8 );
|
||||
}
|
||||
|
||||
wchar_t *LMsg( int ID ) {
|
||||
// TODO better max value perhaps?
|
||||
std::wstring LMsg( int id, ... ) {
|
||||
static wchar_t local[MAX_PATH];
|
||||
auto hInstance = GetModuleHandle( NULL );
|
||||
LoadString( hInstance, ID, local, MAX_PATH );
|
||||
// TODO add vargs
|
||||
LoadString( hInstance, id, local, MAX_PATH );
|
||||
|
||||
va_list args;
|
||||
va_start( args, id );
|
||||
int count = 0;
|
||||
const wchar_t *p;
|
||||
while ( ( p = va_arg( args, const wchar_t * ) ) != NULL )
|
||||
count++;
|
||||
va_end( args );
|
||||
|
||||
if ( count == 0 )
|
||||
return local;
|
||||
|
||||
va_start( args, id );
|
||||
int len = vswprintf( nullptr, 0, local, args );
|
||||
va_end( args );
|
||||
wchar_t *text = new wchar_t[len + 1];
|
||||
va_start( args, id );
|
||||
vswprintf( text, len + 1, local, args );
|
||||
std::wstring ret = text;
|
||||
delete[] text;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else
|
||||
@ -256,7 +274,8 @@ string userHome() {
|
||||
return dir_s;
|
||||
}
|
||||
CoTaskMemFree( dir );
|
||||
throw std::runtime_error( _( APPDATA_NOT_FOUND ) );
|
||||
// runtime_error doesn't support wstring
|
||||
throw std::runtime_error( "Couldn't find user's appdata" );
|
||||
}
|
||||
|
||||
#else // UNIX
|
||||
@ -592,7 +611,7 @@ void refreshDB( bool linux, void *progress_ptr ) {
|
||||
#ifndef GUI
|
||||
cleanUpLine();
|
||||
#endif
|
||||
p.print( _( REFRESHING ) + string( " " ) + show[TEXT( "SHOW" )] );
|
||||
p.print( _( REFRESHING ) + string( 1, ' ' ) + show[TEXT( "SHOW" )] );
|
||||
p.print( 0 );
|
||||
std::map< int, std::map< int, string > > seasons;
|
||||
|
||||
@ -875,7 +894,7 @@ void refreshSelectDB( std::unordered_set< size_t > indexes, bool linux,
|
||||
ProgressBar p( progress_ptr );
|
||||
|
||||
for ( auto &show : shows ) {
|
||||
p.print( _( REFRESHING ) + string( ' ', 1 ) + show[TEXT( "SHOW" )] );
|
||||
p.print( _( REFRESHING ) + string( 1, ' ' ) + show[TEXT( "SHOW" )] );
|
||||
if ( FSLib::exists( show[TEXT( "PATH" )] ) ) {
|
||||
p.print( 0 );
|
||||
std::map< int, std::map< int, string > > seasons;
|
||||
|
@ -16,9 +16,9 @@ using string = std::wstring;
|
||||
using char_t = wchar_t;
|
||||
|
||||
std::wstring utf8_to_wstring( const std::string &utf8 );
|
||||
wchar_t *LMsg( int ID );
|
||||
std::wstring LMsg( int id, ... );
|
||||
|
||||
#define _( x, ... ) LMsg( ID, ##__VA_ARGS__ )
|
||||
#define _( x, ... ) LMsg( x, ##__VA_ARGS__ ).c_str()
|
||||
|
||||
#else
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user