/*! \brief Helper function for making filename of log file unique */ static void makeFilenameUnique(char* filename) { #ifdef LOG_RX_TX_UNIQUE if (doesFileExist(filename)) // if a file already exist with the same name, { // create a unique filename by adding a counter: char filename2[XS_MAX_FILENAME_LENGTH]; char basename[XS_MAX_FILENAME_LENGTH]; strcpy(basename, filename); basename[strlen(basename) - 4] = 0; // remove .log extension int counter = 1; do { sprintf(filename2, "%s_%d.log", basename, counter++); if (counter > 100) // don't count further than 100 { sprintf(filename2, "%s_n.log", basename); break; } } while (doesFileExist(filename2)); strcpy(filename, filename2); } #else (void)filename; #endif }
bool systemCheckPassed(void) { //the following system files must exist: if(!doesFileExist("/usr/bin/modinfo")) return false; if(!doesFileExist("/usr/bin/samprom")) return false; if(!doesFileExist("/usr/bin/power_key")) return false; if(!doesFileExist("/usr/bin/otgd")) return false; if(!doesFileExist("/usr/bin/read_mac_sn")) return false; std::string info; //make sure power_key is running std::string power_key_check = "ps | grep power_key | grep -v ps"; std::string cmd = "(" + power_key_check + ")" + " > /tmp/systest"; system(cmd.c_str()); std::ifstream output_file("/tmp/systest"); std::string line; while(std::getline(output_file, line)) info += (line + '\n'); if(info.size() <= 3) { std::cout << "power_key is not running." << std::endl << std::flush; return false; } return true; }
char * getFullPath(char * name) { bool found = FALSE; char * pathlist = getenv("PATH"); // prepare the memory for the possible paths char * home = getenv("HOME"); char * homeCopy = malloc(MAXPATHLEN*sizeof(char*)); strcpy(homeCopy,home); char * pathCopy = malloc(MAXPATHLEN*sizeof(char*)); strcpy(pathCopy,pathlist); char * result = malloc(MAXPATHLEN*sizeof(char*)); // prepare memory to store the result char * current = getCurrentWorkingDir(); strcat(homeCopy,"/"); strcat(homeCopy,name); if (name[0] == '/') { // if it is an absolute path, store result. if (doesFileExist(name)) { strcpy(result,name); found = TRUE; } } else { if (doesFileExist(homeCopy)) { // If it is in the home directory strcpy(result,homeCopy); found = TRUE; } else { strcat(current,"/"); strcat(current,name); if (doesFileExist(current)) { // If it is in the current directory strcpy(result,current); found = TRUE; } else { // Else, check every path in PATH environment variable char* fullpath = strtok(pathCopy, ":"); while (fullpath != NULL) { char * path = malloc(MAXPATHLEN*sizeof(char*)); strcpy(path,fullpath); strcat(path,"/"); if (doesFileExist(strcat(path,name))) { strcpy(result,path); found = TRUE; } fullpath = strtok(NULL, ":"); free(path); } } } } free(current); free(pathCopy); free(homeCopy); if (found) { return result; } else { free(result); PrintPError(name); return NULL; } } /* getFullPath */
CLoggerDefaultBackEnd::CLoggerDefaultBackEnd(){ std::string tmpFilePath; tmpFilePath = "Logs/"; tmpFilePath += getDate(); for(int counter = 1; true; counter++){ std::string logFilePathCheck; logFilePathCheck = tmpFilePath; logFilePathCheck += "_"; logFilePathCheck += std::to_string(counter); logFilePathCheck += ".log"; bool doesFileExistCheck = doesFileExist(logFilePathCheck); bool isFileEmptyCheck = isFileEmpty(logFilePathCheck); if((doesFileExistCheck && isFileEmptyCheck) || !doesFileExistCheck){ logFilePath = logFilePathCheck; break; } } }
static void processLanguageRegex (const langType language, const char* const parameter) { if (parameter == NULL || parameter [0] == '\0') clearPatternSet (language); else if (parameter [0] != '@') addLanguageRegex (language, parameter); else if (! doesFileExist (parameter + 1)) error (WARNING, "cannot open regex file"); else { const char* regexfile = parameter + 1; FILE* const fp = fopen (regexfile, "r"); if (fp == NULL) error (WARNING | PERROR, regexfile); else { vString* const regex = vStringNew (); while (readLine (regex, fp)) addLanguageRegex (language, vStringValue (regex)); fclose (fp); vStringDelete (regex); } } }
/* Get the absolute path of a file. Searches first in PATH. * If not found in PATH, will check if fileName is already * an absolute OR relative path. * Accepts absolute paths with '~' representing HOME * @param: string of the name or path of a file * @return: string of absolute path of the file if found. NULL otherwise. */ char* getFilePath(char* fileName){ char** paths = getPaths(); char* filePath = NULL; int i = 0; filePath = malloc(PATH_MAX*sizeof(char)); while( paths[i] != NULL){ strcpy(filePath, paths[i]); strcat(filePath, "/"); strcat(filePath, fileName); if(doesFileExist(filePath)){ return filePath; } i++; } //File was not found in PATH strcpy(filePath, fileName); filePath = tildaToHome(filePath); filePath = realpath(filePath, NULL); if( filePath != NULL ){ return filePath; } return NULL; }
void verifyFileExists(const char * path) { if (!doesFileExist(path)) { int fd = open(path, O_RDWR | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); VERIFY_ERRNO(-1 != fd, "Failed to create the file for appending: %s\n", ECFailedToCreateFile); close(fd); } }
int main(int argc, char const *argv[]) { VERIFY(argc == ParameterCount, "Bad parameter count\n", ECBadArgumentCount); const char * filePath = argv[TargetFile]; if (doesFileExist(filePath)) { printf("Input file exists\n"); FileType fileType = getFileType(filePath); printFileType(fileType); VERIFY(FTDir != fileType, "Can't add data to a directory\n", ECFileIsADirectory); makeFileSize(filePath, TARGET_FILE_SIZE); } else { printf("Input file does not exist\n"); makeFileSize(filePath, TARGET_FILE_SIZE); } /* This is the code used for making the graph size_t writeSizes[] = {MEGABYTE(1),KILOBYTE(256), KILOBYTE(64), KILOBYTE(16), KILOBYTE(4)}; for (int i = 0; i < ARRAYSIZE(writeSizes); i++) { printWriteStatistics(filePath, writeSizes[i]); } printf("**************\n"); */ printWriteStatistics(filePath, WRITE_SIZE); return 0; }
extern void openTagFile (void) { setDefaultTagFileName (); TagsToStdout = isDestinationStdout (); if (TagFile.vLine == NULL) TagFile.vLine = vStringNew (); /* Open the tags file. */ if (TagsToStdout) /* Open a tempfile with read and write mode. Read mode is used when * write the result to stdout. */ TagFile.fp = tempFile ("w+", &TagFile.name); else { boolean fileExists; TagFile.name = eStrdup (Option.tagFileName); fileExists = doesFileExist (TagFile.name); if (fileExists && ! isTagFile (TagFile.name)) error (FATAL, "\"%s\" doesn't look like a tag file; I refuse to overwrite it.", TagFile.name); if (Option.etags) { if (Option.append && fileExists) TagFile.fp = fopen (TagFile.name, "a+b"); else TagFile.fp = fopen (TagFile.name, "w+b"); } else { if (Option.append && fileExists) { TagFile.fp = fopen (TagFile.name, "r+"); if (TagFile.fp != NULL) { TagFile.numTags.prev = updatePseudoTags (TagFile.fp); fclose (TagFile.fp); TagFile.fp = fopen (TagFile.name, "a+"); } } else { TagFile.fp = fopen (TagFile.name, "w"); if (TagFile.fp != NULL) addPseudoTags (); } } if (TagFile.fp == NULL) error (FATAL | PERROR, "cannot open tag file"); } if (TagsToStdout) TagFile.directory = eStrdup (CurrentDirectory); else TagFile.directory = absoluteDirname (TagFile.name); }
bool SampleApexResourceCallback::doesFileExist(const char* filename, const char* ext) { char fullname[512] = {0}; physx::shdfnd::strlcat(fullname, sizeof(fullname), filename); physx::shdfnd::strlcat(fullname, sizeof(fullname), ext); return doesFileExist(fullname); }
static char* getEpiphanyExecutableFile(struct interpreterconfiguration* configuration) { char * fullFilename=(char*) malloc(strlen(EPIPHANY_BINARY_FILE) + 6); if (configuration->loadElf) { sprintf(fullFilename, "%s.elf", EPIPHANY_BINARY_FILE); } else if (configuration->loadSrec) { sprintf(fullFilename, "%s.srec", EPIPHANY_BINARY_FILE); } else { fprintf(stderr, "Neither ELF nore SREC file formats selected for device executable\n"); exit(0); } if (doesFileExist(fullFilename)) return fullFilename; char * binLocation=(char*) malloc(strlen(fullFilename) + strlen(BIN_PATH) + 1); sprintf(binLocation, "%s%s", BIN_PATH, fullFilename); if (doesFileExist(binLocation)) return binLocation; fprintf(stderr, "Can not device binary '%s' in the local directory or binary (%s) directory\n", fullFilename, BIN_PATH); exit(0); }
int rmpathTest(char *szPath) { printf ("rmpathTest for %s...\n", szPath); int rv=rmpath(szPath); if ((rv != 0) || doesFileExist(szPath)) { printf ("rmpath failed for %s, rv %d errno %d\n", szPath, rv, errno); return 1; } return 0; }
void DataHandler::createFileIfNotExisting(const char *dataFilePath) { if(!doesFileExist(dataFilePath)) { cerr << "File " << dataFilePath << " doesn't exist. Creating..." << endl; fstream createStream(dataFilePath, ios_base::out); if(createStream.fail()) { string error = string("File ") + dataFilePath + string(" doesn't exist and unable to create it!"); throw error; } createStream.close(); } }
bool SimpleFileSystemVolume::renameFile(const UnicodeString& currentName, const UnicodeString& newName) { auto lock = ScopedMutexLock(mutex_); if (doesFileExist(newName)) return false; for (auto entry : entries_) { if (entry->name == currentName) { entry->name = newName; return true; } } return false; }
void Config::loadConfig() { if (doesFileExist(charenc("csgo//cfg//cheetos//config.ini"))) { configManager.initialize(charenc("config.ini")); configManager.getBoolean(charenc("Aimbot"), charenc("Enabled"), cvar::aimbot_enabled); configManager.getInteger(charenc("Aimbot"), charenc("Aimbot Key"), cvar::general_key_aimbot); configManager.getFloat(charenc("Aimbot"), charenc("Field of View"), cvar::aimbot_fov); configManager.getFloat(charenc("Aimbot"), charenc("Smoothing"), cvar::aimbot_smoothing); configManager.getFloat(charenc("Aimbot"), charenc("Recoil Control Min"), cvar::aimbot_rcs_min); configManager.getFloat(charenc("Aimbot"), charenc("Recoil Control Max"), cvar::aimbot_rcs_max); configManager.getFloat(charenc("Aimbot"), charenc("Randomize Hitbox"), cvar::aimbot_randomize_hitbox); configManager.getFloat(charenc("Aimbot"), charenc("Randomize Angles"), cvar::aimbot_randomize_angle); configManager.getBoolean(charenc("ESP"), charenc("Enabled"), cvar::esp_enabled); configManager.getBoolean(charenc("ESP"), charenc("Box"), cvar::esp_draw_box); configManager.getBoolean(charenc("ESP"), charenc("Name"), cvar::esp_draw_name); configManager.getBoolean(charenc("ESP"), charenc("Weapon"), cvar::esp_draw_weapon); configManager.getBoolean(charenc("ESP"), charenc("Callout"), cvar::esp_draw_callout); configManager.getBoolean(charenc("ESP"), charenc("Health"), cvar::esp_draw_health); configManager.getBoolean(charenc("ESP"), charenc("Health Text"), cvar::esp_draw_health_text); configManager.getBoolean(charenc("ESP"), charenc("Armor"), cvar::esp_draw_armor); configManager.getBoolean(charenc("ESP"), charenc("Armor Text"), cvar::esp_draw_armor_text); configManager.getBoolean(charenc("ESP"), charenc("World"), cvar::esp_draw_world); configManager.getBoolean(charenc("ESP"), charenc("Glow"), cvar::esp_draw_glow); configManager.getBoolean(charenc("Misc"), charenc("Bunnyhop"), cvar::misc_bunnyhop); configManager.getBoolean(charenc("Misc"), charenc("Triggerbot"), cvar::misc_triggerbot); configManager.getInteger(charenc("Misc"), charenc("Triggerbot Key"), cvar::general_key_triggerbot); configManager.getBoolean(charenc("Misc"), charenc("Skin Changer"), cvar::misc_skinchanger); configManager.getBoolean(charenc("Misc"), charenc("Knife Changer"), cvar::misc_knifechanger); configManager.getInteger(charenc("Misc"), charenc("Knife Model"), cvar::misc_knifechanger_model); configManager.getInteger(charenc("Misc"), charenc("Viewmodel Field of View"), cvar::misc_overridefov); configManager.getBoolean(charenc("Misc"), charenc("Standalone Recoil Control"), cvar::misc_recoilcontrol); configManager.getFloat(charenc("Misc"), charenc("Standalone Recoil Control Scale"), cvar::misc_recoilcontrol_scale); configManager.getBoolean(charenc("Misc"), charenc("Matchmaking Scoreboard"), cvar::misc_scoreboard); } else { saveConfig(); } }
int mkpathTest(char *szPath, char *szCheck) { int rv = 0; printf ("mkpathTest for %s...\n", szPath); rv=mkpath(szPath, S_IRWXU); if (szCheck==NULL) szCheck=szPath; if ((rv != 0) || !doesFileExist(szCheck)) { printf ("mkpath failed for %s, rv %d errno %d\n", szCheck, rv, errno); return 1; } else { rv=rmpath(szCheck); if (rv != 0) { printf ("rmpath failed for %s, rv %d errno %d\n", szCheck, rv, errno); return 1; } } return 0; }
FILE_HANDLING_STS_ENUM MemoryCard::createFile(char * pFileName_UB) { if (doesFileExist(pFileName_UB)) return FILE_HANDLING_STS_ALREADY_EXISTS; // Open() function auto-create a file GL_FileData_X.pFileName_UB = pFileName_UB; GL_FileData_X.file_H = GL_pCard_H->open(pFileName_UB, FILE_WRITE); if (GL_FileData_X.file_H) { GL_FileData_X.isOpened = true; // Close the file GL_FileData_X.file_H.close(); GL_FileData_X.file_H = File(); // empty constructor GL_FileData_X.isOpened = false; } else { return FILE_HANDLING_STS_CANNOT_CREATE; } return FILE_HANDLING_STS_OK; }
//------------------------------------------------------------------------------ // updateData() -- Update the log file //------------------------------------------------------------------------------ bool Logger::openFile() { // local flags (default is success) bool tOpened = true; bool tFailed = false; // Need a file name if (filename->len() == 0) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "Logger::openFile(): Unable to open logger file: no file name" << std::endl; } tOpened = false; tFailed = true; } else { //--- // Allocate space for the full file name //--- size_t len = pathname->len(); // start with the length of the path name len += 1; // add a character for the slash len += filename->len(); // add the length of the file name len += 4; // add characters for possible version number, "_V99" len += 1; // Add one for the null(0) at the end of the string const size_t NAME_LENGTH = len; char* fullname = new char[NAME_LENGTH]; fullname[0] = '\0'; //--- // Create the (initial) full file name //--- if (pathname->len() > 0) { lcStrcat(fullname,NAME_LENGTH,*pathname); lcStrcat(fullname,NAME_LENGTH,"/"); } lcStrcat(fullname,NAME_LENGTH,*filename); //--- // Make sure that it doesn't already exist (we don't want to over write good data). //--- bool validName = !doesFileExist(fullname); if ( !validName ) { // If the file already exists, try appending a version number "v99" .. char* origname = new char[NAME_LENGTH]; lcStrcpy(origname, NAME_LENGTH, fullname); validName = false; for (unsigned int i = 1; i <= 99 && !validName; i++) { sprintf(fullname, "%s_v%02d", origname, i); validName = !doesFileExist(fullname); } if ( !validName ) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "Logger::openFile(): All version of the logger file already exists: " << origname << std::endl; } tOpened = false; tFailed = true; } delete[] origname; } if ( validName ) { //--- // Make sure we have an output stream //--- if (lout == 0) lout = new std::ofstream(); //--- // Open the file //--- if (isMessageEnabled(MSG_INFO)) { std::cout << "Logger::openFile() Opening log file = " << fullname << std::endl; } lout->open(fullname); if (lout->fail()) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "Logger::openFile(): Failed to open log file: " << fullname << std::endl; } tOpened = false; tFailed = true; } else if (topLine != 0) { *lout << *topLine << std::endl; } } delete[] fullname; } opened = tOpened; failed = tFailed; return opened; }
//------------------------------------------------------------------------------ // Open the data file //------------------------------------------------------------------------------ bool FileReader::openFile() { // When we're already open, just return if (isOpen()) return true; // local flags (default is success) bool tOpened = true; bool tFailed = false; // Need a file name if (filename == nullptr || filename->len() == 0) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "FileReader::openFile(): Unable to open data file: no file name" << std::endl; } tOpened = false; tFailed = true; } else { //--- // Allocate space for the full file name //--- size_t nameLength = 0; if (pathname != nullptr) { nameLength += pathname->len(); // add the length of the path name nameLength += 1; // add a character for the slash } nameLength += filename->len(); // add the length of the file name nameLength += 1; // Add one for the null(0) at the end of the string char* fullname = new char[nameLength]; fullname[0] = '\0'; //--- // Create the (initial) full file name //--- if (pathname != nullptr && pathname->len() > 0) { lcStrcat(fullname, nameLength ,*pathname); lcStrcat(fullname, nameLength, "/"); } lcStrcat(fullname,nameLength,*filename); //--- // Make sure that it exists //--- bool validName = doesFileExist(fullname); //--- // When we have a valid file name ... //--- if ( validName ) { //--- // Make sure we have an input stream //--- if (sin == nullptr) sin = new std::ifstream(); //--- // Open the file (binary input mode) //--- sin->open(fullname, std::ios_base::in | std::ios_base::binary ); if (isMessageEnabled(MSG_INFO)) { std::cout << "FileReader::openFile() Opening data file = " << fullname << std::endl; } if (sin->fail()) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "FileReader::openFile(): Failed to open data file: " << fullname << std::endl; } tOpened = false; tFailed = true; } } delete[] fullname; } fileOpened = tOpened; fileFailed = tFailed; return fileOpened; }
extern void openTagFile (void) { setDefaultTagFileName (); TagsToStdout = isDestinationStdout (); if (TagFile.vLine == NULL) TagFile.vLine = vStringNew (); /* Open the tags file. */ if (TagsToStdout) TagFile.fp = tempFile ("w", &TagFile.name); else { boolean fileExists; setDefaultTagFileName (); TagFile.name = eStrdup (Option.tagFileName); fileExists = doesFileExist (TagFile.name); if (fileExists && /*! isTagFile (TagFile.name)*/ 0) /* allways override old files */ error (FATAL, "\"%s\" doesn't look like a tag file; I refuse to overwrite it.", TagFile.name); if (Option.etags) { if (Option.append && fileExists) TagFile.fp = fopen (TagFile.name, "a+b"); else TagFile.fp = fopen (TagFile.name, "w+b"); } else { if (Option.append && fileExists) { TagFile.fp = fopen (TagFile.name, "r+"); if (TagFile.fp != NULL) { TagFile.numTags.prev = updatePseudoTags (TagFile.fp); fclose (TagFile.fp); TagFile.fp = fopen (TagFile.name, "a+"); } } else { TagFile.fp = fopen (TagFile.name, "w"); /* if (TagFile.fp != NULL) addPseudoTags ();*/ } } if (TagFile.fp == NULL) { error (FATAL | PERROR, "cannot open tag file"); exit (1); } } if (TagsToStdout) TagFile.directory = eStrdup (CurrentDirectory); else { if(TagFile.directory){ free(TagFile.directory); } TagFile.directory = absoluteDirname (TagFile.name); } }
int main(int argc, char *argv[]) { int sockfd, newsockfd, portno = 51717, clilen; char buffer[256]; struct sockaddr_in serv_addr, cli_addr; int n; int data; FILE *fp; portno = atoi(argv[1]); printf( "using port #%d\n", portno ); sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error( const_cast<char *>("ERROR opening socket") ); bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons( portno ); if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error( const_cast<char *>( "ERROR on binding" ) ); listen(sockfd,5); clilen = sizeof(cli_addr); //--- infinite wait on a connection --- while ( 1 ) { printf( "waiting for new client...\n" ); if ( ( newsockfd = accept( sockfd, (struct sockaddr *) &cli_addr, (socklen_t*) &clilen) ) < 0 ) error( const_cast<char *>("ERROR on accept") ); printf( "opened new communication with client\n" ); while ( 1 ) { //---- wait for a number from client --- // data = getData( newsockfd ); // printf( "got %d\n", data ); // if ( data < 0 ) // break; // data = func( data ); //--- send new data back --- // printf( "sending back %d\n", data ); // sendData( newsockfd, data ); int rc = doesFileExist("/echo/alexa.cmd"); if (rc > 0) { fp = fopen("/echo/alexa.cmd", "r"); // strcpy(buffer,"a7 off"); for (int i=0;i<255;i++) buffer[i]=0; printf("Reading file\n"); size_t newLen = fread(buffer, sizeof(char),255 , fp); printf("Read file\n"); if (newLen == 0) { fputs("Error reading file", stderr); } else { buffer[++newLen] = '\0'; /* Just to be safe. */ printf("Got from Alexa %s",buffer); } sendDataStr( newsockfd, buffer ); system("rm /echo/alexa.cmd"); } else { printf("Sleeping"); sleep(1); } } close( newsockfd ); //--- if -2 sent by client, we can quit --- if ( data == -2 ) break; } return 0; }
int main(int argc, char *argv[]) { /*Initialize the catalog locks*/ MT_lock_init(&dataLock); MT_cond_init(&mainCond); MT_cond_init(&writeTCond); MT_cond_init(&readCond); char* file_name_in = 0; char* file_name_out = 0; char separator_sign = ' '; char* parse_string = "xyz"; char* buffer; char printstring[256]; LASReaderH reader = NULL; LASHeaderH header = NULL; LASPointH p = NULL; FILE** files_out = NULL; int len, j; int64_t mortonkey = 0; unsigned int index = 0; int num_files_in = 0, num_files_out = 0, num_files, num_of_entries=0, check = 0, num_read_threads = DEFAULT_NUM_READ_THREADS; int i; pthread_t *writeThreads = NULL; pthread_t *readThreads = NULL; struct readThreadArgs *dataRead = NULL; boolean input_file = FALSE; int64_t global_offset_x = 0; int64_t global_offset_y = 0; double scale_x; double scale_y; if (argc == 1) { usage(); exit(0); } /*Allocate space for input files*/ files_name_in = (char**) malloc(sizeof(char*)*DEFAULT_NUM_INPUT_FILES); for (i = 1; i < argc; i++) { if ( strcmp(argv[i],"-h") == 0 || strcmp(argv[i],"--help") == 0 ) { usage(); exit(0); } else if ( strcmp(argv[i],"-v") == 0 || strcmp(argv[i],"--verbose") == 0 ) { verbose = TRUE; } else if ( strcmp(argv[i],"--num_read_threads") == 0) { num_read_threads = atoi(argv[++i]); } else if ( strcmp(argv[i],"-s") == 0 || strcmp(argv[i],"--skip_invalid") == 0 ) { skip_invalid = TRUE; } else if ( strcmp(argv[i], "--parse") == 0 || strcmp(argv[i], "-parse") == 0 ) { i++; parse_string = argv[i]; } else if ( strcmp(argv[i], "--moffset") == 0 || strcmp(argv[i], "-moffset") == 0 ) { i++; buffer = strtok (argv[i], ","); j = 0; while (buffer) { if (j == 0) { global_offset_x = S64(buffer); } else if (j == 1) { global_offset_y = S64(buffer); } j++; buffer = strtok (NULL, ","); while (buffer && *buffer == '\040') buffer++; } if (j != 2){ fprintf(stderr, "Only two int64_t are required in moffset option!\n"); exit(1); } } else if ( strcmp(argv[i], "--check") == 0 || strcmp(argv[i], "-check") == 0 ) { i++; check = 1; buffer = strtok (argv[i], ","); j = 0; while (buffer) { if (j == 0) { sscanf(buffer, "%lf", &scale_x); } else if (j == 1) { sscanf(buffer, "%lf", &scale_y); } j++; buffer = strtok (NULL, ","); while (buffer && *buffer == '\040') buffer++; } if (j != 2){ fprintf(stderr, "Only two doubles are required in moffset option!\n"); exit(1); } } else if ( strcmp(argv[i],"--input") == 0 || strcmp(argv[i],"-input") == 0 || strcmp(argv[i],"-i") == 0 || strcmp(argv[i],"-in") == 0 ) { i++; files_name_in[num_files_in++] = argv[i]; if (num_files_in % DEFAULT_NUM_INPUT_FILES) files_name_in = (char**) realloc(files_name_in, (num_files_in*2)*sizeof(char*)); } else if (strcmp(argv[i],"--file") == 0 || strcmp(argv[i],"-file") == 0 || strcmp(argv[i],"-f") == 0 ) { i++; int read; char line_buffer[BUFSIZ]; FILE* in = NULL; in = fopen(argv[i], "r"); if (!in) { fprintf(stderr, "ERROR: the path for file containing the input files is invalid %s\n", argv[i]); exit(1); } while (fgets(line_buffer, sizeof(line_buffer), in)) { line_buffer[strlen(line_buffer)-1]='\0'; files_name_in[num_files_in++] = strdup(line_buffer); if (num_files_in % DEFAULT_NUM_INPUT_FILES) files_name_in = (char**) realloc(files_name_in, (num_files_in*2)*sizeof(char*)); } fclose(in); input_file = TRUE; } else if ((num_files_in != 0) && num_files_out == 0) { file_name_out = argv[i]; num_files_out++; } else { fprintf(stderr, "ERROR: unknown argument '%s'\n",argv[i]); usage(); exit(1); } } /* end looping through argc/argv */ num_of_entries = strlen(parse_string); if (num_files_in == 0) { LASError_Print("No input filename was specified"); usage(); exit(1); } num_files = num_files_in; /*Entries metadata*/ i = 0; for (;;) { switch (parse_string[i]) { /* // the morton code on xy */ case 'k': entries[i] = ENTRY_k; entriesType[i] = sizeof(int64_t); /*Changes for Oscar's new Morton code function*/ //entriesFunc[i] = (void*)morton2D_encode; entriesFunc[i] = (void*)morton2D_encodeOscar; break; /* // the x coordinate double*/ case 'x': entries[i] = ENTRY_x; entriesType[i] = sizeof(double); entriesFunc[i] = (void*)LASPoint_GetX; break; /* // the y coordinate double*/ case 'y': entries[i] = ENTRY_y; entriesType[i] = sizeof(double); entriesFunc[i] = (void*)LASPoint_GetY; break; /* // the z coordinate double*/ case 'z': entries[i] = ENTRY_z; entriesType[i] = sizeof(double); entriesFunc[i] = (void*)LASPoint_GetZ; break; /* // the X coordinate decimal*/ case 'X': entries[i] = ENTRY_X; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASPoint_GetX; break; /* // the y coordinate decimal*/ case 'Y': entries[i] = ENTRY_Y; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASPoint_GetY; break; /* // the z coordinate decimal*/ case 'Z': entries[i] = ENTRY_Z; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASPoint_GetZ; break; /* // the gps-time */ case 't': entries[i] = ENTRY_t; entriesType[i] = sizeof(double); entriesFunc[i] = (void*)LASPoint_GetTime; break; /* // the intensity */ case 'i': entries[i] = ENTRY_i; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASPoint_GetIntensity; break; /* the scan angle */ case 'a': entries[i] = ENTRY_a; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASPoint_GetScanAngleRank; break; /* the number of the return */ case 'r': entries[i] = ENTRY_r; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASPoint_GetReturnNumber; break; /* the classification */ case 'c': entries[i] = ENTRY_c; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASPoint_GetClassification; break; /* the user data */ case 'u': entries[i] = ENTRY_u; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASPoint_GetUserData; break; /* the number of returns of given pulse */ case 'n': entries[i] = ENTRY_n; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASPoint_GetNumberOfReturns; break; /* the red channel color */ case 'R': entries[i] = ENTRY_R; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASColor_GetRed; break; /* the green channel color */ case 'G': entries[i] = ENTRY_G; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASColor_GetGreen; break; /* the blue channel color */ case 'B': entries[i] = ENTRY_B; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASColor_GetBlue; break; case 'M': entries[i] = ENTRY_M; entriesType[i] = sizeof(unsigned int); break; case 'p': entries[i] = ENTRY_p; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASPoint_GetPointSourceId; break; /* the edge of flight line flag */ case 'e': entries[i] = ENTRY_e; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASPoint_GetFlightLineEdge; break; /* the direction of scan flag */ case 'd': entries[i] = ENTRY_d; entriesType[i] = sizeof(int); entriesFunc[i] = (void*)LASPoint_GetScanDirection; break; } i++; if (parse_string[i] == 0) { break; } } /*Prepare the output files*/ if (file_name_out == NULL) { len = (int)strlen(file_name_in); file_name_out = LASCopyString(file_name_in); if (file_name_out[len-3] == '.' && file_name_out[len-2] == 'g' && file_name_out[len-1] == 'z') { len = len - 4; } while (len > 0 && file_name_out[len] != '.') { len--; } file_name_out[len] = '\0'; } char *str = malloc(sizeof(char)*(strlen(file_name_out)+12)); files_out = (FILE**) malloc(sizeof(FILE*)*num_of_entries); for (i = 0; i < num_of_entries; i++) { sprintf(str, "%s_col_%c.dat", file_name_out, parse_string[i]); if(doesFileExist(str)) { remove(str); } files_out[i] = fopen(str, "wb"); if (files_out[i] == 0) { LASError_Print("Could not open file for write"); usage(); exit(1); } } free(str); /*Initialize structures for the reading threads*/ //data = (struct writeT**) malloc(num_read_threads*sizeof(struct writeT*)); //Malloc is more efficient than calloc data = (struct writeT**) calloc(num_read_threads, sizeof(struct writeT*)); dataRead = (struct readThreadArgs*) malloc(sizeof(struct readThreadArgs)*num_read_threads); /* Launch read Threads */ stop = 0; readThreads = (pthread_t*) malloc(sizeof(pthread_t)*num_read_threads); for (i=0; i < num_read_threads; i++) { dataRead[i].id = i; dataRead[i].num_read_threads = num_read_threads; dataRead[i].num_of_entries = num_of_entries; dataRead[i].check = check; dataRead[i].global_offset_x = global_offset_x; dataRead[i].global_offset_y = global_offset_y; dataRead[i].scale_x = scale_x; dataRead[i].scale_y = scale_y; pthread_create(&readThreads[i], NULL, readFile, (void*)dataRead); } int writeIndex = 0; writeThreads = (pthread_t*) malloc(sizeof(pthread_t)*num_of_entries); /* Launch Threads */ struct writeThreadArgs *dataWrite = (struct writeThreadArgs *) malloc(sizeof(struct writeThreadArgs) *num_of_entries); for (i = 0; i < num_of_entries; i++) { dataWrite[i].id = i; dataWrite[i].out = files_out[i]; pthread_create(&writeThreads[i], NULL, writeFile, (void*)(&dataWrite[i])); } sleep(1); //Do we need to comment this one out!? int done = 0; while (num_files) { /*Obtain lock over data to get the pointer*/ MT_set_lock(&dataLock); dataWriteT = data[writeIndex]; while (dataWriteT == NULL) { /*Sleep and wait for data to be read*/ MT_cond_wait(&mainCond,&dataLock); dataWriteT = data[writeIndex]; } data[writeIndex] = NULL; //Release the lock /*Tell the write threads there is new data*/ pthread_cond_broadcast(&writeTCond); /*Tell the read threads there is a new buf empty*/ pthread_cond_broadcast(&readCond); MT_unset_lock(&dataLock); /*Keep looping*/ writeIndex++; writeIndex = (writeIndex % num_read_threads); MT_set_lock(&dataLock); while (done == 0) { /*Sleep and wait for data to be read*/ MT_cond_wait(&mainCond,&dataLock); done = 1; for (i = 0; i < num_of_entries; i++) { if (dataWriteT[i].values != NULL) { done = 0; break; } } } num_files--; if (verbose) printf("Files to go %d\n", num_files); free(dataWriteT); dataWriteT = NULL; done = 0; MT_unset_lock(&dataLock); } /*Tell the write threads to exit*/ MT_set_lock(&dataLock); stop = 1; pthread_cond_broadcast(&writeTCond); MT_unset_lock(&dataLock); /* Wait for Threads to Finish */ for (i=0; i<num_of_entries; i++) { pthread_join(writeThreads[i], NULL); } free(dataWrite); free(writeThreads); MT_cond_destroy(&readCond); MT_cond_destroy(&writeTCond); MT_cond_destroy(&mainCond); MT_lock_destroy(&dataLock); for (i = 0; i < num_of_entries; i++) { fflush(files_out[i]); if (verbose) printf("close file %d\n", i); fsync(files_out[i]); fclose(files_out[i]); } free(files_out); if (input_file) { for (i=0 ; i < num_files_in; i++) free(files_name_in[i]); free(files_name_in); } free(dataRead); if (readThreads) free(readThreads); return 0; }
//------------------------------------------------------------------------------ // Open the data file //------------------------------------------------------------------------------ bool PrintHandler::openFile() { // When we're already open, just return if (isOpen()) return true; // If we don't have a file name then we're using the standard output if (filename == 0 || filename->len() == 0) return true; // clear the old 'full' file name setFullFilename(0); // local flags (default is success) bool tOpened = true; bool tFailed = false; //--- // Allocate space for the full file name //--- size_t nameLength = 0; if (pathname != 0) { nameLength += pathname->len(); // add the length of the path name nameLength += 1; // add a character for the slash } nameLength += filename->len(); // add the length of the file name nameLength += 4; // add characters for possible version number, "_V99" nameLength += 1; // Add one for the null(0) at the end of the string char* fullname = new char[nameLength]; fullname[0] = '\0'; //--- // Create the (initial) full file name //--- if (pathname != 0 && pathname->len() > 0) { lcStrcat(fullname, nameLength ,*pathname); lcStrcat(fullname, nameLength, "/"); } lcStrcat(fullname,nameLength,*filename); //--- // Make sure that it doesn't already exist (we don't want to over write good data). //--- bool validName = !doesFileExist(fullname); if ( !validName ) { // If the file already exists, try appending a version number "v99" .. char* origname = new char[nameLength]; lcStrcpy(origname, nameLength, fullname); validName = false; for (unsigned int i = 1; i <= 99 && !validName; i++) { std::sprintf(fullname, "%s_v%02d", origname, i); validName = !doesFileExist(fullname); } if ( !validName ) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "PrintHandler::openFile(): All version of the data file already exists: " << origname << std::endl; } tOpened = false; tFailed = true; } delete[] origname; } //--- // When we have a valid file name ... //--- if ( validName ) { // The file name with the path and version number setFullFilename(fullname); //--- // Make sure we have an output stream //--- if (sout == 0) sout = new std::ofstream(); //--- // Open the file //--- sout->open(fullname, std::ios_base::out); if (isMessageEnabled(MSG_INFO)) { std::cout << "PrintHandler::openFile() Opening data file = " << fullname << std::endl; } if (sout->fail()) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "PrintHandler::openFile(): Failed to open data file: " << fullname << std::endl; } tOpened = false; tFailed = true; } } delete[] fullname; fileOpened = tOpened; fileFailed = tFailed; return fileOpened; }
int main(int argc, char *argv[]) { int opt; endianness_t endianness = SET_BIG_ENDIAN; int prompt_to_overwrite = 1; while ((opt = getopt(argc, argv, "ef")) != -1) { switch (opt) { case 'e': endianness = SET_LITTLE_ENDIAN; break; case 'f': prompt_to_overwrite = 0; break; } } DEBUG_PRINTF("argc=%d, optind=%d\n", argc, optind); if (argc - optind < 3) { printf("Usage: %s [-ef] set1 set2 ... output\n", argv[0]); printf(" -e\tTreat SET files as little-endian\n"); printf(" -f\tOverwrite files without prompting\n"); return EXIT_SYNTAX; } int num_files = argc - 1 - optind; uint32_t *object_counts = malloc(4 * num_files); uint32_t total_objects = 0; SETEntry **data = malloc(sizeof(SETEntry*) * num_files); int i; for (i=0; i<num_files; i++) { // loop through the input filenames const char *filename = argv[i+optind]; DEBUG_PRINTF("Input file: %s\n", filename); FILE *fp = fopen(filename, "rb"); if (!fp) { printf("Error reading file %s\n", filename); perror(argv[0]); return EXIT_ERROR; } uint32_t num_objects = readSETHeader(fp, endianness); object_counts[i] = num_objects; total_objects += num_objects; data[i] = malloc(sizeof(SETEntry) * num_objects); if (data[i] == NULL) { printf("Not enough memory! Are you sure those are all SET files?\n"); printf("(Make sure you have the endianness correct, and use -e if necessary.)\n"); return EXIT_ERROR; } fread(data[i], sizeof(SETEntry), num_objects, fp); if (feof(fp)) { printf("File %s is too short.\n", filename); printf("Are you sure it's a SET file?\n"); return EXIT_ERROR; } fclose(fp); } const char *out_filename = argv[argc-1]; DEBUG_PRINTF("Output file: %s\n", out_filename); if (prompt_to_overwrite) // Don't check whether the file exists if not necessary if (doesFileExist(out_filename)) { printf("Output file %s already exists!\n", out_filename); printf("Do you want to overwrite it? [no]: "); char ch = getchar(); if (ch != 'y' && ch != 'Y') { printf("Aborting. No changes have been made.\n"); return EXIT_ERROR; } } FILE *fp = fopen(out_filename, "wb"); if (!fp) { printf("Error creating file %s\n", out_filename); perror(argv[0]); return EXIT_ERROR; } writeSETHeader(fp, total_objects, endianness); for (i=0; i<num_files; i++) { uint32_t num_objects = object_counts[i]; fwrite(data[i], sizeof(SETEntry), num_objects, fp); } fclose(fp); printf("%d files have been successfully merged into %s.\n", num_files, out_filename); // Let the OS take care of freeing the memory. return EXIT_SUCCESS; }
boolean MemoryCard::doesFileExist(String FileName_Str) { return (doesFileExist(FileName_Str.c_str())); }
void* SampleApexResourceCallback::requestResource(const char* nameSpace, const char* pname) { void* resource = 0; bool incrementNumGets = true; PX_ASSERT(nameSpace && *nameSpace); PX_ASSERT(pname && *pname); #if DEBUG_RESOURCE_REQUESTS fprintf(gDebugOutput, "new - %s\n", pname); #endif #if WORK_AROUND_BROKEN_ASSET_PATHS // look for goofy "::" characters... const char* p = pname; while (*p && *p != ':') { p++; } if (*p == ':') { PX_ASSERT(!"Obsolete asset name format, fix your assets!"); return NULL; } #endif if (!strcmp(nameSpace, APEX_MATERIALS_NAME_SPACE)) { SampleFramework::SampleAsset* asset = findSampleAsset(pname, SampleFramework::SampleAsset::ASSET_MATERIAL); if (asset) { resource = asset; } } else if (!strcmp(nameSpace, APEX_CUSTOM_VB_NAME_SPACE)) { // We currently don't support any custom vertex semantics in the samples, // so the resource will simply be a copy the name. A real game engine // could return a pointer to whatever they want, or a member of an enum of // custom semantics. Whatever resources are returned here will be provided // in the Render Resources API, in the array: // void ** UserRenderVertexBufferDesc::customBuffersIdents size_t len = strlen(pname); char* n = new char[len + 1]; physx::shdfnd::strlcpy(n, len + 1, pname); resource = (void*)(n); } else if (!strcmp(nameSpace, APEX_COLLISION_GROUP_NAME_SPACE)) { PX_ASSERT(0 && "NRP seed failure for" APEX_COLLISION_GROUP_NAME_SPACE); } else if (!strcmp(nameSpace, APEX_COLLISION_GROUP_MASK_NAME_SPACE)) { PX_ASSERT(0 && "NRP seed failure for " APEX_COLLISION_GROUP_MASK_NAME_SPACE); } else if (!strcmp(nameSpace, APEX_COLLISION_GROUP_128_NAME_SPACE)) { // Note: When using effects that were authored in the ParticleEffectTool the // collision group names are defined by an artist/designer and it is up to the application // to translate that name into a viable set of collision group flags. The algorithm for // how to translate these named fields to a set of bit fields is application specific. // Within the context of the sample framework, we must simply return 'some' valid result. // The previous behavior of this code is that it required that all named collision groups // be predefined ahead of time. However, within the context of using assets authored by // the ParticleEffectTool this is on longer the case. These values are considered 'globals' // within the context of the APEX SDK and do not get specific release calls performed on them. // For this reason the 'number of gets' counter should not be incredmented. incrementNumGets = false; const char *equal = strchr(pname,'='); // if it uses the ASCII encoded filter bits format... if ( equal ) { physx::PxFilterData *fdata = (physx::PxFilterData *)m_FilterBits->getEncodedFilterData(pname); resource = fdata; } else { static physx::PxFilterData filterData; resource = &filterData; memset(resource,0xFF,sizeof(filterData)); } } else if (!strcmp(nameSpace, APEX_COLLISION_GROUP_64_NAME_SPACE)) { incrementNumGets = false; static uint64_t collisionGroup; resource = &collisionGroup; memset(resource,0xFF,sizeof(collisionGroup)); // PX_ASSERT(0 && "NRP seed failure for " APEX_COLLISION_GROUP_64_NAME_SPACE); } else if (!strcmp(nameSpace, APEX_PHYSICS_MATERIAL_NAME_SPACE)) { PX_ASSERT(0 && "NRP seed failure for " APEX_PHYSICS_MATERIAL_NAME_SPACE); } else { #if APEX_USE_PARTICLES if ( mModuleParticles ) // If we are using the Particles module { // See if this data for this resource was preloaded into the particles module. NvParameterized::Interface *iface = mModuleParticles->locateResource(pname,nameSpace); if ( iface ) { NvParameterized::Interface *copyInterface=NULL; iface->clone(copyInterface); // Create a copy of the parameterize data. PX_ASSERT(copyInterface); if ( copyInterface ) { nvidia::apex::Asset *asset = m_apexSDK->createAsset(copyInterface,pname); // Create the asset using this NvParameterized::Inteface data PX_ASSERT(asset); resource = asset; // return this resource that we just created if ( asset == NULL ) { // If it failed to create the asset; destroy the interface data. copyInterface->destroy(); } } } } #endif if ( resource == NULL ) { nvidia::apex::Asset* asset = 0; if ( #if PX_PHYSICS_VERSION_MAJOR == 3 #if APEX_USE_PARTICLES !strcmp(nameSpace, EMITTER_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, GROUND_EMITTER_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, IMPACT_EMITTER_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, PARTICLE_IOS_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, FORCEFIELD_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, IOFX_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, BASIC_IOS_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, JET_FS_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, ATTRACTOR_FS_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, NOISE_FS_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, VORTEX_FS_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, WIND_FS_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, TURBULENCE_FS_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, VELOCITY_SOURCE_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, HEAT_SOURCE_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, SUBSTANCE_SOURCE_AUTHORING_TYPE_NAME) || #endif // APEX_USE_PARTICLES !strcmp(nameSpace, DESTRUCTIBLE_AUTHORING_TYPE_NAME) || !strcmp(nameSpace, RENDER_MESH_AUTHORING_TYPE_NAME) || #endif !strcmp(nameSpace, CLOTHING_AUTHORING_TYPE_NAME) ) { // Assets that are using NvParameterized (and serialized outside of APEX) // currently have an XML extension. PX_ASSERT(pname); physx::PxFileBuf* stream = 0; const char* ext = getFileExtension(pname); if (ext) { stream = findApexAsset(pname); } else { if (XML_ASSET == m_assetPreference) { if (doesFileExist(pname, ".apx")) { ext = ".apx"; } if (!ext && doesFileExist(pname, ".apb")) { ext = ".apb"; } } else if (BIN_ASSET == m_assetPreference) { if (!ext && doesFileExist(pname, ".apb")) { ext = ".apb"; } if (!ext && doesFileExist(pname, ".apx")) { ext = ".apx"; } } else { // We prefer binary files in shipping builds if (!ext && doesFileExist(pname, ".apx")) { ext = ".apx"; } if (!ext && doesFileExist(pname, ".apb")) { ext = ".apb"; } } PX_ASSERT(ext); if (ext) { char fullname[512] = {0}; physx::shdfnd::strlcpy(fullname, sizeof(fullname), pname); physx::shdfnd::strlcat(fullname, sizeof(fullname), ext); stream = findApexAsset(fullname); } } if (stream) { // we really shouldn't have extensions in our asset names, and apps should // determine the serialization type using this ApesSDK::getSerializeType() method NvParameterized::Serializer::SerializeType serType = m_apexSDK->getSerializeType(*stream); if (ext) { NvParameterized::Serializer::SerializeType iSerType; if (0 == strcmp(".apx", ext)) { iSerType = NvParameterized::Serializer::NST_XML; } else if (0 == strcmp(".apb", ext)) { iSerType = NvParameterized::Serializer::NST_BINARY; } else { iSerType = NvParameterized::Serializer::NST_LAST; PX_ASSERT(0 && "Invalid asset file extension"); } // PH: If you end up here, you have a binary file with an xml extension (.apx or .xml) or vice versa PX_ASSERT(iSerType == serType && "Wrong file extension??"); PX_UNUSED(iSerType); } NvParameterized::Serializer::ErrorType serError; NvParameterized::SerializePlatform platform; serError = m_apexSDK->getSerializePlatform(*stream, platform); PX_ASSERT(serError == NvParameterized::Serializer::ERROR_NONE); NvParameterized::Serializer* ser = m_apexSDK->createSerializer(serType); PX_ASSERT(ser); if (NULL==ser) { if (m_renderer.getErrorCallback()) { // emit a "missing asset" warning using output error stream char msg[1024]; physx::shdfnd::snprintf(msg, sizeof(msg), "Error creating the serializer for asset <%s> in namespace <%s>", pname, nameSpace); m_renderer.getErrorCallback()->reportError(physx::PxErrorCode::eDEBUG_WARNING, msg, __FILE__, __LINE__); } if (stream) { stream->release(); stream = NULL; } return NULL; } NvParameterized::Serializer::DeserializedData data; NvParameterized::SerializePlatform currentPlatform; m_apexSDK->getCurrentPlatform(currentPlatform); NvParameterized::Traits* t = m_apexSDK->getParameterizedTraits(); uint32_t len = stream->getFileLength(); if (NvParameterized::Serializer::NST_BINARY == serType && INPLACE_BINARY && platform == currentPlatform) { void* p = t->alloc(len); stream->read(p, len); serError = ser->deserializeInplace(p, len, data); } else if (NvParameterized::Serializer::NST_BINARY == serType) { // If the asset is binary but not inplace, read it into a memory buffer (MUCH faster with PS3 dev env). // We could do this with XML files as well, but if there's a huge XML asset the consoles may fail on // the allocation. void* p = t->alloc(len); stream->read(p, len); physx::PxFileBuf* memStream = m_apexSDK->createMemoryReadStream(p, len); serError = ser->deserialize(*memStream, data); m_apexSDK->releaseMemoryReadStream(*memStream); t->free(p); } else { serError = ser->deserialize(*stream, data); } if (serError == NvParameterized::Serializer::ERROR_NONE && data.size() == 1) { NvParameterized::Interface* params = data[0]; asset = m_apexSDK->createAsset(params, pname); PX_ASSERT(asset && "ERROR Creating NvParameterized Asset"); } else { PX_ASSERT(0 && "ERROR Deserializing NvParameterized Asset"); } stream->release(); ser->release(); } } PX_ASSERT(asset); if (asset) { bool rightType = strcmp(nameSpace, asset->getObjTypeName()) == 0; PX_ASSERT(rightType); if (rightType) { resource = asset; } else { m_apexSDK->releaseAsset(*asset); asset = 0; } } } } if (resource ) { if ( incrementNumGets ) { m_numGets++; } } else if (m_renderer.getErrorCallback()) { // emit a "missing asset" warning using output error stream char msg[1024]; physx::shdfnd::snprintf(msg, sizeof(msg), "Could not find asset <%s> in namespace <%s>", pname, nameSpace); m_renderer.getErrorCallback()->reportError(physx::PxErrorCode::eDEBUG_WARNING, msg, __FILE__, __LINE__); } return resource; }
void Config::loadSkinConfig() { if (doesFileExist(charenc("csgo//cfg//cheetos//skinconfig.ini"))) { configManager.initialize(charenc("skinconfig.ini")); for (int i = 1; i <= 65; i++) { if (!WeaponConfig::isPistol(i) && !WeaponConfig::isAutomatic(i) && !WeaponConfig::isSniper(i) && !WeaponConfig::isShotgun(i) && !WeaponConfig::isKnife(i)) continue; char weaponName[32]; switch (i) { case WEAPON_DEAGLE: { strcpy(weaponName, charenc("DEAGLE")); break; } case WEAPON_DUALS: { strcpy(weaponName, charenc("DUALIES")); break; } case WEAPON_FIVE7: { strcpy(weaponName, charenc("FIVE-SEVEN")); break; } case WEAPON_GLOCK: { strcpy(weaponName, charenc("GLOCK")); break; } case WEAPON_AK47: { strcpy(weaponName, charenc("AK47")); break; } case WEAPON_AUG: { strcpy(weaponName, charenc("AUG")); break; } case WEAPON_AWP: { strcpy(weaponName, charenc("AWP")); break; } case WEAPON_FAMAS: { strcpy(weaponName, charenc("FAMAS")); break; } case WEAPON_G3SG1: { strcpy(weaponName, charenc("G3SG1")); break; } case WEAPON_GALIL: { strcpy(weaponName, charenc("GALIL")); break; } case WEAPON_M249: { strcpy(weaponName, charenc("M249")); break; } case WEAPON_M4A1: { strcpy(weaponName, charenc("M4A1")); break; } case WEAPON_MAC10: { strcpy(weaponName, charenc("MAC-10")); break; } case WEAPON_P90: { strcpy(weaponName, charenc("P90")); break; } case WEAPON_UMP45: { strcpy(weaponName, charenc("UMP-45")); break; } case WEAPON_XM1014: { strcpy(weaponName, charenc("XM1014")); break; } case WEAPON_BIZON: { strcpy(weaponName, charenc("BIZON")); break; } case WEAPON_MAG7: { strcpy(weaponName, charenc("MAG-7")); break; } case WEAPON_NEGEV: { strcpy(weaponName, charenc("NEGEV")); break; } case WEAPON_SAWEDOFF: { strcpy(weaponName, charenc("SAWED-OFF")); break; } case WEAPON_TEC9: { strcpy(weaponName, charenc("TEC-9")); break; } case WEAPON_TASER: { strcpy(weaponName, charenc("ZEUS")); break; } case WEAPON_P2000: { strcpy(weaponName, charenc("P2000")); break; } case WEAPON_MP7: { strcpy(weaponName, charenc("MP7")); break; } case WEAPON_MP9: { strcpy(weaponName, charenc("MP9")); break; } case WEAPON_NOVA: { strcpy(weaponName, charenc("NOVA")); break; } case WEAPON_P250: { strcpy(weaponName, charenc("P250")); break; } case WEAPON_SCAR20: { strcpy(weaponName, charenc("SCAR-20")); break; } case WEAPON_SG553: { strcpy(weaponName, charenc("SG553")); break; } case WEAPON_SCOUT: { strcpy(weaponName, charenc("SCOUT")); break; } case WEAPON_REVOLVER: { strcpy(weaponName, charenc("REVOLVER")); break; } case WEAPON_M4A1S: { strcpy(weaponName, charenc("M4A1-S")); break; } case WEAPON_USPS: { strcpy(weaponName, charenc("USP-S")); break; } case WEAPON_CZ75: { strcpy(weaponName, charenc("CZ-75")); break; } } configManager.getInteger(weaponName, charenc("Skin"), skincfg.at(i).skin); configManager.getInteger(weaponName, charenc("StatTrak"), skincfg.at(i).stattrak); configManager.getInteger(weaponName, charenc("Seed"), skincfg.at(i).seed); configManager.getFloat(weaponName, charenc("Condition"), skincfg.at(i).wear); skincfg.at(i).name = configManager.getString(weaponName, charenc("Name"), skincfg.at(i).name); } for (int i = 500; i <= 516; i++) { if (!WeaponConfig::isPistol(i) && !WeaponConfig::isAutomatic(i) && !WeaponConfig::isSniper(i) && !WeaponConfig::isShotgun(i) && !WeaponConfig::isKnife(i)) continue; char weaponName[32]; switch (i) { case WEAPON_KNIFE_GUT: { strcpy(weaponName, charenc("GUT KNIFE")); break; } case WEAPON_KNIFE_FLIP: { strcpy(weaponName, charenc("FLIP KNIFE")); break; } case WEAPON_KNIFE_BAYONET: { strcpy(weaponName, charenc("BAYONET")); break; } case WEAPON_KNIFE_KARAMBIT: { strcpy(weaponName, charenc("KARAMBIT")); break; } case WEAPON_KNIFE_M9BAYONET: { strcpy(weaponName, charenc("M9 BAYONET")); break; } case WEAPON_KNIFE_BUTTERFLY: { strcpy(weaponName, charenc("BUTTERFLY KNIFE")); break; } case WEAPON_KNIFE_HUNTSMAN: { strcpy(weaponName, charenc("HUNTSMAN KNIFE")); break; } case WEAPON_KNIFE_BOWIE: { strcpy(weaponName, charenc("BOWIE KNIFE")); break; } } configManager.getInteger(weaponName, charenc("Skin"), skincfg.at(i).skin); configManager.getInteger(weaponName, charenc("StatTrak"), skincfg.at(i).stattrak); configManager.getInteger(weaponName, charenc("Seed"), skincfg.at(i).seed); configManager.getFloat(weaponName, charenc("Condition"), skincfg.at(i).wear); skincfg.at(i).name = configManager.getString(weaponName, charenc("Name"), skincfg.at(i).name); } } else { saveSkinConfig(); } }
//----------------------------------------------------------------------------// void MinizipResourceProvider::loadRawDataContainer(const String& filename, RawDataContainer& output, const String& resourceGroup) { const String final_filename = getFinalFilename(filename, resourceGroup); if (d_pimpl->d_loadLocal && doesFileExist(final_filename)) { DefaultResourceProvider::loadRawDataContainer(filename, output, resourceGroup); return; } if (d_pimpl->d_zfile == 0) { throw InvalidRequestException( "'" + final_filename + "' cannot be " "loaded because the archive has not been set"); } #if CEGUI_STRING_CLASS == CEGUI_STRING_CLASS_STD if (unzLocateFile(d_pimpl->d_zfile, final_filename.c_str(), 0) != UNZ_OK) #elif CEGUI_STRING_CLASS == CEGUI_STRING_CLASS_UNICODE if (unzLocateFile(d_pimpl->d_zfile, final_filename.toUtf8String().c_str(), 0) != UNZ_OK) #endif { throw InvalidRequestException("'" + final_filename + "' does not exist"); } unz_file_info file_info; if (unzGetCurrentFileInfo(d_pimpl->d_zfile, &file_info, 0, 0, 0, 0, 0, 0) != UNZ_OK) { throw FileIOException("'" + final_filename + "' error reading file header"); } if (unzOpenCurrentFile(d_pimpl->d_zfile) != Z_OK) { throw FileIOException("'" + final_filename + "' error opening file"); } std::uint64_t size = file_info.uncompressed_size; std::uint8_t* buffer = new std::uint8_t[size]; if (unzReadCurrentFile(d_pimpl->d_zfile, buffer, size) < 0) { throw FileIOException("'" + final_filename + "' error reading file"); } if (unzCloseCurrentFile(d_pimpl->d_zfile) != UNZ_OK) { throw GenericException("'" + final_filename + "' error validating file"); } output.setData(buffer); output.setSize(size); }