Esempio n. 1
0
Node *createSnake(Node *_head,
                  int _count,
                  Node *_body)
{
  Node *root = createSegment(_head);
  setState(root, HEAD);
  setState(_body, BODY);

  const int StripeSize = 3;
  int counter = 0;

  Node *listptr = root;
  if(_count > 0)
  {
    //Create and position the body segments
    for(int i = 0; i < _count; ++i)
    {
      if(listptr!=NULL)
      {
        // Set the initial strip pattern on the snake
        // and change the starting frame for a ripple effect
        counter++;
        if(counter <= StripeSize)
        {
          addState(_body, ALT);
          _body->anim.currentFrame = 1;
        }
        else if(counter < (StripeSize*2))
        {
          removeState(_body, ALT);
          _body->anim.currentFrame = 0;
        }
        else
        {
          counter = 0;
        }

        insertAfterSegment(listptr, createSegment(_body), false);
        updateSnakePos(root, &listptr->next, RIGHT);

        listptr = getLastSegment(root);
      }
    }
  }

  return root;
}
Esempio n. 2
0
//------------------------------------------------------------------------------
std::string FilePath::getExtension() const
{
    std::string lExtension("");
    std::string lLastSegment = getLastSegment();

    if (!lLastSegment.empty())
    {
        size_t lnDotPos = lLastSegment.find_last_of('.');

        if (lnDotPos != std::string::npos)
        {
            lExtension = lLastSegment.substr(lnDotPos);
        }
    }

    return lExtension;
}
Esempio n. 3
0
int CLibMoor::selectDownloadMailBox(int MailBox, std::string path) {

	myPath = path;

        LOG(Log::Info, boost::format("Pobieranie do %1%") %path);
        mySeg = getLastSegment(path + myHash->getInfo().fileName);
        if (mySeg == myHash->getInfo().numOfSegments) {
            LOG(Log::Info, "Plik pobrano w calosci, przerywam...");
            return 1;
        }

	int vector_size = myHash->getInfo().accounts.size();

	if (MailBox > vector_size -1) {
		selected = 0;
		LOG(Log::Info ,"Skrzynka nie istnieje, wybieram pierwsza z listy");
	}
	else
		selected = MailBox;
	/*for (int i = 0; i < vector_size; ++i) {
		LOG(Log::Debug, boost::format( "%1%. ID: %2% L: %3% P: %4%" ) %i
										%myHash->getInfo().accounts[i].name
										%myHash->getInfo().accounts[i].login
										%myHash->getInfo().accounts[i].password);
	}*/

	int tries = 0;
	int baddownloads = 0;
	while (tries <= myHash->getInfo().accounts.size() || baddownloads <= (myHash->getInfo().accounts.size()*2) && downloadDone == false ) {
		std::string mailbox = myHash->getInfo().accounts[selected].name;
		std::string login = myHash->getInfo().accounts[selected].login;
		std::string passwd = myHash->getInfo().accounts[selected].password;

//		validMailbox = true;

                myMailBox = MailboxFactory::Instance().Create(mailbox, login, passwd);
		if (myMailBox) {
                        started = true;
			LOG(Log::Info, boost::format( "Logowanie do:  %1%" )
			               %myHash->getInfo().accounts[selected].name);
                        state = Status::Connecting;
			if (myMailBox->loginRequest() == 0) {
				tries = 0;
				myMailBox->setFileName(path + myHash->getInfo().fileName);
				myMailBox->setFileCRC(myHash->getInfo().crc);
                                state = Status::Connected;
				LOG(Log::Info, "Zalogowano pomyslnie...");
				LOG(Log::Info, "Sprawdzanie listy segmentow...");
				myMailBox->getHeadersRequest();
				unsigned int segments = myMailBox->countAvailableSegments(mySeg);
				bool found;
				if (segments == 0) {
					LOG(Log::Info, "--== Nie znaleziono zadnego segmentu! Zmieniam skrzynke ==--");
					found = false;
				} else {
					int tmpseg;
					bool missing;
					for (int i = 1; i <= myHash->getInfo().numOfSegments; i++) {
						tmpseg = myMailBox->checkAvailableSegment(i);
						if (tmpseg != true) {
							LOG(Log::Info,  boost::format("--== Uwaga, brakuje segmentu: %1% ==--") %(i));
							missing = true;
						}
					}
					if (missing != true) {
						LOG(Log::Info, "Znaleziono wszystkie segmenty, rozpoczynam pobieranie...");
					}
					else {
						LOG(Log::Info, "Na skrzynce brakuje segmentu(ow), pobieranie moze sie nie udac");
						// TODO - pytanie o zmiane skrzynki?
					}
					found = true;
				}
				if (found == true) {
					state = Status::Downloading;
					if (startDownload() == 0) {
						LOG(Log::Info, boost::format("Pobranie segmentu %1% nie powiodlo sie... Przelaczanie skrzynki...") %(mySeg + 1) );
						state = Status::SegmentError;
						baddownloads++;
					}
				}

			}
			else {
				LOG(Log::Info, "Logowanie nie powiodlo sie..." );
                                state = Status::ConnectionError;
			}
		}
		// Program should never reach this execution path, if decoder is
		// implemented properly!
		else {
			LOG(Log::Info, "Wybrana skrzynka nie jest obsługiwana w tej wersji programu.");
		}

		if (downloadDone == true) {
			myMailBox->setFileCRC(myHash->getInfo().crc);
			std::string crcFromHash = myMailBox->getFileCRC();
			LOG(Log::Info, boost::format ("Sprawdzanie CRC sciagnietego pliku, oczekiwane CRC: [%1%]") %crcFromHash);
			myMailBox->calculateFileCRC(myPath + myHash->getInfo().fileName);
			std::string fileCRC = myMailBox->getFileCRC();
			LOG(Log::Info, boost::format ("CRC sciagnietego pliku: [%1%]") %fileCRC);

			if (fileCRC.compare(crcFromHash) != 0){
				LOG(Log::Error, "-- Zle CRC sciagnietego pliku! --");
				state = Status::FileError;
			} else {
				LOG(Log::Info, "-- CRC OK! --");
				state = Status::Finished;
			}
			break;
		}

		if (tries >= myHash->getInfo().accounts.size()) {
			LOG(Log::Info, "Nie udalo sie pobrac pliku z zadnej ze skrzynek... Koncze program." );
			state = Status::FileError;
			downloadDone = true;
			delete myMailBox;
			break;
		}

		if (++selected >= vector_size)
				selected = 0;
		++tries;
	}

//	myMailBox -> Login();

	return 0;
}