示例#1
0
int progressFunction(void* ptr, double totalDown, double nowDown, double totalUp, double nowUp) {
  if (ptr) {
    ProgressCallback& progressCallback = *((ProgressCallback*)ptr);
    if (totalUp > 0)
      progressCallback(nowUp / totalUp);
    if (totalDown > 0)
      progressCallback(nowDown / totalDown);
  }
  if (cancel) {
    cancel = false;
    return 1;
  } else
    return 0;
}
示例#2
0
void OGL_ProgressCallback(int delta_progress)
{
  progressCallback(delta_progress);
  /*
  if (!show_ogl_progress) {
    return;
  }
  ogl_progress += delta_progress;
#ifdef _OPENMP
  // can only draw OpenGL in the main thread
  if (omp_get_thread_num() == 0)
#endif
  {
    int32 current_ticks = SDL_GetTicks();
    if (current_ticks > last_update_tick + 33) {
      if (OGL_LoadScreen::instance()->Use()) {
        OGL_LoadScreen::instance()->Progress(
          100 * ogl_progress / total_ogl_progress);
      }
      else{
        draw_progress_bar(ogl_progress, total_ogl_progress);
      }
      last_update_tick = current_ticks;
    }
  }
   */
}
示例#3
0
int ResourceCache::Preload(const string & pattern, void(*progressCallback)(int, bool &))
{
	if (m_pFile == NULL)
		return 0;

	int iNumFiles = m_pFile->VGetNumResources();
	int iNumLoaded = 0;
	bool bCancel = false;

	for (int i = 0; i < iNumFiles; ++i)
	{
		Resource resource(m_pFile->VGetResourceName(i));

		if (StringHelper::WildcardMatch(pattern.c_str(), resource.m_name.c_str()))
		{
			shared_ptr<ResHandle> pHandle = GetHandle(&resource);
			++iNumLoaded;
		}

		if (progressCallback)
		{
			progressCallback(static_cast<int>(i* 100.0f / static_cast<float>(iNumFiles)), bCancel);
		}
	}

	return iNumLoaded;
}
示例#4
0
//
// ResCache::Preload								- Chapter 8, page 236
//
int ResCache::Preload(const std::string pattern, void (*progressCallback)(int, bool &))
{
	if (m_file==NULL)
		return 0;

	int numFiles = m_file->VGetNumResources();
	int loaded = 0;
	bool cancel = false;
	for (int i=0; i<numFiles; ++i)
	{
		Resource resource(m_file->VGetResourceName(i));

		if (WildcardMatch(pattern.c_str(), resource.m_name.c_str()))
		{
			shared_ptr<ResHandle> handle = g_pApp->m_ResCache->GetHandle(&resource);
			++loaded;
		}

		if (progressCallback != NULL)
		{
			progressCallback(i * 100/numFiles, cancel);
		}
	}
	return loaded;
}
示例#5
0
    void openHTTPConnection (URL_COMPONENTS& uc, URL::OpenStreamProgressCallback* progressCallback,
                             void* progressCallbackContext)
    {
        const TCHAR* mimeTypes[] = { _T("*/*"), 0 };

        DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES;

        if (address.startsWithIgnoreCase ("https:"))
            flags |= INTERNET_FLAG_SECURE;  // (this flag only seems necessary if the OS is running IE6 -
                                            //  IE7 seems to automatically work out when it's https)

        request = HttpOpenRequest (connection, isPost ? _T("POST") : _T("GET"),
                                   uc.lpszUrlPath, 0, 0, mimeTypes, flags, 0);

        if (request != 0)
        {
            INTERNET_BUFFERS buffers = { 0 };
            buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
            buffers.lpcszHeader = headers.toWideCharPointer();
            buffers.dwHeadersLength = (DWORD) headers.length();
            buffers.dwBufferTotal = (DWORD) postData.getSize();

            if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
            {
                int bytesSent = 0;

                for (;;)
                {
                    const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
                    DWORD bytesDone = 0;

                    if (bytesToDo > 0
                         && ! InternetWriteFile (request,
                                                 static_cast <const char*> (postData.getData()) + bytesSent,
                                                 (DWORD) bytesToDo, &bytesDone))
                    {
                        break;
                    }

                    if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
                    {
                        if (HttpEndRequest (request, 0, 0, 0))
                            return;

                        break;
                    }

                    bytesSent += bytesDone;

                    if (progressCallback != nullptr
                          && ! progressCallback (progressCallbackContext, bytesSent, (int) postData.getSize()))
                        break;
                }
            }
        }

        close();
    }
示例#6
0
/// Save the song to disk	
bool Song::Save(const char* filename, void (*progressCallback)(int, const char *))
{
	FILE* pfile = fopen(filename, "wb");
	// check if file open failed
	if(NULL == pfile)
		{
		printf("Failed to open song file %s!\n", filename);
        return false;
		}

	// init progress display
	progressCallback(0, "Saving song...");

	fwrite(&name, SONG_NAME_LEN * sizeof(char), 1, pfile);
	fwrite(&vol, sizeof(char), 1, pfile);
	fwrite(&BPM, sizeof(char), 1, pfile);
	fwrite(&pitch, sizeof(char), 1, pfile);
	fwrite(&currentPatternIndex, sizeof(int), 1, pfile);
	fwrite(&songPos, sizeof(int), 1, pfile);

	progressCallback(10, "Saving song...");

	unsigned int songListLength = PATTERNS_PER_SONG;
	fwrite(&songListLength, sizeof(int), 1, pfile);
	fwrite(&songList[0], songListLength * sizeof(char), 1, pfile);

	progressCallback(30, "Saving song...");

	unsigned int numPatterns = MAX_PATTERN;
	fwrite(&numPatterns, sizeof(int), 1, pfile);
	fwrite(&patterns[0], numPatterns * sizeof(DrumPattern), 1, pfile);

	progressCallback(60, "Saving song...");

	unsigned int numTracks = NUM_TRACKS;
	fwrite(&numTracks, sizeof(int), 1, pfile);
	fwrite(&trackMixInfo[0], numTracks * sizeof(TrackMixInfo), 1, pfile);

	progressCallback(100, "Saving song...");
	
	fclose(pfile);
	
	return true;	
}
void
avtDataObjectSource::UpdateProgress(int current, int total, const char *typ,
                                    const char *descr)
{
    CheckAbort();
    if (progressCallback != NULL)
    {
        progressCallback(progressCallbackArgs, typ, descr, current, total);
    }
}
示例#8
0
    static bool sendHeader (int socketHandle, const MemoryBlock& requestHeader, const uint32 timeOutTime,
                            URL::OpenStreamProgressCallback* progressCallback, void* progressCallbackContext)
    {
        size_t totalHeaderSent = 0;

        while (totalHeaderSent < requestHeader.getSize())
        {
            if (Time::getMillisecondCounter() > timeOutTime)
                return false;

            const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));

            if (send (socketHandle, static_cast <const char*> (requestHeader.getData()) + totalHeaderSent, numToSend, 0) != numToSend)
                return false;

            totalHeaderSent += numToSend;

            if (progressCallback != nullptr && ! progressCallback (progressCallbackContext, totalHeaderSent, requestHeader.getSize()))
                return false;
        }

        return true;
    }
示例#9
0
int ResCache::preload( const std::string pattern, void (*progressCallback)(int, bool &) ) {
	if( m_files.empty() )
		return 0;

	int loaded = 0;
	for( ResourceFiles::iterator fileItr = m_files.begin(); fileItr != m_files.end(); ++fileItr ) {
		int numFiles = (*fileItr)->VGetNumResources();
		bool cancel = false;
		for( int i = 0; i < numFiles; ++i ) {
			Resource resource((*fileItr)->VGetResourceName(i));

			if( WildcardMatch(pattern.c_str(), resource.m_name.c_str()) ) {
				std::shared_ptr<ResHandle> handle = getHandle(&resource);
				++loaded;
			}

			if( progressCallback != NULL ) {
				progressCallback(i * 100/numFiles, cancel);
			}
		}
	}

	return loaded;
}//ResCache::preload
示例#10
0
	bool ZipFile::readLargeFile(int p_Index, void *p_Buffer, void(*progressCallback)(int, bool&))
	{
		if (p_Buffer == NULL || p_Index < 0 || p_Index >= m_NumEntries)
			return false;

		// Quick'n dirty read, the whole file at once.
		// Ungood if the ZIP has huge files inside

		// Go to the actual file and read the local header.
		fseek(m_File, m_AppDir[p_Index]->hdrOffset, SEEK_SET);
		TZipLocalHeader h;

		memset(&h, 0, sizeof(h));
		fread(&h, sizeof(h), 1, m_File);
		if (h.sig != TZipLocalHeader::SIGNATURE)
			return false;

		// Skip extra fields
		fseek(m_File, h.fnameLen + h.xtraLen, SEEK_CUR);

		if (h.compression == Z_NO_COMPRESSION)
		{
			// Simply read in raw stored data.
			fread(p_Buffer, h.cSize, 1, m_File);
			return true;
		}
		else if (h.compression != Z_DEFLATED)
			return false;

		// Alloc compressed data buffer and read the whole stream
		char *pcData = new char[h.cSize];
		if (!pcData)
			return false;

		memset(pcData, 0, h.cSize);
		fread(pcData, h.cSize, 1, m_File);

		bool ret = true;

		// Setup the inflate stream.
		z_stream stream;
		int err;

		stream.next_in = (Bytef*)pcData;
		stream.avail_in = (uInt)h.cSize;
		stream.next_out = (Bytef*)p_Buffer;
		stream.avail_out = (128 * 1024); //  read 128k at a time h.ucSize;
		stream.zalloc = (alloc_func)0;
		stream.zfree = (free_func)0;

		// Perform inflation. wbits < 0 indicates no zlib header inside the data.
		err = inflateInit2(&stream, -MAX_WBITS);
		if (err == Z_OK)
		{
			uInt count = 0;
			bool cancel = false;
			while (stream.total_in < (uInt)h.cSize && !cancel)
			{
				err = inflate(&stream, Z_SYNC_FLUSH);
				if (err == Z_STREAM_END)
				{
					err = Z_OK;
					break;
				}
				else if (err != Z_OK)
				{
					//GCC_ASSERT(0 && "Something happened.");
					break;
				}

				stream.avail_out = (128 * 1024);
				stream.next_out += stream.total_out;

				progressCallback(count * 100 / h.cSize, cancel);
			}
			inflateEnd(&stream);
		}
		if (err != Z_OK)
			ret = false;

		delete[] pcData;
		return ret;
	}
示例#11
0
/// Load a songfrom disk	
bool Song::Load(const char* filename, void (*progressCallback)(int, const char *))
{
	FILE* pfile = fopen(filename, "rb");
	// check if file open failed
	if(NULL == pfile)
		{
		printf("Failed to open song file %s!\n", filename);
        return false;
		}

	// init progress display
	progressCallback(0, "Loading song...");

	fread(&name, SONG_NAME_LEN * sizeof(char), 1, pfile);
	fread(&vol, sizeof(char), 1, pfile);
	fread(&BPM, sizeof(char), 1, pfile);
	fread(&pitch, sizeof(char), 1, pfile);
	currentPatternIndex = freadInt(pfile);
	songPos = freadInt(pfile);
	progressCallback(10, "Loading song...");

	// read song list (sequence)
	int songListLength = freadInt(pfile);
	if (songListLength > PATTERNS_PER_SONG)
		{
		//DoMessage(sdlRenderer, bigFont, "Song Load Warning", "Song sequence length too long,\npossibly from later version.\n \nSong may be truncated.", false);
		SDL_ShowSimpleMessageBox(0, "Song Load Warning", "Song sequence length too long,\npossibly from later version.\n \nSong may be truncated.", NULL);
		fread(&songList[0], PATTERNS_PER_SONG * sizeof(char), 1, pfile);
		// skip over extra
		fseek(pfile, songListLength - PATTERNS_PER_SONG, SEEK_CUR);
		}
	else
		{
		fread(&songList[0], songListLength * sizeof(char), 1, pfile);
		}
	progressCallback(30, "Loading song...");

	// read patterns
	int numPatterns = freadInt(pfile);
	if (numPatterns > MAX_PATTERN)
		{
		//DoMessage(sdlRenderer, bigFont, "Song Load Warning", "Too many patterns,\npossibly from later version.\n \nSome patterns may not be loaded.", false);
		SDL_ShowSimpleMessageBox(0, "Song Load Warning", "Too many patterns,\npossibly from later version.\n \nSome patterns may not be loaded.", NULL);
		for (int i = 0; i < MAX_PATTERN; i++)
			patterns[i].Read(pfile);
		// skip over extra
		DrumPattern tempPat;
		for (int i = 0; i < (numPatterns - MAX_PATTERN); i++)
			tempPat.Read(pfile);
		}
	else
		{
		for (int i = 0; i < numPatterns; i++)
			patterns[i].Read(pfile);
		}
	progressCallback(60, "Loading song...");

	// read patterns
	int numTracks = freadInt(pfile);
	if (numTracks > NUM_TRACKS)
		{
		//DoMessage(sdlRenderer, bigFont, "Song Load Warning", "Too many tracks!\nSome tracks may not be loaded.", false);
		SDL_ShowSimpleMessageBox(0, "Song Load Warning", "Too many tracks!\nSome tracks may not be loaded.", NULL);
		for (int i = 0; i < NUM_TRACKS; i++)
			trackMixInfo[i].Read(pfile);
		// skip over extra
		TrackMixInfo tempTrackInfo;
		for (int i = 0; i < (numTracks - NUM_TRACKS); i++)
			tempTrackInfo.Read(pfile);
		}
	else
		{
		for (int i = 0; i < numTracks; i++)
			trackMixInfo[i].Read(pfile);
		}

	progressCallback(100, "Loading song...");
	
	fclose(pfile);
	
	return true;	
}
示例#12
0
/// Load a drumkit
bool DrumKit::Load(const char* kitname, void (*progressCallback)(int, const char *))
{
	char scmd[200], stemp[200];
	FILE *pfile;
	FILE *plog;

	printf("Loading drumkit '%s'...\n", kitname);

	// Init progress display
	progressCallback(0, "Loading drumkit...");

	char kitcfgpath[200];
	strcpy(kitcfgpath, "kits/");
	strcat(kitcfgpath, kitname);
	strcat(kitcfgpath, "/kit.cfg");
	char logpath[200];
	strcpy(logpath, "loadkit.log");			// JH 11/4/2009 - always make dk load log in program folder (dk folder may not exist!)

	if (KIT_DEBUG)
		{
		printf("Drumkit path: %s...\n", kitcfgpath);
		printf("Log file path: %s...\n", logpath);

		plog = fopen(logpath, "w");
		fprintf(plog, "Opening kit config file: %s\n", kitcfgpath);
		fflush(plog);
		}

	pfile = fopen(kitcfgpath, "r");
	// check if file open failed
	if(NULL == pfile)
		{
		if (KIT_DEBUG)
			{
			fprintf(plog, "Failed to open kit config file!\n");
			fclose(plog);
			}
        return false;
		}

	// Reset track info
	Init();

	// Parse kit file
	int lineNumber = 0;
	int numTracksRead = 0;
	bool end = false;
	while(!end)
		{
		// reset valid flags to trap errors
		bool validCmd = false;
		bool validParam = false;

		lineNumber++;
		if (!fgets(scmd, 200, pfile))
			break;
			
		if (KIT_DEBUG)
			fprintf(plog, "Command is %s\n", scmd);
			
		if(scmd[0] == '!' || scmd[0] == '#')
			{
			validCmd = true;
			validParam = true;
			if (KIT_DEBUG)
				fprintf(plog, "Comment encountered. Scanning till eol.\n");
			// read till end of line (character 10)
			fscanf(pfile, "%c", &stemp[0]);
			while(stemp[0] != 10)
				fscanf(pfile, "%c", &stemp[0]);
			}
		
		// track def?
		if(strstr(scmd, "track") == scmd)
			{
			// get param value
			char *param = strchr(scmd, '=');
			if (param)
				{
				param++;
				// get track value (= drum number/index)
				// NB: drum is associated with a "track number", so that
				//     we can have a drumkit with eg 3 drums that load into tracks
				//     1, 4 and 5.
				int trackNum = 0;
				sscanf(scmd+5, "%d", &trackNum);
				if (KIT_DEBUG) printf("Track %d:\n", trackNum);
				if (trackNum >=1 && trackNum <= MAX_DRUMS_PER_KIT)
					{
					numTracksRead++;
					validCmd = true;
					// remove "\n" off end of params
					param[strlen(param)-1] = 0;
					// parse params
					char *sname = strtok(param, "|");
					if (KIT_DEBUG) printf("   Name: %s\n", sname);
					if (sname)
						{
						char *smix = strtok(NULL, "|");
						if (KIT_DEBUG) printf("   Mix: %s\n", smix);
						if (smix)
							{
							char *span = strtok(NULL, "|");
							if (KIT_DEBUG) printf("   Pan: %s\n", span);
							if (span)
								{
								char *sfile = strtok(NULL, "|");
								if (KIT_DEBUG) printf("   File: %s\n", sfile);
								if (sfile)
									{
									// validate params
									validParam = true;
									int mix = atoi(smix);
									if (mix < 0 || mix > 255)
										{
										printf("Bad mix value, line %d\n", lineNumber);
										mix = 200;
										}
									int pan = atoi(span);
									if (pan < 0 || pan > 255)
										{
										printf("Bad pan value, line %d\n", lineNumber);
										pan = 128;
										}
									// text sample path
									char samplePath[200];
									strcpy(samplePath, "kits/");
									strcat(samplePath, kitname);
									strcat(samplePath, "/");
									strcat(samplePath, sfile);
									if (KIT_DEBUG) printf("samplepath: %s\n", samplePath);
									/*
									FILE* pf = fopen(samplePath, "rb");
									if (pf)
										fclose(pf);
									else
										printf("Bad sample filename, line %d\n", lineNumber);
									*/
									// set trackinfo
									int i = trackNum - 1;
									drums[i].vol = mix;
									drums[i].pan = pan;
									// TODO : safe name copy
									strcpy_s(drums[i].name, sname);
									// Load sample
									if (drums[i].sampleData)
										Mix_FreeChunk(drums[i].sampleData);
									drums[i].sampleData = Mix_LoadWAV(samplePath);
									if (KIT_DEBUG) printf("sampledata: %X\n", (unsigned int)drums[i].sampleData);

									// update progress bar
									progressCallback(trackNum * 10, "Loading drumkit...");
									}
								}
							}
						}
					}
				else
					{
	        		if (KIT_DEBUG)
	        			fprintf(plog, "Error - bad track number on line %d\n", lineNumber);
					}
				}
			else
				{
				if (KIT_DEBUG)
					fprintf(plog, "Error - bad parameter on line %d\n", lineNumber);
				}
				
				
			}	// end if track def

		// drumkit name?
		if(strstr(scmd, "name") == scmd)
			{
			validCmd = true;
			// get param value
			char *param = strchr(scmd, '=');
			if (param)
				{
				param++;
				// remove "\n" off end of param
				param[strlen(param)-1] = 0;
				if (strlen(param) > 0)
					{
					validParam = true;
					if (strlen(param) > 31)
						param[DRUMKIT_NAME_LEN - 1] = 0;
					strcpy(this->name, param);
					}
				}
			}

		if (!validCmd)
			{
			printf("Bad command on line %d\n", lineNumber);
			if (KIT_DEBUG)
				fprintf(plog, "Bad command on line %d\n", lineNumber);
			}

		if (!validParam)
			{
			printf("Bad parameter on line %d\n", lineNumber);
			if (KIT_DEBUG)
				fprintf(plog, "Bad parameter on line %d\n", lineNumber);
			}

		// check if EOF before end
		if (feof(pfile))
			end = true;
		}

	fclose(pfile);

	if (KIT_DEBUG)
		fclose(plog);
	
	return true;
}
示例#13
0
 virtual void markProgress() {
   std::unique_lock<std::mutex> lock(this->_mutex);
   progressCallback();
 }
示例#14
0
文件: fsrtns.c 项目: juddy/edcde
static int
CopyObject(char *sourceP, char *targetP, int repl, int link)
/* copy a directory, file, or symbolic link */
{
  struct stat src_stat;
  int rc;

  if (progressCallback)
    if (progressCallback(sourceP) != 0)
      return -1;

  if (periodicCallback)
    if (periodicCallback() != 0)
      return -1;

  if (lstat(sourceP, &src_stat) < 0)
    rc = errno;

  else {

copy_switch:

    switch(src_stat.st_mode & S_IFMT) {

      case S_IFDIR:
        rc = CopyDir(sourceP, targetP, repl, link, &src_stat);
        break;

      case S_IFREG:
        rc = CopyFile(sourceP, targetP, repl, &src_stat);
        break;

      case S_IFLNK:
        if (link)
          rc = CopyLink(sourceP, targetP, repl, &src_stat);
        else if (stat(sourceP, &src_stat) < 0)
          rc = errno;
        else
          goto copy_switch;
        break;

      default:
        rc = EINVAL;
    }
  }

  /*
   * Return code zero means everything is ok;
   * return code -1 means the operation is aborted.
   * In either case, propagated the return code up.
   */
  if (rc <= 0)
    return rc;

  /*
   * Return code > 0 means an error occurred in the last operation.
   * Call the the error callback function.  If the callback returns
   * zero, we return zero; this will cause the error to be ignored.
   * Otherwise we return -1 to signal that the operation is aborted.
   */
  if (!errorCallback)
    return rc;
  else if (errorCallback(sourceP, rc) == 0)
    return 0;
  else
    return -1;
}