Load time-zones from UTF-8 paths correctly
Use _wfopen on Windows, after converting UTF-8 paths to wchar
This commit is contained in:
@@ -42,6 +42,7 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include <simgear/structure/exception.hxx>
|
#include <simgear/structure/exception.hxx>
|
||||||
|
#include <simgear/misc/strutils.hxx>
|
||||||
|
|
||||||
#include "lowleveltime.h"
|
#include "lowleveltime.h"
|
||||||
|
|
||||||
@@ -857,7 +858,12 @@ void fgtzfile_read (const char *file)
|
|||||||
// file = _new;
|
// file = _new;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
f = fopen (file, "rb");
|
#if defined(SG_WINDOWS)
|
||||||
|
const std::wstring wfile = simgear::strutils::convertUtf8ToWString(file);
|
||||||
|
f = _wfopen(wfile.c_str(), L"rb");
|
||||||
|
#else
|
||||||
|
f = fopen(file, "rb");
|
||||||
|
#endif
|
||||||
|
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
perror( "fgtzfile_read(): " );
|
perror( "fgtzfile_read(): " );
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ void SGTime::init( const SGGeod& location, const SGPath& root, time_t init_time
|
|||||||
SGPath zone( root );
|
SGPath zone( root );
|
||||||
zone.append( "zone.tab" );
|
zone.append( "zone.tab" );
|
||||||
SG_LOG( SG_EVENT, SG_INFO, "Reading timezone info from: " << zone );
|
SG_LOG( SG_EVENT, SG_INFO, "Reading timezone info from: " << zone );
|
||||||
std::string zs = zone.local8BitStr();
|
std::string zs = zone.utf8Str();
|
||||||
static_tzContainer.reset(new SGTimeZoneContainer( zs.c_str() ));
|
static_tzContainer.reset(new SGTimeZoneContainer( zs.c_str() ));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +243,7 @@ void SGTime::updateLocal( const SGGeod& aLocation, const SGPath& root ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currGMT = sgTimeGetGMT( gmtime(&cur_time) );
|
currGMT = sgTimeGetGMT( gmtime(&cur_time) );
|
||||||
std::string zs = zone.local8BitStr();
|
std::string zs = zone.utf8Str();
|
||||||
aircraftLocalTime = sgTimeGetGMT( (fgLocaltime(&cur_time, zs.c_str())) );
|
aircraftLocalTime = sgTimeGetGMT( (fgLocaltime(&cur_time, zs.c_str())) );
|
||||||
local_offset = aircraftLocalTime - currGMT;
|
local_offset = aircraftLocalTime - currGMT;
|
||||||
// cout << "Using " << local_offset << " as local time offset Timezone is "
|
// cout << "Using " << local_offset << " as local time offset Timezone is "
|
||||||
|
|||||||
Regular → Executable
+7
-1
@@ -36,6 +36,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <simgear/structure/exception.hxx>
|
#include <simgear/structure/exception.hxx>
|
||||||
|
#include <simgear/misc/strutils.hxx>
|
||||||
|
|
||||||
#include "timezone.h"
|
#include "timezone.h"
|
||||||
|
|
||||||
@@ -134,7 +135,12 @@ SGTimeZone::SGTimeZone(const SGTimeZone& other)
|
|||||||
SGTimeZoneContainer::SGTimeZoneContainer(const char *filename)
|
SGTimeZoneContainer::SGTimeZoneContainer(const char *filename)
|
||||||
{
|
{
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
FILE* infile = fopen(filename, "rb");
|
#if defined(SG_WINDOWS)
|
||||||
|
const std::wstring wfile = simgear::strutils::convertUtf8ToWString(filename);
|
||||||
|
FILE* infile = _wfopen(wfile.c_str(), L"rb");
|
||||||
|
#else
|
||||||
|
FILE* infile = fopen(filename, "rb");
|
||||||
|
#endif
|
||||||
if (!(infile)) {
|
if (!(infile)) {
|
||||||
std::string e = "Unable to open time zone file '";
|
std::string e = "Unable to open time zone file '";
|
||||||
throw sg_exception(e + filename + '\'');
|
throw sg_exception(e + filename + '\'');
|
||||||
|
|||||||
Reference in New Issue
Block a user