terrasync: some code cleanup - don't use snprintf
This commit is contained in:
parent
59a6fd1ed8
commit
da707f3e40
@ -289,10 +289,8 @@ bool SGTerraSync::SvnThread::start()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool use_int_svn = false;
|
|
||||||
#ifdef HAVE_SVN_CLIENT_H
|
#ifdef HAVE_SVN_CLIENT_H
|
||||||
_use_svn |= _use_built_in;
|
_use_svn |= _use_built_in;
|
||||||
use_int_svn = _use_built_in;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((_use_svn)&&(_svn_server==""))
|
if ((_use_svn)&&(_svn_server==""))
|
||||||
@ -312,37 +310,6 @@ bool SGTerraSync::SvnThread::start()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
// whitespace support should work now
|
|
||||||
//#ifdef SG_WINDOWS
|
|
||||||
if ((_use_svn)&&(!use_int_svn))
|
|
||||||
{
|
|
||||||
// external SVN support is used
|
|
||||||
if (hasWhitespace(_local_dir))
|
|
||||||
{
|
|
||||||
SG_LOG(SG_TERRAIN,SG_ALERT,
|
|
||||||
"Cannot start scenery download. Directory '" << _local_dir <<
|
|
||||||
"' contains white-space characters." << endl <<
|
|
||||||
"This path is unsupported when using external subversion on Windows." << endl <<
|
|
||||||
"Please select a different target directory without white-space characters.");
|
|
||||||
_fail_count++;
|
|
||||||
_stalled = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (hasWhitespace(_svn_command))
|
|
||||||
{
|
|
||||||
SG_LOG(SG_TERRAIN,SG_ALERT,
|
|
||||||
"Cannot start scenery download. Path to utility '" << _svn_command <<
|
|
||||||
"' contains white-space characters." << endl <<
|
|
||||||
"This path is unsupported when using external subversion on Windows." << endl <<
|
|
||||||
"Please move utility to a different directory or add the directory to your system 'PATH'.");
|
|
||||||
_fail_count++;
|
|
||||||
_stalled = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_fail_count = 0;
|
_fail_count = 0;
|
||||||
_updated_tile_count = 0;
|
_updated_tile_count = 0;
|
||||||
_success_count = 0;
|
_success_count = 0;
|
||||||
@ -420,20 +387,19 @@ bool SGTerraSync::SvnThread::syncTreeInternal(const char* dir)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char command[512];
|
ostringstream command;
|
||||||
char dest_base_dir[512];
|
command << _svn_server << "/" << dir;
|
||||||
snprintf( command, 512,
|
|
||||||
"%s/%s", _svn_server.c_str(), dir);
|
ostringstream dest_base_dir;
|
||||||
snprintf( dest_base_dir, 512,
|
dest_base_dir << _local_dir << "/" << dir;
|
||||||
"%s/%s", _local_dir.c_str(), dir);
|
|
||||||
|
|
||||||
apr_pool_t *subpool = svn_pool_create(_svn_pool);
|
apr_pool_t *subpool = svn_pool_create(_svn_pool);
|
||||||
|
|
||||||
svn_error_t *err = NULL;
|
svn_error_t *err = NULL;
|
||||||
#if (SVN_VER_MINOR >= 5)
|
#if (SVN_VER_MINOR >= 5)
|
||||||
err = svn_client_checkout3(NULL,
|
err = svn_client_checkout3(NULL,
|
||||||
command,
|
command.str().c_str(),
|
||||||
dest_base_dir,
|
dest_base_dir.str().c_str(),
|
||||||
_svn_rev_peg,
|
_svn_rev_peg,
|
||||||
_svn_rev,
|
_svn_rev,
|
||||||
svn_depth_infinity,
|
svn_depth_infinity,
|
||||||
@ -444,8 +410,8 @@ bool SGTerraSync::SvnThread::syncTreeInternal(const char* dir)
|
|||||||
#else
|
#else
|
||||||
// version 1.4 API
|
// version 1.4 API
|
||||||
err = svn_client_checkout2(NULL,
|
err = svn_client_checkout2(NULL,
|
||||||
command,
|
command.str().c_str(),
|
||||||
dest_base_dir,
|
dest_base_dir.str().c_str(),
|
||||||
_svn_rev_peg,
|
_svn_rev_peg,
|
||||||
_svn_rev,
|
_svn_rev,
|
||||||
1, // recurse=true - same as svn_depth_infinity for checkout3 above
|
1, // recurse=true - same as svn_depth_infinity for checkout3 above
|
||||||
@ -469,7 +435,7 @@ bool SGTerraSync::SvnThread::syncTreeInternal(const char* dir)
|
|||||||
err->message << " (code " << err->apr_err << ").");
|
err->message << " (code " << err->apr_err << ").");
|
||||||
svn_error_clear(err);
|
svn_error_clear(err);
|
||||||
// try to clean up
|
// try to clean up
|
||||||
err = svn_client_cleanup(dest_base_dir,
|
err = svn_client_cleanup(dest_base_dir.str().c_str(),
|
||||||
_svn_ctx,subpool);
|
_svn_ctx,subpool);
|
||||||
if (!err)
|
if (!err)
|
||||||
{
|
{
|
||||||
@ -489,14 +455,24 @@ bool SGTerraSync::SvnThread::syncTreeInternal(const char* dir)
|
|||||||
|
|
||||||
bool SGTerraSync::SvnThread::syncTreeExternal(const char* dir)
|
bool SGTerraSync::SvnThread::syncTreeExternal(const char* dir)
|
||||||
{
|
{
|
||||||
int rc;
|
ostringstream buf;
|
||||||
char command[512];
|
SGPath localPath( _local_dir );
|
||||||
|
localPath.append( dir );
|
||||||
|
|
||||||
if (_use_svn)
|
if (_use_svn)
|
||||||
{
|
{
|
||||||
#ifdef SG_WINDOWS
|
buf << "\"" << _svn_command << "\" "
|
||||||
SGPath localPath( _local_dir );
|
<< svn_options << " "
|
||||||
localPath.append( dir );
|
<< "\"" << _svn_server << "/" << dir << "\" "
|
||||||
|
<< "\"" << localPath.str_native() << "\"";
|
||||||
|
} else {
|
||||||
|
buf << rsync_cmd << " "
|
||||||
|
<< "\"" << _rsync_server << "/" << dir << "/\" "
|
||||||
|
<< "\"" << localPath.str_native() << "/\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
string command;
|
||||||
|
#ifdef SG_WINDOWS
|
||||||
// windows command line parsing is just lovely...
|
// windows command line parsing is just lovely...
|
||||||
// to allow white spaces, the system call needs this:
|
// to allow white spaces, the system call needs this:
|
||||||
// ""C:\Program Files\something.exe" somearg "some other arg""
|
// ""C:\Program Files\something.exe" somearg "some other arg""
|
||||||
@ -504,25 +480,12 @@ bool SGTerraSync::SvnThread::syncTreeExternal(const char* dir)
|
|||||||
// entire string needs to be wrapped by "" too.
|
// entire string needs to be wrapped by "" too.
|
||||||
// The svn url needs forward slashes (/) as a path separator while
|
// The svn url needs forward slashes (/) as a path separator while
|
||||||
// the local path needs windows-native backslash as a path separator.
|
// the local path needs windows-native backslash as a path separator.
|
||||||
snprintf( command, 512,
|
command = "\"" + buf.str() + "\"";
|
||||||
"\"\"%s\" %s %s/%s \"%s\"\"", _svn_command.c_str(), svn_options,
|
|
||||||
_svn_server.c_str(), dir,
|
|
||||||
localPath.str_native().c_str() );
|
|
||||||
#else
|
#else
|
||||||
// support white-space paths (use '"')
|
command = buf.str();
|
||||||
snprintf( command, 512,
|
|
||||||
"\"%s\" %s %s/%s \"%s/%s\"", _svn_command.c_str(), svn_options,
|
|
||||||
_svn_server.c_str(), dir,
|
|
||||||
_local_dir.c_str(), dir );
|
|
||||||
#endif
|
#endif
|
||||||
} else {
|
|
||||||
snprintf( command, 512,
|
|
||||||
"%s %s/%s/ \"%s/%s/\"", rsync_cmd,
|
|
||||||
_rsync_server.c_str(), dir,
|
|
||||||
_local_dir.c_str(), dir );
|
|
||||||
}
|
|
||||||
SG_LOG(SG_TERRAIN,SG_DEBUG, "sync command '" << command << "'");
|
SG_LOG(SG_TERRAIN,SG_DEBUG, "sync command '" << command << "'");
|
||||||
rc = system( command );
|
int rc = system( command.c_str() );
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
SG_LOG(SG_TERRAIN,SG_ALERT,
|
SG_LOG(SG_TERRAIN,SG_ALERT,
|
||||||
@ -836,20 +799,16 @@ void SGTerraSync::setTileCache(TileCache* tile_cache)
|
|||||||
|
|
||||||
void SGTerraSync::syncAirportsModels()
|
void SGTerraSync::syncAirportsModels()
|
||||||
{
|
{
|
||||||
char synced_other;
|
static const char bounds[] = "KZAJ";
|
||||||
for ( synced_other = 'K'; synced_other <= 'Z'; synced_other++ )
|
for( unsigned i = 0; i < sizeof(bounds)/sizeof(bounds[0])/2; i+= 2 )
|
||||||
{
|
{
|
||||||
char dir[512];
|
for ( char synced_other = bounds[i]; synced_other <= bounds[i+1]; synced_other++ )
|
||||||
snprintf( dir, 512, "Airports/%c", synced_other );
|
{
|
||||||
WaitingTile w(dir,false);
|
ostringstream dir;
|
||||||
_svnThread->request( w );
|
dir << "Airports/" << synced_other;
|
||||||
}
|
WaitingTile w(dir.str(),false);
|
||||||
for ( synced_other = 'A'; synced_other <= 'J'; synced_other++ )
|
_svnThread->request( w );
|
||||||
{
|
}
|
||||||
char dir[512];
|
|
||||||
snprintf( dir, 512, "Airports/%c", synced_other );
|
|
||||||
WaitingTile w(dir,false);
|
|
||||||
_svnThread->request( w );
|
|
||||||
}
|
}
|
||||||
WaitingTile w("Models",false);
|
WaitingTile w("Models",false);
|
||||||
_svnThread->request( w );
|
_svnThread->request( w );
|
||||||
@ -892,12 +851,11 @@ void SGTerraSync::syncArea( int lat, int lon )
|
|||||||
bool refresh=true;
|
bool refresh=true;
|
||||||
for (const char** tree = &terrainobjects[0]; *tree; tree++)
|
for (const char** tree = &terrainobjects[0]; *tree; tree++)
|
||||||
{
|
{
|
||||||
char dir[512];
|
ostringstream dir;
|
||||||
snprintf( dir, 512, "%s/%c%03d%c%02d/%c%03d%c%02d",
|
dir << *tree << "/" << setfill('0')
|
||||||
*tree,
|
<< EW << setw(3) << abs(baselon) << NS << setw(2) << abs(baselat) << "/"
|
||||||
EW, abs(baselon), NS, abs(baselat),
|
<< EW << setw(3) << abs(lon) << NS << setw(2) << abs(lat);
|
||||||
EW, abs(lon), NS, abs(lat) );
|
WaitingTile w(dir.str(),refresh);
|
||||||
WaitingTile w(dir,refresh);
|
|
||||||
_svnThread->request( w );
|
_svnThread->request( w );
|
||||||
refresh=false;
|
refresh=false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user