NS_IMETHODIMP nsLocalFile::SetRelativeDescriptor(nsIFile* aFromFile, const nsACString& aRelativeDesc) { NS_NAMED_LITERAL_CSTRING(kParentDirStr, "../"); nsCOMPtr<nsIFile> targetFile; nsresult rv = aFromFile->Clone(getter_AddRefs(targetFile)); if (NS_FAILED(rv)) { return rv; } // // aRelativeDesc is UTF-8 encoded // nsCString::const_iterator strBegin, strEnd; aRelativeDesc.BeginReading(strBegin); aRelativeDesc.EndReading(strEnd); nsCString::const_iterator nodeBegin(strBegin), nodeEnd(strEnd); nsCString::const_iterator pos(strBegin); nsCOMPtr<nsIFile> parentDir; while (FindInReadable(kParentDirStr, nodeBegin, nodeEnd)) { rv = targetFile->GetParent(getter_AddRefs(parentDir)); if (NS_FAILED(rv)) { return rv; } if (!parentDir) { return NS_ERROR_FILE_UNRECOGNIZED_PATH; } targetFile = parentDir; nodeBegin = nodeEnd; pos = nodeEnd; nodeEnd = strEnd; } nodeBegin = nodeEnd = pos; while (nodeEnd != strEnd) { FindCharInReadable('/', nodeEnd, strEnd); targetFile->Append(NS_ConvertUTF8toUTF16(Substring(nodeBegin, nodeEnd))); if (nodeEnd != strEnd) { // If there's more left in the string, inc over the '/' nodeEnd is on. ++nodeEnd; } nodeBegin = nodeEnd; } return InitWithFile(targetFile); }
bool Enemy::InitData(const string& name) { EnemyInfo* info = PlaneManager::getInstance()->GetEnemyInfo(name); SetName(name); ChangeBulletType(info->bulletType); SetHpMax(info->hpMax); SetHp(GetHpMax()); _duration = info->duration; _stayTime = info->stayTime; SetMoveSpeed(info->moveSpeed); _score = info->score; _itemID = info->itemID; switch (info->layer) { case 1: SetOrder(LAYER_ENEMY_1); break; case 2: SetOrder(LAYER_ENEMY_2); break; case 3: SetOrder(LAYER_ENEMY_3); break; default: SetOrder(LAYER_ENEMY_1); break; } ChangeMoveState(info->moveStateID); SetMoveEnable(true); if (InitWithFile(info->imgPath)) { return true; } return false; }