Пример #1
0
StringTableEntry Platform::getExecutableName()
{
#ifdef UNICODE
   StringTableEntry exe;
   getExecutableInfo( NULL, &exe );
   return exe;
#else
   static StringTableEntry cen = NULL;
   if (!cen)
   {
      char cen_buf[2048];
      GetModuleFileNameA( NULL, cen_buf, 2047);
      forwardslash(cen_buf);

      char *delimiter = dStrrchr( cen_buf, '/' );

      if( delimiter != NULL )
      {
         *delimiter = 0x00;
         delimiter++;
         cen = StringTable->insert(delimiter);
      }
      else
         cen = StringTable->insert(cen_buf);
   }
   return cen;
#endif
}
 //-----------------------------------------------------------------------------
 // Returns true if the pathname exists, false otherwise.  If isFile is true,
 // the pathname is assumed to be a file path, and only the directory part
 // will be examined (everything before last /)
 bool DirExists(char* pathname, bool isFile)
 {
    static char testpath[20000];
    dStrncpy(testpath, pathname, sizeof(testpath));
    if (isFile)
    {
       // find the last / and make it into null
       char* lastSlash = dStrrchr(testpath, '/');
       if (lastSlash != NULL)
          *lastSlash = 0;
    }
    return Platform::isDirectory(testpath);
 }
   void setExePathName(const char* exePathName)
   {
      if (exePathName == NULL)
         sBinPathName[0] = '\0';
      else
         dStrncpy(sBinPathName, exePathName, sizeof(sBinPathName));

      // set the base exe name field
      char *binName = dStrrchr(sBinPathName, '/');
      if( !binName )
         binName = sBinPathName;
      else
         *binName++ = '\0';
      sBinName = binName;
   }
Пример #4
0
//-----------------------------------------------------------------------------
bool Platform::createPath(const char *file)
{
   //<Mat> needless console noise
   //Con::warnf("creating path %s",file);
   // if the path exists, we're done.
   struct stat statData;
   if( stat(file, &statData) == 0 )
   {
	  return true;               // exists, rejoice.
   }

   // get the parent path.
   // we're not using basename because it's not thread safe.
   const U32 len = dStrlen(file) + 1;
   char parent[len];
   bool isDirPath = false;

   dSprintf(parent, len, "%s", file);

   if(parent[len - 2] == '/')
   {
	  parent[len - 2] = '\0';    // cut off the trailing slash, if there is one
	  isDirPath = true;          // we got a trailing slash, so file is a directory.
   }

   // recusively create the parent path.
   // only recurse if newpath has a slash that isn't a leading slash.
   char *slash = dStrrchr(parent,'/');
   if( slash && slash != parent)
   {
	  // snip the path just after the last slash.
	  slash[1] = '\0';
	  // recusively create the parent path. fail if parent path creation failed.
	  if(!Platform::createPath(parent))
		 return false;
   }

   // create *file if it is a directory path.
   if(isDirPath)
   {
	  // try to create the directory
	  if( mkdir(file, 0777) != 0) // app may reside in global apps dir, and so must be writable to all.
		 return false;
   }

   return true;
}
Пример #5
0
static void getExecutableInfo( StringTableEntry* path, StringTableEntry* exe )
{
   static StringTableEntry pathEntry = NULL;
   static StringTableEntry exeEntry = NULL;

   if( !pathEntry )
   {
      if (!Platform::getWebDeployment())
      {
         WCHAR cen_buf[ 2048 ];
         GetModuleFileNameW( NULL, cen_buf, sizeof( cen_buf ) / sizeof( cen_buf[ 0 ] ) );
         forwardslash( cen_buf );

         WCHAR* delimiter = dStrrchr( cen_buf, '/' );
         if( delimiter )
            *delimiter = '\0';

         char* pathBuf = convertUTF16toUTF8( cen_buf );
         char* exeBuf = convertUTF16toUTF8( delimiter + 1 );

         pathEntry = StringTable->insert( pathBuf );
         exeEntry = StringTable->insert( exeBuf );

         SAFE_DELETE_ARRAY( pathBuf );
         SAFE_DELETE_ARRAY( exeBuf );
      }
      else
      {
         char cdir[4096];
         GetCurrentDirectoryA(4096, cdir);
         pathEntry = StringTable->insert(cdir);
         exeEntry = StringTable->insert("WebGameCtrl.exe");
      }
   }

   if( path )
      *path = pathEntry;
   if( exe )
      *exe = exeEntry;
}
Пример #6
0
StringTableEntry Platform::getExecutablePath()
{
#ifdef UNICODE
   StringTableEntry path;
   getExecutableInfo( &path, NULL );
   return path;
#else
   static StringTableEntry cen = NULL;
   if (!cen)
   {
      char cen_buf[2048];
      GetModuleFileNameA( NULL, cen_buf, 2047);
      forwardslash(cen_buf);

      char *delimiter = dStrrchr( cen_buf, '/' );

      if( delimiter != NULL )
         *delimiter = 0x00;

      cen = StringTable->insert(cen_buf);
   }
   return cen;
#endif
}
Пример #7
0
bool StandardMainLoop::handleCommandLine( S32 argc, const char **argv )
{
   // Allow the window manager to process command line inputs; this is
   // done to let web plugin functionality happen in a fairly transparent way.
   PlatformWindowManager::get()->processCmdLineArgs(argc, argv);

   Process::handleCommandLine( argc, argv );

   // Set up the command line args for the console scripts...
   Con::setIntVariable("Game::argc", argc);
   U32 i;
   for (i = 0; i < argc; i++)
      Con::setVariable(avar("Game::argv%d", i), argv[i]);

#ifdef TORQUE_PLAYER
   if(argc > 2 && dStricmp(argv[1], "-project") == 0)
   {
      char playerPath[1024];
      Platform::makeFullPathName(argv[2], playerPath, sizeof(playerPath));
      Platform::setCurrentDirectory(playerPath);

      argv += 2;
      argc -= 2;

      // Re-locate the game:/ asset mount.

      Torque::FS::Unmount( "game" );
      Torque::FS::Mount( "game", Platform::FS::createNativeFS( playerPath ) );
   }
#endif

   // Executes an entry script file. This is "main.cs"
   // by default, but any file name (with no whitespace
   // in it) may be run if it is specified as the first
   // command-line parameter. The script used, default
   // or otherwise, is not compiled and is loaded here
   // directly because the resource system restricts
   // access to the "root" directory.

#ifdef TORQUE_ENABLE_VFS
   Zip::ZipArchive *vfs = openEmbeddedVFSArchive();
   bool useVFS = vfs != NULL;
#endif

   Stream *mainCsStream = NULL;

   // The working filestream.
   FileStream str; 

   const char *defaultScriptName = "main.cs";
   bool useDefaultScript = true;

   // Check if any command-line parameters were passed (the first is just the app name).
   if (argc > 1)
   {
      // If so, check if the first parameter is a file to open.
      if ( (dStrcmp(argv[1], "") != 0 ) && (str.open(argv[1], Torque::FS::File::Read)) )
      {
         // If it opens, we assume it is the script to run.
         useDefaultScript = false;
#ifdef TORQUE_ENABLE_VFS
         useVFS = false;
#endif
         mainCsStream = &str;
      }
   }

   if (useDefaultScript)
   {
      bool success = false;

#ifdef TORQUE_ENABLE_VFS
      if(useVFS)
         success = (mainCsStream = vfs->openFile(defaultScriptName, Zip::ZipArchive::Read)) != NULL;
      else
#endif
         success = str.open(defaultScriptName, Torque::FS::File::Read);

#if defined( TORQUE_DEBUG ) && defined (TORQUE_TOOLS) && !defined(TORQUE_DEDICATED) && !defined( _XBOX )
      if (!success)
      {
         OpenFileDialog ofd;
         FileDialogData &fdd = ofd.getData();
         fdd.mFilters = StringTable->insert("Main Entry Script (main.cs)|main.cs|");
         fdd.mTitle   = StringTable->insert("Locate Game Entry Script");

         // Get the user's selection
         if( !ofd.Execute() )
            return false;

         // Process and update CWD so we can run the selected main.cs
         S32 pathLen = dStrlen( fdd.mFile );
         FrameTemp<char> szPathCopy( pathLen + 1);

         dStrcpy( szPathCopy, fdd.mFile );
         //forwardslash( szPathCopy );

         const char *path = dStrrchr(szPathCopy, '/');
         if(path)
         {
            U32 len = path - (const char*)szPathCopy;
            szPathCopy[len+1] = 0;

            Platform::setCurrentDirectory(szPathCopy);

            // Re-locate the game:/ asset mount.

            Torque::FS::Unmount( "game" );
            Torque::FS::Mount( "game", Platform::FS::createNativeFS( ( const char* ) szPathCopy ) );

            success = str.open(fdd.mFile, Torque::FS::File::Read);
            if(success)
               defaultScriptName = fdd.mFile;
         }
      }
#endif
      if( !success )
      {
         char msg[1024];
         dSprintf(msg, sizeof(msg), "Failed to open \"%s\".", defaultScriptName);
         Platform::AlertOK("Error", msg);
#ifdef TORQUE_ENABLE_VFS
         closeEmbeddedVFSArchive();
#endif

         return false;
      }

#ifdef TORQUE_ENABLE_VFS
      if(! useVFS)
#endif
         mainCsStream = &str;
   }

   // This should rarely happen, but lets deal with
   // it gracefully if it does.
   if ( mainCsStream == NULL )
      return false;

   U32 size = mainCsStream->getStreamSize();
   char *script = new char[size + 1];
   mainCsStream->read(size, script);

#ifdef TORQUE_ENABLE_VFS
   if(useVFS)
      vfs->closeFile(mainCsStream);
   else
#endif
      str.close();

   script[size] = 0;

   char buffer[1024], *ptr;
   Platform::makeFullPathName(useDefaultScript ? defaultScriptName : argv[1], buffer, sizeof(buffer), Platform::getCurrentDirectory());
   ptr = dStrrchr(buffer, '/');
   if(ptr != NULL)
      *ptr = 0;
   Platform::setMainDotCsDir(buffer);
   Platform::setCurrentDirectory(buffer);

   Con::evaluate(script, false, useDefaultScript ? defaultScriptName : argv[1]); 
   delete[] script;

#ifdef TORQUE_ENABLE_VFS
   closeEmbeddedVFSArchive();
#endif

   return true;
}
Пример #8
0
static void _assignCommandKeys(const char* accel, MenuRef menu, MenuItemIndex item)
{
   if(!(accel && *accel))
      return;
   
   // get the modifier keys
   String _accel = String::ToLower( accel );
   int mods = _getModifierMask(_accel);

   // accel is space or dash delimted.
   // the modifier key is either the last token in accel, or the first char in accel.
   const char* key = dStrrchr(_accel, ' ');
   if(!key)
      key = dStrrchr(_accel, '-');
   if(!key)
      key = _accel;
   else
      key++;
      
   if(dStrlen(key) <= 1)
   {
      char k = dToupper( key[0] );
      SetMenuItemCommandKey( menu, item, false, k );
   }
   else
   {
      SInt16 glyph = kMenuNullGlyph;

      //*** A lot of these mappings came from a listing at http://developer.apple.com/releasenotes/Carbon/HIToolboxOlderNotes.html
      if(!dStricmp(key, "DELETE"))
         glyph = kMenuDeleteRightGlyph;
         
      else if(!dStricmp(key, "HOME"))
         glyph = kMenuNorthwestArrowGlyph;
         
      else if(!dStricmp(key, "END"))
         glyph = kMenuSoutheastArrowGlyph;
         
      else if(!dStricmp(key, "BACKSPACE"))
         glyph =  kMenuDeleteLeftGlyph;
         
      else if(!dStricmp(key, "TAB"))
         glyph =  kMenuTabRightGlyph;
         
      else if(!dStricmp(key, "RETURN"))
         glyph =  kMenuReturnGlyph;
         
      else if(!dStricmp(key, "ENTER"))
         glyph =  kMenuEnterGlyph;
         
      else if(!dStricmp(key, "PG UP"))
         glyph =  kMenuPageUpGlyph;
         
      else if(!dStricmp(key, "PG DOWN"))
         glyph =  kMenuPageDownGlyph;
         
      else if(!dStricmp(key, "ESC"))
         glyph =  kMenuEscapeGlyph;
         
      else if(!dStricmp(key, "LEFT"))
         glyph =  kMenuLeftArrowGlyph;
         
      else if(!dStricmp(key, "RIGHT"))
         glyph =  kMenuRightArrowGlyph;
         
      else if(!dStricmp(key, "UP"))
         glyph =  kMenuUpArrowGlyph;

      else if(!dStricmp(key, "DOWN"))
         glyph =  kMenuDownArrowGlyph;

      else if(!dStricmp(key, "SPACE"))
         glyph =  kMenuSpaceGlyph;

      else if(!dStricmp(key, "F1"))
         glyph =  kMenuF1Glyph;

      else if(!dStricmp(key, "F2"))
         glyph =  kMenuF2Glyph;

      else if(!dStricmp(key, "F3"))
         glyph =  kMenuF3Glyph;

      else if(!dStricmp(key, "F4"))
         glyph =  kMenuF4Glyph;

      else if(!dStricmp(key, "F5"))
         glyph =  kMenuF5Glyph;

      else if(!dStricmp(key, "F6"))
         glyph =  kMenuF6Glyph;

      else if(!dStricmp(key, "F7"))
         glyph =  kMenuF7Glyph;

      else if(!dStricmp(key, "F8"))
         glyph =  kMenuF8Glyph;

      else if(!dStricmp(key, "F9"))
         glyph =  kMenuF9Glyph;

      else if(!dStricmp(key, "F10"))
         glyph =  kMenuF10Glyph;

      else if(!dStricmp(key, "F11"))
         glyph =  kMenuF11Glyph;

      else if(!dStricmp(key, "F12"))
         glyph =  kMenuF12Glyph;

      else if(!dStricmp(key, "F13"))
         glyph =  kMenuF13Glyph;

      else if(!dStricmp(key, "F14"))
         glyph =  kMenuF14Glyph;

      else if(!dStricmp(key, "F15"))
         glyph =  kMenuF15Glyph;

      SetMenuItemKeyGlyph(menu, item, glyph);
   }

   SetMenuItemModifiers(menu, item, mods);
}
Пример #9
0
bool PxSingleActorData::preload( bool server, String &errorBuffer )
{
   if ( !Parent::preload( server, errorBuffer ) )
      return false;

   // If the stream is null, exit.
   if ( !physXStream || !physXStream[0] )
   {
      errorBuffer = "PxSingleActorData::preload: physXStream is unset!";
      return false;
   }

   // Set up our buffer for the binary stream filename path.
   UTF8 binPhysXStream[260] = { 0 };
   const UTF8* ext = dStrrchr( physXStream, '.' );

   // Copy the xml stream path except for the extension.
   if ( ext )
      dStrncpy( binPhysXStream, physXStream, getMin( 260, ext - physXStream ) );
   else
      dStrncpy( binPhysXStream, physXStream, 260 );

   // Concatenate the binary extension.
   dStrcat( binPhysXStream, ".nxb" );

   // Get the modified times of the two files.
   FileTime xmlTime = {0}, binTime = {0};
   Platform::getFileTimes( physXStream, NULL, &xmlTime );
   Platform::getFileTimes( binPhysXStream, NULL, &binTime );

   // If the binary is newer... load that.
   if ( Platform::compareFileTimes( binTime, xmlTime ) >= 0 )
      _loadCollection( binPhysXStream, true );

   // If the binary failed... then load the xml.
   if ( !physicsCollection )
   {
      _loadCollection( physXStream, false );

      // If loaded... resave the xml in binary format
      // for quicker subsequent loads.
      if ( physicsCollection )
         NXU::saveCollection( physicsCollection, binPhysXStream, NXU::FT_BINARY );
   }

   // If it still isn't loaded then we've failed!
   if ( !physicsCollection )
   {
      errorBuffer = String::ToString( "PxSingleActorData::preload: could not load '%s'!", physXStream );
      return false;
   }

   if (!shapeName || shapeName == '\0') 
   {
      errorBuffer = "PxSingleActorData::preload: no shape name!";
      return false;
   }

   // Now load the shape.
   shape = ResourceManager::get().load( shapeName );

   if (bool(shape) == false)
   {
      errorBuffer = String::ToString( "PxSingleActorData::preload: unable to load shape: %s", shapeName );
      return false;
   }

   return true;
}