bool AresConfig::ParseToolbarItems (wxToolBar* toolbar, iDocumentNode* sectionNode) { csRef<iDataBuffer> buf = app->GetVFS ()->GetRealPath ("/ares/data/icons/toolbar/32x32"); csString path (buf->GetData ()); path += CS_PATH_SEPARATOR; wxImage image (32, 32); csRef<iDocumentNodeIterator> it = sectionNode->GetNodes (); while (it->HasNext ()) { csRef<iDocumentNode> child = it->Next (); if (child->GetType () != CS_NODE_ELEMENT) continue; csString value = child->GetValue (); if (value == "item") { csString name = child->GetAttributeValue ("name"); csString idString = child->GetAttributeValue ("id"); csString target = child->GetAttributeValue ("target"); csString imageFile = child->GetAttributeValue ("image"); csString command = child->GetAttributeValue ("command"); csString help = child->GetAttributeValue ("help"); csString args = child->GetAttributeValue ("args"); bool toggle = child->GetAttributeValueAsBool ("toggle"); int id = StringToId (idString); if (id == wxID_ANY) id = app->GetUIManager ()->AllocContextMenuID (); app->AllocateMenuCommand (id, name, target, command, args, help); image.LoadFile (wxString::FromUTF8 (path + imageFile)); toolbar->AddTool (id, wxString::FromUTF8 (name), wxBitmap (image), wxString::FromUTF8 (help), toggle ? wxITEM_CHECK : wxITEM_NORMAL); } else if (value == "sep") { toolbar->AddSeparator (); } else { return app->ReportError ("Error parsing 'aresedconfig.xml', unknown element '%s'!", value.GetData ()); } } return true; }
bool AresConfig::ParseMenuItems (wxMenu* menu, iDocumentNode* itemsNode) { csRef<iDocumentNodeIterator> it = itemsNode->GetNodes (); while (it->HasNext ()) { csRef<iDocumentNode> child = it->Next (); if (child->GetType () != CS_NODE_ELEMENT) continue; csString value = child->GetValue (); if (value == "item") { csString name = child->GetAttributeValue ("name"); csString hotkey = child->GetAttributeValue ("key"); csString idString = child->GetAttributeValue ("id"); csString target = child->GetAttributeValue ("target"); csString command = child->GetAttributeValue ("command"); csString help = child->GetAttributeValue ("help"); csString args = child->GetAttributeValue ("args"); int id = StringToId (idString); if (id == wxID_ANY) id = app->GetUIManager ()->AllocContextMenuID (); if (!hotkey.IsEmpty()) { name.SetCapacity (name.Length() + 1 + hotkey.Length()); name.Append ("\t"); name.Append (hotkey); } app->AllocateMenuCommand (id, name, target, command, args, help); app->AppendMenuItem (menu, id, name, help); } else if (value == "sep") { menu->AppendSeparator (); } else { return app->ReportError ("Error parsing 'aresedconfig.xml', unknown element '%s'!", value.GetData ()); } } return true; }
static VOID ParseArgs( IN int argc, IN char* argv[], OUT PCSTR* ppszUserName, OUT PDWORD pdwId, OUT PBOOLEAN pbShowSid ) { DWORD dwError = 0; int iArg = 0; PSTR pszArg = NULL; BOOLEAN bIsId = FALSE; PSTR pszUserName = NULL; DWORD dwId = 0; BOOLEAN bShowSid = FALSE; if (argc < 2) { ShowUsage(); exit(1); } // First, get any options. for (iArg = 1; iArg < argc; iArg++) { pszArg = argv[iArg]; if (!strcmp(pszArg, "--help") || !strcmp(pszArg, "-h")) { ShowUsage(); exit(0); } else if (!strcmp(pszArg, "--uid") || !strcmp(pszArg, "-u")) { PCSTR pszUid = NULL; bIsId = TRUE; if ((iArg + 1) >= argc) { fprintf(stderr, "Missing argument for %s option.\n", pszArg); ShowUsage(); exit(1); } pszUid = argv[iArg + 1]; iArg++; if (!IsAllDigits(pszUid)) { fprintf(stderr, "Non-numeric argument for %s option.\n", pszArg); ShowUsage(); exit(1); } dwError = StringToId(pszUid, &dwId); if (dwError) { fprintf(stderr, "Invalid range for %s option.\n", pszArg); ShowUsage(); exit(1); } // There can be no options following this one. iArg++; break; } else if (!strcmp(pszArg, "--show-sid")) { bShowSid = TRUE; } else { break; } } // Now get positional arguments. if ((argc - iArg) >= 1) { pszUserName = argv[iArg++]; if (LW_IS_NULL_OR_EMPTY_STR(pszUserName)) { fprintf(stderr, "Please specify a non-empty user name to query for.\n"); ShowUsage(); exit(1); } } // Now verify arguments. if (argc > iArg) { fprintf(stderr, "Too many arguments.\n"); ShowUsage(); exit(1); } if (bIsId && pszUserName) { fprintf(stderr, "Please specify either a uid or user name.\n"); ShowUsage(); exit(1); } *ppszUserName = pszUserName; *pdwId = dwId; *pbShowSid = bShowSid; }