Пример #1
0
BOOL ShowSelectExecDlg(LPSTR path)
{
	OPENFILENAME ofn;
	ZeroMemory(&ofn,sizeof(ofn));

	ofn.lpstrFile = GetRegValue(HKEY_CURRENT_USER,"Software\\GNU\\GnuPG","gpgProgram");
	if ( ofn.lpstrFile && existsFile(ofn.lpstrFile) ) {
		strcpy(path, ofn.lpstrFile);
		return TRUE;
	}
	ofn.lpstrFile = GetRegValue(HKEY_LOCAL_MACHINE,"Software\\GNU\\GnuPG","Install Directory");
	if ( ofn.lpstrFile ) {
		strcat(ofn.lpstrFile,"\\gpg.exe");
		if ( existsFile(ofn.lpstrFile) ) {
			strcpy(path, ofn.lpstrFile);
			return TRUE;
		}
	}

	ofn.lStructSize = sizeof(ofn);
	ofn.nMaxFile = MAX_PATH;
	ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON;

	ofn.lpstrFile = path;
	ofn.lpstrFilter = "GnuPG executable (gpg.exe)\0gpg.exe\0All files (*.*)\0*.*\0";
	ofn.lpstrTitle = "Select GnuPG executable";
	if (!GetOpenFileName(&ofn)) return FALSE;

	return TRUE;
}
Пример #2
0
int Project::load() {
  std::string curdir = getCurrentDir();
  std::string abspath = getRealPath(curdir);
  char buf[PATH_MAX];

  for (;;) {
    if (curdir.length() < MIN_PROJECT_PATH_LENGTH) {
      return -1; // error
    }

    std::string proj = curdir + PROJECT_FILENAME;
    if (existsFile(proj)) {
      filename = proj;
      content = getFileContent(proj);
      dir = curdir;
      return  0; // ok
    }

    // copy curdir to buf for, api compatibility
    memcpy(buf, curdir.c_str(), curdir.length());
    buf[curdir.length()] = '\0';

    curdir = dirname(buf);
  }

  return -1; // error
}
Пример #3
0
// to truncate a file at its current position
// leaving byte at current possition intact
// deleting everything afterward.
signed char FileMgr::trunc(FileDesc *file) {

	static const char *writeTest = "x";
	long size = file->seek(1, SEEK_CUR);
	if (size == 1) // was empty
		size = 0;
	char nibble [ 32767 ];
	bool writable = file->write(writeTest, 1);
	int bytes = 0;

	if (writable) {
		// get tmpfilename
		char *buf = new char [ strlen(file->path) + 10 ];
		int i;
		for (i = 0; i < 9999; i++) {
			sprintf(buf, "%stmp%.4d", file->path, i);
			if (!existsFile(buf))
				break;
		}
		if (i == 9999)
			return -2;

		int fd = ::open(buf, O_CREAT|O_RDWR, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
		if (fd < 0)
			return -3;
	
		file->seek(0, SEEK_SET);
		while (size > 0) {	 
			bytes = file->read(nibble, 32767);
			bytes = (bytes < size)?bytes:size;
			if (write(fd, nibble, bytes) != bytes) { break; }
			size -= bytes;
		}
		if (size < 1) {
			// zero out the file
			::close(file->fd);
			file->fd = ::open(file->path, O_TRUNC, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
			::close(file->fd);
			file->fd = -77;	// force file open by filemgr
			// copy tmp file back (dumb, but must preserve file permissions)
			lseek(fd, 0, SEEK_SET);
			do {
				bytes = read(fd, nibble, 32767);
				file->write(nibble, bytes);
			} while (bytes == 32767);
		}
		
		::close(fd);
		::close(file->fd);
		removeFile(buf);		// remove our tmp file
		file->fd = -77;	// causes file to be swapped out forcing open on next call to getFd()
	}
	else { // put offset back and return failure
		file->seek(-1, SEEK_CUR);
		return -1;
	}
	return 0;
}
Пример #4
0
	static std::vector<std::string> getAllFilenames(std::string path) {
		std::vector<std::string> list = getAllElementsInDir(path);
		std::vector<std::string> file_list;
		for (std::string fname : list) {
			if (fname.compare(0, 1, ".") == 0) //archivos que comienzan por "."
				continue;
			std::string full_name = path + "/" + fname;
			if (existsFile(full_name))
				file_list.push_back(full_name);
		}
		return file_list;
	}
Пример #5
0
	void setupDirectoryIndexes(){
		if(existsFile(getDataDirectory())){
			if(isInfoEnabled()) info(concatAll( 3, "Usando " , getDataDirectory() , " como directorio de indices"));
		}else{
			if(isInfoEnabled()) info(concatAll(2 , "No existe el directorio " , getDataDirectory()));

			if(createDirectory(getDataDirectory())){
				if(isInfoEnabled()) info(concatAll(2 , "Se crea " , getDataDirectory()));
			}else{
				if(isInfoEnabled()) info(concatAll(2 , "No se pudo crear el directorio " , getDataDirectory()));
				killAndWait(1);
				return;
			}
		}
	}
Пример #6
0
int __cdecl _gpg_open_keyrings(LPSTR ExecPath, LPSTR HomePath)
{
	if ( !ExecPath || (!*ExecPath && !ShowSelectExecDlg(ExecPath)) ) {
		return 0;
	}
	if ( !HomePath || (!*HomePath && !ShowSelectHomeDlg(HomePath)) ) {
		return 0;
	}
	if ( !existsFile(ExecPath) ) {
		//	ErrorMessage(txtwarning, txtinvalidexecutable, txtverifyoptions);
		return 0;
	}
	strcpy(gpgExecutable, ExecPath);
	strcpy(gpgHomeDirectory, HomePath);
	updateKeyUserIDs(publickeyuserid);
	updateKeyUserIDs(secretkeyuserid);
	return 1;
}
Пример #7
0
ssize_t fs_read_file(struct superblock *sb, const char *fname, char *buf,
        size_t bufsz) {
    if (existsFile(sb, fname) == FALSE) {
        errno = ENOENT;
        return -1;
    }
    int len = 0, exists = 0;
    char** fileParts = getFileParts(fname, &len);

    uint64_t fileBlock = findFile(sb, fname, &exists);

    struct inode* node;
    initNode(&node, sb->blksz);
    struct nodeinfo* meta = (struct nodeinfo*) calloc(1, sb->blksz);

    seek_read(sb, fileBlock, node);
    seek_read(sb, node->meta, meta);
    assert(strcmp(meta->name, fileParts[len - 1]) == 0);

    size_t size = MIN(meta->size, bufsz);
    size = MAX(sb->blksz, size);
    size_t read_blocks = 0;

    char* buf_p = (char*) calloc(1, size);
    char* p = buf_p;
    do {
        int i = 0;
        while (node->links[i] != 0) {
            seek_read(sb, node->links[i++], p);
            p = p + sb->blksz;
            read_blocks++;
        }
        if (node->next == 0)break;
        seek_read(sb, node->next, node);
    } while (node->next != 0);
    strcpy(buf, buf_p);
    freeFileParts(&fileParts, len);
    free(meta);
    free(node);
    free(buf_p);
    return size;
}
Пример #8
0
void StaticPoseNode::readFile(const std::string &file) {
    if (!existsFile(file)) {
        ROS_INFO("The pose file: %s does not exist, I will create a empty one", file.c_str());
        V4R::PoseD pose;
        pose.clear();
        pose.write(file, "frameSrc", "frameDes");
    }

    pose_msgs::Transform t;
    V4R::PoseD pose;
    pose.read(file, t.frameSrc, t.frameDes);
    if (t.frameSrc.empty() || t.frameDes.empty()) {
        ROS_ERROR("\tPose file error: %s", file.c_str() );
        return;
    }
    ROS_INFO("\tPoseFile: %s", file.c_str() );
    ROS_INFO("\tPose: %s -> %s  %s ", t.frameSrc.c_str() , t.frameDes.c_str() , pose.human_readable().c_str() );
    pose.copyTo(&t.rotation.x, &t.translation.x);
    transforms_.push_back(t);
}
Пример #9
0
    static void copyFile(const char* sourceFileName, const char* destFileName, bool overwrite)
    {
        // コピー先ファイルの存在確認
        if (!overwrite && existsFile(destFileName)) {
            LN_ENSURE(0);
            return;
        }

        // http://ppp-lab.sakura.ne.jp/ProgrammingPlacePlus/c/044.html
        FILE* fpSrc = fopen(sourceFileName, "rb");
        if (fpSrc == NULL) {
            LN_ENSURE(0);
            return;
        }

        FILE* fpDest = fopen(destFileName, "wb");
        if (fpDest == NULL) {
            LN_ENSURE(0);
            return;
        }

        // バイナリデータとして 1byte ずつコピー
        // (windows ではバッファリングが効くけど、それ以外はわからない。
        //  Linux とかで極端に遅くなるようならここでバッファリングも考える)
        while (1) {
            byte_t b;
            fread(&b, 1, 1, fpSrc);
            if (feof(fpSrc)) {
                break;
            }
            if (ferror(fpSrc)) {
                LN_ENSURE(0);
                return;
            }

            fwrite(&b, sizeof(b), 1, fpDest);
        }

        fclose(fpDest);
        fclose(fpSrc);
    }
Пример #10
0
int fs_write_file(struct superblock *sb, const char *fname, char *buf, size_t cnt) {
    const uint64_t blocksNeeded = MAX(1, cnt / sb->blksz);
    if (blocksNeeded > sb->freeblks) {
        errno = ENOSPC;
        return -1;
    }
    int blocksUsed = 0;

    if (strlen(fname) + 1 > getFileNameMaxLen(sb)) {
        errno = ENAMETOOLONG;
        return -1;
    }

    if (existsFile(sb, fname)) {
        errno = EEXIST;
        return -1;
    }

    int len = 0, exists = 0;
    char** fileParts = getFileParts(fname, &len);
    uint64_t dirBlock = findFile(sb, fname, &exists);
    char* dirName = NULL;
    struct inode* dirNode, *node;
    struct nodeinfo* meta = (struct nodeinfo*) calloc(1, sb->blksz);
    initNode(&dirNode, sb->blksz);
    initNode(&node, sb->blksz);
    seek_read(sb, dirBlock, dirNode);
    seek_read(sb, dirNode->meta, meta);
    dirName = calloc(1, sizeof (char)* (strlen(meta->name) + 1));
    strcpy(dirName, meta->name);

    if (strcmp(fileParts[MAX(0, len - 2)], dirName) != 0) {
        errno = EBADF;
        free(dirName);
        free(node);
        free(meta);
        free(dirNode);
        return -1;
    }


    uint64_t fileBlock = fs_get_block(sb);
    insertInBlock(sb, dirBlock, fileBlock);
    uint64_t blocksList[blocksNeeded];
    ///properly write the file
    while (blocksUsed < blocksNeeded) {
        uint64_t block = fs_get_block(sb);
        blocksList[blocksUsed] = block;
        char* temp = calloc(1, sb->blksz);
        char* blockContent = buf + sb->blksz * (blocksUsed);
        strcpy(temp, blockContent);
        blocksUsed++;
        seek_write(sb, block, temp);
        free(temp);
    }
    strcpy(meta->name, fileParts[len - 1]);
    meta->size = cnt;
    meta->reserved[0] = 0;

    node->meta = fs_get_block(sb);
    node->mode = IMREG;
    node->parent = dirBlock;

    seek_write(sb, node->meta, meta);

    uint64_t nodeBlock = fileBlock;
    blocksUsed = 0;
    while (blocksUsed < blocksNeeded) {
        int i = 0;
        int linksLen = getLinksMaxLen(sb);
        int N = MIN(linksLen, blocksNeeded);
        while (i < N) {
            node->links[i] = blocksList[i];
            i++;
            blocksUsed++;
        }
        if (blocksUsed < blocksNeeded) {
            node->next = fs_get_block(sb);
            seek_write(sb, nodeBlock, node);
            nodeBlock = node->next;
            node->next = 0;
            node->parent = fileBlock;
            node->mode = IMCHILD | IMREG;
            node->meta = fs_get_block(sb);
            strcpy(meta->name, fileParts[len - 1]);
            meta->size = cnt;
            seek_write(sb, node->meta, meta);
        }
    }
    seek_write(sb, nodeBlock, node);

    free(meta);
    free(node);
    freeFileParts(&fileParts, len);
    free(dirNode);
    free(dirName);

    return 0;
}
Пример #11
0
int main(int argc, char *argv[]) {
	// init fnkdat
	if(fnkdat(NULL, NULL, 0, FNKDAT_INIT) < 0) {
      perror("Could not initialize fnkdat");
      exit(EXIT_FAILURE);
	}

	bool bShowDebug = false;
    for(int i=1; i < argc; i++) {
	    //check for overiding params
	    std::string parameter(argv[i]);

		if(parameter == "--showlog") {
		    // special parameter which does not overwrite settings
            bShowDebug = true;
		} else if((parameter == "-f") || (parameter == "--fullscreen") || (parameter == "-w") || (parameter == "--window") || (parameter.find("--PlayerName=") == 0) || (parameter.find("--ServerPort=") == 0)) {
            // normal parameter for overwriting settings
            // handle later
        } else {
            printUsage();
            exit(EXIT_FAILURE);
		}
	}

	if(bShowDebug == false) {
	    // get utf8-encoded log file path
	    std::string logfilePath = getLogFilepath();
	    const char* pLogfilePath = logfilePath.c_str();

	    #if defined (_WIN32)

        // on win32 we need an ansi-encoded filepath
        WCHAR szwLogPath[MAX_PATH];
        char szLogPath[MAX_PATH];

        if(MultiByteToWideChar(CP_UTF8, 0, pLogfilePath, -1, szwLogPath, MAX_PATH) == 0) {
            fprintf(stderr, "Conversion of logfile path from utf-8 to utf-16 failed\n");
            exit(EXIT_FAILURE);
        }

        if(WideCharToMultiByte(CP_ACP, 0, szwLogPath, -1, szLogPath, MAX_PATH, NULL, NULL) == 0) {
            fprintf(stderr, "Conversion of logfile path from utf-16 to ansi failed\n");
            exit(EXIT_FAILURE);
        }

        pLogfilePath = szLogPath;

	    #endif

        int d = open(pLogfilePath, O_WRONLY | O_CREAT | O_TRUNC, 0644);
        if(d < 0) {
            fprintf(stderr, "Opening logfile '%s' failed\n", pLogfilePath);
            exit(EXIT_FAILURE);
        }

        // Hint: fileno(stdout) != STDOUT_FILENO on Win32 (see SDL_win32_main.c)
        if(dup2(d, fileno(stdout)) < 0) {
            fprintf(stderr, "Redirecting stdout failed\n");
            exit(EXIT_FAILURE);
        }

        // Hint: fileno(stderr) != STDERR_FILENO on Win32 (see SDL_win32_main.c)
        if(dup2(d, fileno(stderr)) < 0) {
            fprintf(stderr, "Redirecting stderr failed\n");
            exit(EXIT_FAILURE);
        }
	}

	fprintf(stdout, "Starting Dune Legacy " VERSION " ...\n"); fflush(stdout);

	if(checkForExcessPrecision() == true) {
        fprintf(stdout, "WARNING: Floating point operations are internally calculated with higher precision. Network game might get async. Are you using x87-FPU? Check your compile settings!\n"); fflush(stdout);
	}

    // First check for missing files
    std::vector<std::string> missingFiles = FileManager::getMissingFiles();

    if(missingFiles.empty() == false) {
        // create data directory inside config directory
        char tmp[FILENAME_MAX];
        fnkdat("data/", tmp, FILENAME_MAX, FNKDAT_USER | FNKDAT_CREAT);

        bool cannotShowMissingScreen = false;
        fprintf(stderr,"The following files are missing:\n");
        std::vector<std::string>::const_iterator iter;
        for(iter = missingFiles.begin() ; iter != missingFiles.end(); ++iter) {
            fprintf(stderr," %s\n",iter->c_str());
            if(iter->find("LEGACY.PAK") != std::string::npos) {
                cannotShowMissingScreen = true;
            }
        }

        fprintf(stderr,"Put them in one of the following directories:\n");
        std::vector<std::string> searchPath = FileManager::getSearchPath();
        std::vector<std::string>::const_iterator searchPathIter;
        for(searchPathIter = searchPath.begin(); searchPathIter != searchPath.end(); ++searchPathIter) {
            fprintf(stderr," %s\n",searchPathIter->c_str());
        }

        if(cannotShowMissingScreen == true) {
            return EXIT_FAILURE;
        }
    }

	bool bExitGame = false;
	bool bFirstInit = true;
	bool bFirstGamestart = false;

    debug = false;
    cursorFrame = UI_CursorNormal;

	do {
		int seed = time(NULL);
		srand(seed);

        // check if configfile exists
        std::string configfilepath = getConfigFilepath();
        if(existsFile(configfilepath) == false) {
            std::string userLanguage = getUserLanguage();
            if(userLanguage.empty()) {
                userLanguage = "en";
            }

            if(missingFiles.empty() == true) {
                // if all pak files were found we can create the ini file
                bFirstGamestart = true;
                createDefaultConfigFile(configfilepath, userLanguage);
            }
        }

		INIFile myINIFile(configfilepath);

		settings.general.playIntro = myINIFile.getBoolValue("General","Play Intro",false);
		settings.general.playerName = myINIFile.getStringValue("General","Player Name","Player");
		settings.video.width = myINIFile.getIntValue("Video","Width",640);
		settings.video.height = myINIFile.getIntValue("Video","Height",480);
		settings.video.fullscreen = myINIFile.getBoolValue("Video","Fullscreen",true);
		settings.video.doubleBuffering = myINIFile.getBoolValue("Video","Double Buffering",true);
		settings.video.frameLimit = myINIFile.getBoolValue("Video","FrameLimit",true);
		settings.video.preferredZoomLevel = myINIFile.getIntValue("Video","Preferred Zoom Level", 0);
		settings.video.scaler = myINIFile.getStringValue("Video","Scaler", "scale2x");
		settings.audio.musicType = myINIFile.getStringValue("Audio","Music Type","adl");
		settings.audio.playMusic = myINIFile.getBoolValue("Audio","Play Music", true);
		settings.audio.playSFX = myINIFile.getBoolValue("Audio","Play SFX", true);
		settings.audio.frequency = myINIFile.getIntValue("Audio","Audio Frequency", 22050);

		settings.general.language = myINIFile.getStringValue("General","Language","en");

		settings.network.serverPort = myINIFile.getIntValue("Network","ServerPort",DEFAULT_PORT);
		settings.network.metaServer = myINIFile.getStringValue("Network","MetaServer",DEFAULT_METASERVER);
		settings.network.debugNetwork = myINIFile.getBoolValue("Network","Debug Network",false);

		settings.ai.campaignAI = myINIFile.getStringValue("AI","Campaign AI",DEFAULTAIPLAYERCLASS);

        settings.gameOptions.gameSpeed = myINIFile.getIntValue("Game Options","Game Speed",GAMESPEED_DEFAULT);
        settings.gameOptions.concreteRequired = myINIFile.getBoolValue("Game Options","Concrete Required",true);
		settings.gameOptions.structuresDegradeOnConcrete = myINIFile.getBoolValue("Game Options","Structures Degrade On Concrete",true);
        settings.gameOptions.fogOfWar = myINIFile.getBoolValue("Game Options","Fog of War",false);
        settings.gameOptions.startWithExploredMap = myINIFile.getBoolValue("Game Options","Start with Explored Map",false);
        settings.gameOptions.instantBuild = myINIFile.getBoolValue("Game Options","Instant Build",false);
        settings.gameOptions.onlyOnePalace = myINIFile.getBoolValue("Game Options","Only One Palace",false);
        settings.gameOptions.rocketTurretsNeedPower = myINIFile.getBoolValue("Game Options","Rocket-Turrets Need Power",false);
        settings.gameOptions.sandwormsRespawn = myINIFile.getBoolValue("Game Options","Sandworms Respawn",false);
        settings.gameOptions.killedSandwormsDropSpice = myINIFile.getBoolValue("Game Options","Killed Sandworms Drop Spice",false);

        fprintf(stdout, "loading texts....."); fflush(stdout);
        pTextManager = new TextManager();
        fprintf(stdout, "\t\tfinished\n"); fflush(stdout);

		if(FileManager::getMissingFiles().size() > 0) {
		    // set back to english
            std::vector<std::string> missingFiles = FileManager::getMissingFiles();
            fprintf(stderr,"The following files are missing for language \"%s\":\n",_("LanguageFileExtension").c_str());
            std::vector<std::string>::const_iterator iter;
            for(iter = missingFiles.begin(); iter != missingFiles.end(); ++iter) {
                fprintf(stderr," %s\n",iter->c_str());
            }
            fprintf(stderr,"Language is changed to English!\n");
            settings.general.language = "en";
		}

		for(int i=1; i < argc; i++) {
		    //check for overiding params
            std::string parameter(argv[i]);

			if((parameter == "-f") || (parameter == "--fullscreen")) {
				settings.video.fullscreen = true;
			} else if((parameter == "-w") || (parameter == "--window")) {
				settings.video.fullscreen = false;
			} else if(parameter.find("--PlayerName=") == 0) {
                settings.general.playerName = parameter.substr(strlen("--PlayerName="));
            } else if(parameter.find("--ServerPort=") == 0) {
                settings.network.serverPort = atol(argv[i] + strlen("--ServerPort="));
            }
		}

        if(bFirstInit == true) {
            fprintf(stdout, "initializing SDL..... \t\t"); fflush(stdout);
            if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO) < 0) {
                fprintf(stderr, "ERROR: Couldn't initialise SDL: %s\n", SDL_GetError());
                exit(EXIT_FAILURE);
            }
            fprintf(stdout, "finished\n"); fflush(stdout);
        }

		if(bFirstGamestart == true && bFirstInit == true) {
            // detect 800x600 screen resolution
            if(SDL_VideoModeOK(800, 600, 8, SDL_HWSURFACE | SDL_FULLSCREEN) > 0) {
                settings.video.width = 800;
                settings.video.height = 600;
                settings.video.preferredZoomLevel = 1;

                myINIFile.setIntValue("Video","Width",settings.video.width);
                myINIFile.setIntValue("Video","Height",settings.video.height);
                myINIFile.setIntValue("Video","Preferred Zoom Level",1);

                myINIFile.saveChangesTo(getConfigFilepath());
            }
		}

        Scaler::setDefaultScaler(Scaler::getScalerByName(settings.video.scaler));

		SDL_EnableUNICODE(1);
		SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
		char strenv[] = "SDL_VIDEO_CENTERED=center";
        SDL_putenv(strenv);
		SDL_WM_SetCaption("Dune Legacy", "Dune Legacy");

		if(bFirstInit == true) {
			fprintf(stdout, "initializing sound..... \t");fflush(stdout);
			if( Mix_OpenAudio(settings.audio.frequency, AUDIO_S16SYS, 2, 1024) < 0 ) {
				SDL_Quit();
				fprintf(stderr,"Warning: Couldn't set %d Hz 16-bit audio\n- Reason: %s\n",settings.audio.frequency,SDL_GetError());
				exit(EXIT_FAILURE);
			} else {
				fprintf(stdout, "allocated %d channels.\n", Mix_AllocateChannels(6)); fflush(stdout);
			}
		}

        pFileManager = new FileManager( !missingFiles.empty() );

        // now we can finish loading texts
        if(missingFiles.empty()) {
            pTextManager->loadData();
        }

        if(pFileManager->exists("IBM.PAL") == true) {
            palette = LoadPalette_RW(pFileManager->openFile("IBM.PAL"), true);
        } else {
            // create dummy palette for showing missing files info
            palette = Palette(256);
            palette[115].r = 202;
            palette[115].g = 141;
            palette[115].b = 16;
            palette[255].r = 255;
            palette[255].g = 255;
            palette[255].b = 255;
        }

		screen = NULL;
		setVideoMode();


		fprintf(stdout, "loading fonts...");fflush(stdout);
		pFontManager = new FontManager();
		fprintf(stdout, "\t\tfinished\n"); fflush(stdout);

		if(!missingFiles.empty()) {
		    // some files are missing
		    bExitGame = true;
		    printMissingFilesToScreen();
		    fprintf(stdout, "Deinitialize....."); fflush(stdout);
		} else {
		    // everything is just fine and we can start the game

            fprintf(stdout, "loading graphics..."); fflush(stdout);
            pGFXManager = new GFXManager();
            fprintf(stdout, "\t\tfinished\n"); fflush(stdout);

            fprintf(stdout, "loading sounds..."); fflush(stdout);
            pSFXManager = new SFXManager();
            fprintf(stdout, "\t\tfinished\n"); fflush(stdout);

            GUIStyle::setGUIStyle(new DuneStyle);

            if(bFirstInit == true) {
                fprintf(stdout, "starting sound player..."); fflush(stdout);
                soundPlayer = new SoundPlayer();
                fprintf(stdout, "\tfinished\n");

                fprintf(stdout, "starting music player...\t"); fflush(stdout);
                if(settings.audio.musicType == "directory") {
                    fprintf(stdout, "playing from music directory\n"); fflush(stdout);
                    musicPlayer = new DirectoryPlayer();
                } else if(settings.audio.musicType == "adl") {
                    fprintf(stdout, "playing ADL files\n"); fflush(stdout);
                    musicPlayer = new ADLPlayer();
                } else if(settings.audio.musicType == "xmi") {
                    fprintf(stdout, "playing XMI files\n"); fflush(stdout);
                    musicPlayer = new XMIPlayer();
                } else {
                    fprintf(stdout, "failed\n"); fflush(stdout);
                    exit(EXIT_FAILURE);
                }

                //musicPlayer->changeMusic(MUSIC_INTRO);
            }

            // Playing intro
            if(((bFirstGamestart == true) || (settings.general.playIntro == true)) && (bFirstInit==true)) {
                fprintf(stdout, "playing intro.....");fflush(stdout);
                Intro* pIntro = new Intro();
                pIntro->run();
                delete pIntro;
                fprintf(stdout, "\t\tfinished\n"); fflush(stdout);
            }

            bFirstInit = false;

            fprintf(stdout, "starting main menu...");fflush(stdout);
            MainMenu * myMenu = new MainMenu();
            fprintf(stdout, "\t\tfinished\n"); fflush(stdout);
            if(myMenu->showMenu() == MENU_QUIT_DEFAULT) {
                bExitGame = true;
            }
            delete myMenu;

            fprintf(stdout, "Deinitialize....."); fflush(stdout);

            GUIStyle::destroyGUIStyle();

            // clear everything
            if(bExitGame == true) {
                delete musicPlayer;
                delete soundPlayer;
                Mix_HaltMusic();
                Mix_CloseAudio();
            }

            delete pTextManager;
            delete pSFXManager;
            delete pGFXManager;
		}

		delete pFontManager;
		delete pFileManager;
		if(bExitGame == true) {
			SDL_Quit();
		}
		fprintf(stdout, "\t\tfinished\n"); fflush(stdout);
	} while(bExitGame == false);

	// deinit fnkdat
	if(fnkdat(NULL, NULL, 0, FNKDAT_UNINIT) < 0) {
		perror("Could not uninitialize fnkdat");
		exit(EXIT_FAILURE);
	}

	return EXIT_SUCCESS;
}
bool ApplicationFileSystem::existsFile(Location location, const Path& path) {
    Path locationPath = getPath(location);
    auto hostDevice = HostPathDevice("", locationPath);
    return hostDevice.existsFile(path);
}
Пример #13
0
bool MenuBase::doInput(SDL_Event &event) {
	switch (event.type) {
		case (SDL_KEYDOWN): {
			// Look for a keypress
			switch(event.key.keysym.sym) {

				case SDLK_ESCAPE: {
					if((pChildWindow == NULL) && (bAllowQuiting == true)) {
						quit();
					}
                } break;

				case SDLK_RETURN: {
					if(SDL_GetModState() & KMOD_ALT) {
						SDL_WM_ToggleFullScreen(screen);
					}
                } break;

                case SDLK_p: {
                    if(SDL_GetModState() & KMOD_CTRL) {
                        // fall through to SDLK_PRINT
                    } else {
                        break;  // do not fall through
                    }
                } // fall through

				case SDLK_PRINT:
				case SDLK_SYSREQ: {
                    std::string screenshotFilename;
                    int i = 1;
                    do {
                        screenshotFilename = "Screenshot" + stringify(i) + ".bmp";
                        i++;
                    } while(existsFile(screenshotFilename) == true);

                    SDL_SaveBMP(screen, screenshotFilename.c_str());
                } break;

                case SDLK_TAB: {
                    if(SDL_GetModState() & KMOD_ALT) {
                        SDL_WM_IconifyWindow();
                    }
                } break;

				default: {
				} break;
			}
		} break;

		case SDL_MOUSEMOTION: {
			SDL_MouseMotionEvent* mouse = &event.motion;

			drawnMouseX = mouse->x;
			drawnMouseY = mouse->y;
		} break;

		case SDL_QUIT: {
			if((pChildWindow == NULL) && (bAllowQuiting == true)) {
				quit();
			}
        } break;

		default: {
        } break;
	}

	handleInput(event);

	return !quiting;
}
Пример #14
0
bool FileMgr::existsDir(NormalizedPath const & path, const char *idirName)
{ return existsFile(path, idirName); }
Пример #15
0
bool existsFile(const string& project, const string& suffix, const bool& mustExist){
//n check whether file project.suffix exists

    time_t dummy;
    return(existsFile(project,suffix,mustExist,dummy));
}