From c6e4bb0669f2e339a85239b06a24040c07a5b013 Mon Sep 17 00:00:00 2001 From: fredb Date: Sun, 12 Oct 2008 07:55:09 +0000 Subject: [PATCH] Alex Perry : * Doesn't download the area at lot,lon of 0,0 if terrasync starts before FlightGear is ready * Attempt to download the Airports directory when no scenery needs to be fetched * Add svn over http support for flag "-S", in addition to the existing default of rsync * Add the command line flag "-T" to just refresh the KSFO surrounding area and exit Frederic Bouvier: Add a MSVC71 project file --- projects/VC7.1/.cvsignore | 2 + projects/VC7.1/FlightGear.sln | 9 ++ projects/VC7.1/terrasync.vcproj | 140 +++++++++++++++++++++++++++ utils/TerraSync/terrasync.cxx | 164 +++++++++++++++++++++----------- 4 files changed, 261 insertions(+), 54 deletions(-) create mode 100755 projects/VC7.1/terrasync.vcproj diff --git a/projects/VC7.1/.cvsignore b/projects/VC7.1/.cvsignore index a231eb25e..e63dcabea 100755 --- a/projects/VC7.1/.cvsignore +++ b/projects/VC7.1/.cvsignore @@ -18,3 +18,5 @@ FlightGear.ncb FlightGear.suo metar_Debug metar_Release +Terrasync_Release +Terrasync_Debug diff --git a/projects/VC7.1/FlightGear.sln b/projects/VC7.1/FlightGear.sln index b054a46ba..e4bc31be5 100755 --- a/projects/VC7.1/FlightGear.sln +++ b/projects/VC7.1/FlightGear.sln @@ -49,6 +49,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "metar", "metar.vcproj", "{F {22540CD3-D3CA-4C86-A773-80AEEE3ACDED} = {22540CD3-D3CA-4C86-A773-80AEEE3ACDED} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "terrasync", "terrasync.vcproj", "{874D3F55-6048-4068-A7C2-7FA6AF1F30EA}" + ProjectSection(ProjectDependencies) = postProject + {22540CD3-D3CA-4C86-A773-80AEEE3ACDED} = {22540CD3-D3CA-4C86-A773-80AEEE3ACDED} + EndProjectSection +EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug @@ -91,6 +96,10 @@ Global {FC424099-5D77-4BC2-A93F-2EE59F816B51}.Debug.Build.0 = Debug|Win32 {FC424099-5D77-4BC2-A93F-2EE59F816B51}.Release.ActiveCfg = Release|Win32 {FC424099-5D77-4BC2-A93F-2EE59F816B51}.Release.Build.0 = Release|Win32 + {874D3F55-6048-4068-A7C2-7FA6AF1F30EA}.Debug.ActiveCfg = Debug|Win32 + {874D3F55-6048-4068-A7C2-7FA6AF1F30EA}.Debug.Build.0 = Debug|Win32 + {874D3F55-6048-4068-A7C2-7FA6AF1F30EA}.Release.ActiveCfg = Release|Win32 + {874D3F55-6048-4068-A7C2-7FA6AF1F30EA}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection diff --git a/projects/VC7.1/terrasync.vcproj b/projects/VC7.1/terrasync.vcproj new file mode 100755 index 000000000..4e02f0828 --- /dev/null +++ b/projects/VC7.1/terrasync.vcproj @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/utils/TerraSync/terrasync.cxx b/utils/TerraSync/terrasync.cxx index 7ec9fef8f..1786be923 100644 --- a/utils/TerraSync/terrasync.cxx +++ b/utils/TerraSync/terrasync.cxx @@ -3,6 +3,7 @@ // Written by Curtis Olson, started November 2002. // // Copyright (C) 2002 Curtis L. Olson - http://www.flightgear.org/~curt +// Copyright (C) 2008 Alexander R. Perry // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -40,24 +41,36 @@ #include #include +#include using std::string; using std::cout; using std::endl; -static string server = "scenery.flightgear.org"; -static string source_module = "Scenery"; -static string source_base = server + (string)"::" + source_module; -static string dest_base = "/dest/scenery/dir"; +const char* svn_base = + "http://terrascenery.googlecode.com/svn/trunk/data/Scenery"; +const char* rsync_base = "scenery.flightgear.org::Scenery"; +const char* source_base = NULL; +const char* dest_base = "terrasyncdir"; +bool use_svn = false; + +const char* svn_cmd = "svn checkout"; +const char* rsync_cmd = + "rsync --verbose --archive --delete --perms --owner --group"; // display usage static void usage( const string& prog ) { - cout << "Usage: " << prog - << " -p [ -s ] -d " << endl; + cout << "Usage: " << endl + << prog << " -p " + << "[ -R ] [ -s ] -d " << endl + << prog << " -p " + << " -S [ -s ] -d " << endl; } +const int nowhere = -9999; + // parse message static void parse_message( const string &msg, int *lat, int *lon ) { double dlat, dlon; @@ -105,6 +118,44 @@ static void parse_message( const string &msg, int *lat, int *lon ) { } else { *lon = (int)dlon; } + + if ((dlon == 0) && (dlat == 0)) { + *lon = nowhere; + *lat = nowhere; + } + +} + +// sync one directory tree +void sync_tree(char* dir) { + int rc; + char command[512]; + SGPath path( dest_base ); + + path.append( dir ); + rc = path.create_dir( 0755 ); + if (rc) { + cout << "Return code = " << rc << endl; + exit(1); + } + + if (use_svn) { + snprintf( command, 512, + "%s %s/%s %s/%s", svn_cmd, + source_base, dir, + dest_base, dir ); + } else { + snprintf( command, 512, + "%s %s/%s/ %s/%s/", rsync_cmd, + source_base, dir, + dest_base, dir ); + } + cout << command << endl; + rc = system( command ); + if (rc) { + cout << "Return code = " << rc << endl; + if (rc == 5120) exit(1); + } } @@ -134,47 +185,21 @@ static void sync_area( int lat, int lon ) { } EW = 'w'; } else { - baselon = (int)(lon / 10) * 10; - EW = 'e'; - } - - char command[512]; - char container_dir[512]; + baselon = (int)(lon / 10) * 10; + EW = 'e'; + } + + const char* terrainobjects[3] = { "Terrain", "Objects", 0 }; + const char** tree; char dir[512]; - - // Sync Terrain - snprintf( container_dir, 512, "%s/Terrain/%c%03d%c%02d", - dest_base.c_str(), EW, abs(baselon), NS, abs(baselat) ); - snprintf( command, 512, "mkdir -p %s", container_dir ); - cout << command << endl; - system( command ); - - snprintf( dir, 512, "Terrain/%c%03d%c%02d/%c%03d%c%02d", - EW, abs(baselon), NS, abs(baselat), - EW, abs(lon), NS, abs(lat) ); - - snprintf( command, 512, - "rsync --verbose --archive --delete --perms --owner --group %s/%s/ %s/%s", - source_base.c_str(), dir, dest_base.c_str(), dir ); - cout << command << endl; - system( command ); - - // Sync Objects - snprintf( container_dir, 512, "%s/Objects/%c%03d%c%02d", - dest_base.c_str(), EW, abs(baselon), NS, abs(baselat) ); - snprintf( command, 512, "mkdir -p %s", container_dir ); - cout << command << endl; - system( command ); - - snprintf( dir, 512, "Objects/%c%03d%c%02d/%c%03d%c%02d", - EW, abs(baselon), NS, abs(baselat), - EW, abs(lon), NS, abs(lat) ); - - snprintf( command, 512, - "rsync --verbose --archive --delete --perms --owner --group %s/%s/ %s/%s", - source_base.c_str(), dir, dest_base.c_str(), dir ); - cout << command << endl; - system( command ); + + for (tree = &terrainobjects[0]; *tree; tree++) { + snprintf( dir, 512, "%s/%c%03d%c%02d/%c%03d%c%02d", + *tree, + EW, abs(baselon), NS, abs(baselat), + EW, abs(lon), NS, abs(lat) ); + sync_tree(dir); + } } @@ -223,6 +248,13 @@ int main( int argc, char **argv ) { } else if ( (string)argv[i] == "-d" ) { ++i; dest_base = argv[i]; + } else if ( (string)argv[i] == "-R" ) { + use_svn = false; + } else if ( (string)argv[i] == "-S" ) { + use_svn = true; + } else if ( (string)argv[i] == "-T" ) { + sync_areas( 37, -123, 0, 0 ); + exit(0); } else { usage( argv[0] ); exit(-1); @@ -230,6 +262,14 @@ int main( int argc, char **argv ) { ++i; } + // Use the appropriate default for the "-s" flag + if (source_base == NULL) { + if (use_svn) + source_base = svn_base; + else + source_base = rsync_base; + } + // Must call this before any other net stuff netInit( &argc,argv ); @@ -251,9 +291,10 @@ int main( int argc, char **argv ) { int maxlen = 256; int len; int lat, lon; - int last_lat = -9999; - int last_lon = -9999; + int last_lat = nowhere; + int last_lon = nowhere; bool recv_msg = false; + int synced_other = 0; while ( true ) { recv_msg = false; @@ -262,13 +303,13 @@ int main( int argc, char **argv ) { recv_msg = true; parse_message( msg, &lat, &lon ); - cout << "pos = " << lat << "," << lon << endl; + cout << "pos in msg = " << lat << "," << lon << endl; } if ( recv_msg ) { if ( lat != last_lat || lon != last_lon ) { int lat_dir, lon_dir, dist; - if ( last_lat == -9999 || last_lon == -9999 ) { + if ( last_lat == nowhere || last_lon == nowhere ) { lat_dir = lon_dir = 0; } else { dist = lat - last_lat; @@ -285,16 +326,31 @@ int main( int argc, char **argv ) { } } cout << "lat = " << lat << " lon = " << lon << endl; - cout << "lat_dir = " << lat_dir << " " << " lon_dir = " << lon_dir << endl; + cout << "lat_dir = " << lat_dir << " " + << "lon_dir = " << lon_dir << endl; sync_areas( lat, lon, lat_dir, lon_dir ); - } + } else if ( last_lat == nowhere || last_lon == nowhere ) { + cout << "Waiting for FGFS to finish startup" << endl; + } else { + switch (synced_other++) { + case 0: + sync_tree((char*) "Airports/K"); + break; + case 1: + sync_tree((char*) "Airports"); + break; + default: + cout << "Done non-tile syncs" << endl; + break; + } + } last_lat = lat; last_lon = lon; - } + } ulSleep( 1 ); - } + } // while true return 0; } -- 2.39.5