示例#1
0
bool EvalCommand( UdpChain& chain , ComEvaluator& evaluator , SBuffer& buffer , ComConnection* con /*= NULL */ )
{
    unsigned size;
    while( chain.readPacket( buffer , size ) )
    {
        size_t oldSize = buffer.getAvailableSize();

        if ( oldSize < size )
            throw ComException( "error UDP Packet" );

        do
        {
            if ( !evaluator.evalCommand( buffer , con ) )
            {
                ::Msg( "readPacket Error Need Fix" );
                return false;
            }
        }
        while( oldSize - buffer.getAvailableSize() < size );

        if ( oldSize - buffer.getAvailableSize() != size )
            throw ComException( "error UDP Packet" );
    }

    return true;
}
      /// <summary>Reads the entire language file</summary>
      /// <param name="path">Full path</param>
      /// <returns>New language file</returns>
      /// <exception cref="Logic::ComException">COM Error</exception>
      /// <exception cref="Logic::FileFormatException">Corrupt XML / Missing elements / missing attributes</exception>
      /// <exception cref="Logic::InvalidValueException">Invalid languageID or pageID</exception>
      /// <exception cref="Logic::IOException">An I/O error occurred</exception>
      LanguageFile LanguageFileReader::ReadFile(Path path)
      {
         try
         {
            LanguageFile file(path);

            // Parse document
            LoadDocument();

            // Get root (as node)
            XmlNodePtr languageNode(Document->documentElement);

            // Read fileID + language tag
            file.ID = LanguageFilenameReader(path.FileName).FileID;
            file.Language = ReadLanguageTag(languageNode);

            // Read pages
            for (int i = 0; i < languageNode->childNodes->length; i++)
            {
               XmlNodePtr n = languageNode->childNodes->item[i];

               if (n->nodeType == Xml::NODE_ELEMENT)
                  file.Pages.Add( ReadPage(n) );
            }

            return file;
         }
         catch (_com_error& ex) {
            throw ComException(HERE, ex);
         }
      }
示例#3
0
   /// <summary>Get fully resolved copy of the path</summary>
   /// <returns></returns>
   /// <exception cref="Logic::ComException">COM operation failed</exception>
   /// <exception cref="Logic::FileNotFoundException">Path not found</exception>
   /// <exception cref="Logic::IOException">Unable to query properties</exception>
   Path  Path::GetResolved() const
   {
      Path resolved;
      
      // Resolve path
      if (!GetFullPathName(c_str(), MAX_PATH, (wchar*)resolved, nullptr))
         throw IOException(HERE, L"Unable to resolve path: "+SysErrorString());

      // Ensure exists
      if (!resolved.Exists())
         throw FileNotFoundException(HERE, resolved);

      // Get info
      SHFILEINFO info;
      if (!SHGetFileInfo((wchar*)resolved, 0, &info, sizeof(info), SHGFI_ATTRIBUTES))
         throw IOException(HERE, L"Unable to retrieve file info: "+SysErrorString());

      // Ensure is link
      if (info.dwAttributes & SFGAO_LINK)
      {
         IShellLinkPtr   shell(CLSID_ShellLink);
         IPersistFilePtr file(shell);
         HRESULT         hr;
         
         // Load file, resolve link, extract resolved path
         if (FAILED(hr=file->Load(resolved.c_str(), STGM_READ))
          || FAILED(hr=shell->Resolve(nullptr, SLR_NO_UI|SLR_ANY_MATCH))
          || FAILED(hr=shell->GetPath((wchar*)resolved, MAX_PATH, nullptr, 0)))
            throw ComException(HERE, L"Unable to resolve shell link: ", hr);
      }

      // Return resolved path
      return resolved;
   }
示例#4
0
      /// <summary>Loads game data</summary>
      /// <param name="data">arguments.</param>
      /// <returns></returns>
      DWORD WINAPI GameDataWorker::ThreadMain(GameDataWorkerData* data)
      {
         try
         {
            XFileSystem vfs;
            HRESULT  hr;

            // Init COM
            if (FAILED(hr=CoInitialize(NULL)))
               throw ComException(HERE, hr);

            // Feedback
            Console << Cons::UserAction << L"Loading " << VersionString(data->Version) << L" game data from " << data->GameFolder << ENDL;
            data->SendFeedback(ProgressType::Operation, 0, VString(L"Loading %s game data from '%s'", VersionString(data->Version).c_str(), data->GameFolder.c_str()));

            // Build VFS. 
            vfs.Enumerate(data->GameFolder, data->Version, data);

            // language files
            StringLib.Enumerate(vfs, data->Language, data);

            // script/game objects
            ScriptObjectLib.Enumerate(data);
            GameObjectLib.Enumerate(vfs, data);

            // Descriptions
            DescriptionLib.Enumerate(data);

            // legacy syntax file
            SyntaxLib.Enumerate(data);

            // Cleanup
            data->SendFeedback(Cons::UserAction, ProgressType::Succcess, 0, VString(L"Loaded %s game data successfully", VersionString(data->Version).c_str()));
            CoUninitialize();
            return 0;
         }
         catch (ExceptionBase& e)
         {
            // Feedback
            Console.Log(HERE, e);
            Console << ENDL;
            data->SendFeedback(Cons::Error, ProgressType::Failure, 0, GuiString(L"Failed to load game data : ") + e.Message);

            // BEEP!
            MessageBeep(MB_ICONERROR);

            // Cleanup
            CoUninitialize();
            return 0;
         }
      }