void prepareMsiData(int localeId) { String msiFilePath = getTmpPath() + kMsiFileName; // Copy msi file to temp copyFile(IDR_MSI, msiFilePath); // Don't need transform for English (United States) if (localeId != kEnglishLocalId) { String transformFile = createFileName(localeId); String transformFilePath = getTmpPath() + transformFile; // Copy mst file to temp if needed copyFile(localeId, transformFilePath); } }
void runMsi(int localeId) { String msiFilePath = getTmpPath() + kMsiFileName; // Crete parameter string for msiexec std::wstringstream parameter; parameter << "/i \"" << msiFilePath << "\"" << " LanguageChoice=\"" << localeIdToShortLocale(localeId) << "\""; // Don't need transform for English (United States) if (localeId != kEnglishLocalId) { String transformFile = createFileName(localeId); String transformFilePath = getTmpPath() + transformFile; parameter << " transforms=\"" << transformFilePath << "\""; } // Execute msiexec with the parameter from above ShellExecute(NULL, _T("open"), _T("msiexec.exe"), parameter.str().c_str(), NULL, SW_SHOWNORMAL); }
static char * SaveEquationAsFile(char *pre, char *eq, char *post) { FILE * f; char name[15]; char *tmp_dir, *fullname, *texname; static int file_number = 0; /* create needed file names */ file_number++; tmp_dir = getTmpPath(); #ifdef INLINE_EQ_ALIGN if(g_inline_eq_align&&!strcmp(pre,"$")) sprintf(name, "l2r-%04d", file_number); else #endif sprintf(name, "l2r_%04d", file_number); fullname = strdup_together(tmp_dir, name); texname = strdup_together(fullname,".tex"); diagnostics(4, "SaveEquationAsFile =%s", texname); f = fopen(texname,"w"); while (eq && (*eq == '\n' || *eq == ' ')) eq++; /* skip whitespace */ if (f) { fprintf(f, "%s", g_preamble); fprintf(f, "\\thispagestyle{empty}\n"); fprintf(f, "\\begin{document}\n"); fprintf(f, "\\setcounter{equation}{%d}\n",getCounter("equation")); if (strstr(pre, "equation")) fprintf(f, "$$%s$$", eq); #ifdef INLINE_EQ_ALIGN else if(g_inline_eq_align&&!strcmp(pre,"$")) fprintf(f, "%s.\\quad %s%s", pre, eq, post); #endif else fprintf(f, "%s%s%s", pre, eq, post); fprintf(f, "\n\\end{document}"); fclose(f); } else { free(fullname); fullname = NULL; } free(tmp_dir); free(texname); return(fullname); }
static char * strdup_tmp_path(char *s) /****************************************************************************** purpose : create a tmp file name using only the end of the filename ******************************************************************************/ { char *tmp, *p, *fullname, c; if (s==NULL) return NULL; tmp = getTmpPath(); c = PATHSEP; p=strrchr(s,c); if (!p) fullname = strdup_together(tmp,s); else fullname = strdup_together(tmp,p+1); free(tmp); return fullname; }
/////////////////////////////////////////////////////////////////////////////// /// main routine of the demo code /// ///\param argc Number of arguments ///\param argv Arguments ///\return 0 if no error occurred /////////////////////////////////////////////////////////////////////////////// int main(int argc, char *argv[]) { const char* fmuFilNam; char* fmuPat; char* tmpPat; char* xmlPat; char* dllPat; // define default argument values double tEnd = 1.0; double h=0.1; int loggingOn = 0; char csv_separator = ','; // parse command line arguments if (argc>1) { fmuFilNam = argv[1]; if(!strcmp(fmuFilNam, "-h") | !strcmp(fmuFilNam, "--help")) { printHelp(argv[0]); return 0; } /*if(!strstr(fmuFilNam,"DoubleInputDoubleOutput.fmu")) { printf("Sorry, this demo only works with the FMU file DoubleInputDoubleOutput.fmu"); return 0; }*/ } else { printError("No fmu file.\n"); printHelp(argv[0]); exit(EXIT_FAILURE); } if (argc>2) { if (sscanf(argv[2],"%lf", &tEnd) != 1) { printfError("The given end time (%s) is not a number.\n", argv[2]); exit(EXIT_FAILURE); } } if (argc>3) { if (sscanf(argv[3],"%lf", &h) != 1) { printfError("The given stepsize (%s) is not a number.\n", argv[3]); exit(EXIT_FAILURE); } } if (argc>4) { if (sscanf(argv[4],"%d", &loggingOn) != 1 || loggingOn<0 || loggingOn>1) { printfError("The given logging flag (%s) is not boolean.\n", argv[4]); exit(EXIT_FAILURE); } if(loggingOn) setDebug(); } if (argc>5) { if (strlen(argv[5]) != 1) { printfError("The given CSV separator char (%s) is not valid.\n", argv[5]); exit(EXIT_FAILURE); } csv_separator = argv[5][0]; } if (argc>6) { printf("warning: Ignoring %d additional arguments: %s ...\n", argc-6, argv[6]); printHelp(argv[0]); } // Get absolute path to FMU, NULL if not found tmpPat = getTmpPath(fmuFilNam, strlen(fmuFilNam)-4); if(tmpPat==NULL){ printError("Cannot allocate temporary path.\n"); exit(EXIT_FAILURE); } // Unzip the FMU to the tmpPat directory if (unpack(fmuFilNam, tmpPat)) { printfError("Fail to unpack fmu \"%s\".\n", fmuFilNam); exit(EXIT_FAILURE); } printDebug("parse tmpPat\\modelDescription.xml.\n"); xmlPat = calloc(sizeof(char), strlen(tmpPat) + strlen(XML_FILE) + 1); sprintf(xmlPat, "%s%s", tmpPat, XML_FILE); // Parse only parses the model description and store in structure fmu.modelDescription fmu.modelDescription = parse(xmlPat); free(xmlPat); if (!fmu.modelDescription) exit(EXIT_FAILURE); // Allocate the memory for dllPat dllPat = calloc(sizeof(char), strlen(tmpPat) + strlen(DLL_DIR) + strlen( getModelIdentifier(fmu.modelDescription)) + strlen(".dll") + 1); sprintf(dllPat,"%s%s%s.dll", tmpPat, DLL_DIR, getModelIdentifier(fmu.modelDescription)); // Load the FMU dll if (loadDll(dllPat, &fmu)) exit(EXIT_FAILURE); printfDebug("Loaded \"%s\"\n", dllPat); free(dllPat); free(tmpPat); // Run the simulation printf("FMU Simulator: run '%s' from t=0..%g with step size h=%g, loggingOn=%d, csv separator='%c'\n", fmuFilNam, tEnd, h, loggingOn, csv_separator); if (simulate(&fmu, tEnd, h, loggingOn, csv_separator)){ printError("Simulation failed.\n"); exit(EXIT_FAILURE); } printf("CSV file '%s' written", RESULT_FILE); // Release FMU FreeLibrary(fmu.dllHandle); freeElement(fmu.modelDescription); return EXIT_SUCCESS; }
void TikzToPng(char *tikzcode,char *exts) { char *fullname, *tmp_dir, *texname, *auxname, *logname, *pdfname, *pngname, *destname; FILE *f; static int file_number = 0; char name[15]; file_number++; tmp_dir = getTmpPath(); snprintf(name,15,"t2p_%04d",file_number); fullname = strdup_together(tmp_dir,name); texname = strdup_together(fullname,".tex"); pdfname = strdup_together(fullname,".pdf"); auxname = strdup_together(fullname,".aux"); logname = strdup_together(fullname,".log"); f = fopen(texname, "w"); fprintf(f,"\\documentclass[varwidth=true,border=10pt]{standalone}\n"); fprintf(f,"\\usepackage{mathtext}\n"); fprintf(f,"\\usepackage[T2A]{fontenc}\n"); fprintf(f,"\\usepackage[%s]{inputenc}\n",g_charset_encoding_name); fprintf(f,"\\usepackage[russian]{babel}\n"); fprintf(f,"\\usepackage{tikz}\n"); fprintf(f,"\\usepackage{gnuplot-lua-tikz}\n"); fprintf(f,"\\begin{document}\n"); int i; for (i=0;i<tikzlibsnum;i++) { fprintf(f,"\\usetikzlibrary{%s}\n",tikzlibs[i]); } if (exts!=NULL) fprintf(f,"\\begin{tikzpicture}[%s]\n",exts); else fprintf(f,"\\begin{tikzpicture}\n"); fprintf(f,"\n%s\n",tikzcode); fprintf(f,"\\end{tikzpicture}\n"); fprintf(f,"\\end{document}\n"); fclose(f); int cmd_len = strlen("pdflatex") + strlen(texname)+32+strlen(" >/dev/null"); char *cmd = (char *)malloc(cmd_len); snprintf(cmd, cmd_len, "pdflatex %s >/dev/null",texname); char *oldcwd = (char *)malloc(1024); getcwd(oldcwd,1024); chdir(tmp_dir); int err = system(cmd); chdir(oldcwd); free(cmd); if (!err) PutPdfFile(pdfname,g_png_figure_scale,0,TRUE); if (g_figs_extract && g_processing_figure) { struct stat st ={0}; if (stat(g_figsdir, &st) == -1) { mkdir(g_figsdir,0755); } g_fignum++; char *figname = (char *)malloc(15*sizeof(char)); snprintf(figname,15,"Ris%d.png",g_fignum); destname = strdup_together(g_figsdir,"/"); pngname = strdup_together(destname,figname); cmd_len = strlen("convert -alpha off -density 300x300 ")+strlen(destname)+strlen(pdfname)+32; cmd = (char *) malloc(cmd_len); snprintf(cmd,cmd_len,"convert -density 300x300 %s -alpha off %s ",pdfname,pngname); printf(cmd); system(cmd); free(cmd); free(destname); free(pngname); } remove(texname); remove(auxname); remove(pdfname); remove(logname); free(oldcwd); free(fullname); free(texname); free(auxname); free(pdfname); free(logname); free(tmp_dir); }
int main(int argc, char *argv[]) { const char* fmuFileName = 0; char* fmuPath = 0; char* tmpPath = 0; char* xmlPath = 0; char* dllPath = 0; char* cmd = 0; // define default argument values double tEnd = 1.0; double h=0.1; int loggingOn = 0; char csv_separator = ';'; const char* resultFileName = "-"; // parse command line arguments if (argc>1) { fmuFileName = argv[1]; } else { fprintf(stderr,"error: no fmu file\n"); printHelp(argv[0]); exit(EXIT_FAILURE); } if (argc>2) { if (sscanf(argv[2],"%lf", &tEnd) != 1) { fprintf(stderr,"error: The given end time (%s) is not a number\n", argv[2]); exit(EXIT_FAILURE); } } if (argc>3) { if (sscanf(argv[3],"%lf", &h) != 1) { fprintf(stderr,"error: The given stepsize (%s) is not a number\n", argv[3]); exit(EXIT_FAILURE); } } if (argc>4) { if (sscanf(argv[4],"%d", &loggingOn) != 1 || loggingOn<0 || loggingOn>1) { fprintf(stderr,"error: The given logging option (%s) must be 0 or 1\n", argv[4]); exit(EXIT_FAILURE); } } if (argc>5) { if (strlen(argv[5]) != 1) { fprintf(stderr,"error: The given CSV separator char (%s) is not valid\n", argv[5]); exit(EXIT_FAILURE); } csv_separator = argv[5][0]; } if (argc>6) { resultFileName = argv[6]; if(strlen(resultFileName)==0) resultFileName = 0; // no output } if (argc>7) { fprintf(stderr,"warning: Ignoring %d additional arguments: %s ...\n", argc-6, argv[6]); printHelp(argv[0]); } // get absolute path to FMU, NULL if not found fmuPath = getFmuPath(fmuFileName); if (!fmuPath) exit(EXIT_FAILURE); // unzip the FMU to the tmpPath directory tmpPath = getTmpPath(); if (!fmuUnzip(fmuPath, tmpPath)) exit(EXIT_FAILURE); // parse tmpPath\modelDescription.xml xmlPath = calloc(sizeof(char), strlen(tmpPath) + strlen(XML_FILE) + 1); sprintf(xmlPath, "%s%s", tmpPath, XML_FILE); fmu.modelDescription = parse(xmlPath); free(xmlPath); if (!fmu.modelDescription) exit(EXIT_FAILURE); // load the FMU dll dllPath = calloc(sizeof(char), strlen(tmpPath) + strlen(DLL_DIR) + strlen( getModelIdentifier(fmu.modelDescription)) + strlen(DLL_SUFFIX) + 1); sprintf(dllPath,"%s%s%s%s", tmpPath, DLL_DIR, getModelIdentifier(fmu.modelDescription), DLL_SUFFIX); if (!fmuLoadDll(dllPath, &fmu)) exit(EXIT_FAILURE); free(dllPath); free(fmuPath); // run the simulation fprintf(stderr,"FMU Simulator: run '%s' from t=0..%g with step size h=%g, loggingOn=%d, csv separator='%c'\n", fmuFileName, tEnd, h, loggingOn, csv_separator); if(resultFileName) if(strlen(resultFileName)==1 && resultFileName[0]=='-') fprintf(stderr, "Output will be written to standard output\n"); else fprintf(stderr, "Output will be written to file %s\n", resultFileName); else fprintf(stderr, "No output file will be produced\n"); fmuSimulate(&fmu, tEnd, h, loggingOn, csv_separator, resultFileName); #if WINDOWS /* Remove temp file directory? Not tested*/ cmd = calloc(sizeof(char), strlen(tmpPath)+20); sprintf(cmd, "rmdir %s /s /q", tmpPath); fprintf(stderr,"Removing %s\n", tmpPath); system(cmd); free(cmd); #else cmd = calloc(sizeof(char), strlen(tmpPath)+8); sprintf(cmd, "rm -rf %s", tmpPath); fprintf(stderr,"Removing %s\n", tmpPath); system(cmd); free(cmd); #endif free(tmpPath); // release FMU fmuFree(&fmu); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { const char* fmuFileName; char* fmuPath; char* tmpPath; char* xmlPath; char* dllPath; // define default argument values double tEnd = 1.0; double h=0.1; int loggingOn = 0; char csv_separator = ';'; // parse command line arguments if (argc>1) { fmuFileName = argv[1]; } else { printf("error: no fmu file\n"); printHelp(argv[0]); exit(EXIT_FAILURE); } if (argc>2) { if (sscanf(argv[2],"%lf", &tEnd) != 1) { printf("error: The given end time (%s) is not a number\n", argv[2]); exit(EXIT_FAILURE); } } if (argc>3) { if (sscanf(argv[3],"%lf", &h) != 1) { printf("error: The given stepsize (%s) is not a number\n", argv[3]); exit(EXIT_FAILURE); } } if (argc>4) { if (sscanf(argv[4],"%d", &loggingOn) != 1 || loggingOn<0 || loggingOn>1) { printf("error: The given logging flag (%s) is not boolean\n", argv[4]); exit(EXIT_FAILURE); } } if (argc>5) { if (strlen(argv[5]) != 1) { printf("error: The given CSV separator char (%s) is not valid\n", argv[5]); exit(EXIT_FAILURE); } csv_separator = argv[5][0]; } if (argc>6) { printf("warning: Ignoring %d additional arguments: %s ...\n", argc-6, argv[6]); printHelp(argv[0]); } // get absolute path to FMU, NULL if not found fmuPath = getFmuPath(fmuFileName); if (!fmuPath) exit(EXIT_FAILURE); // unzip the FMU to the tmpPath directory tmpPath = getTmpPath(); if (!unzip(fmuPath, tmpPath)) exit(EXIT_FAILURE); // parse tmpPath\modelDescription.xml xmlPath = calloc(sizeof(char), strlen(tmpPath) + strlen(XML_FILE) + 1); sprintf(xmlPath, "%s%s", tmpPath, XML_FILE); fmu.modelDescription = parse(xmlPath); free(xmlPath); if (!fmu.modelDescription) exit(EXIT_FAILURE); // load the FMU dll dllPath = calloc(sizeof(char), strlen(tmpPath) + strlen(DLL_DIR) + strlen( getModelIdentifier(fmu.modelDescription)) + strlen(".dll") + 1); sprintf(dllPath,"%s%s%s.dll", tmpPath, DLL_DIR, getModelIdentifier(fmu.modelDescription)); if (!loadDll(dllPath, &fmu)) exit(EXIT_FAILURE); free(dllPath); free(fmuPath); free(tmpPath); // run the simulation printf("FMU Simulator: run '%s' from t=0..%g with step size h=%g, loggingOn=%d, csv separator='%c'\n", fmuFileName, tEnd, h, loggingOn, csv_separator); simulate(&fmu, tEnd, h, loggingOn, csv_separator); printf("CSV file '%s' written", RESULT_FILE); // release FMU FreeLibrary(fmu.dllHandle); freeElement(fmu.modelDescription); return EXIT_SUCCESS; }
String getMsiProductCode() { String productGuid = kEmptyString; // Copy msi file from resources to the temp folder prepareMsiData(kEnglishLocalId); MSIHANDLE msiHandle; String path = getTmpPath() + kMsiFileName; // Open msi file UINT result = MsiOpenPackageEx(path.c_str(), MSIOPENPACKAGEFLAGS_IGNOREMACHINESTATE, &msiHandle); if (result != ERROR_SUCCESS) { return productGuid; } // Get Product code property string length DWORD length = 0; result = MsiGetProperty(msiHandle, _T("ProductCode"), _T(""), &length); if (ERROR_MORE_DATA != result) { return productGuid; } // Get Product code property // increment length for termination character Char* productCode = new Char[++length]; MsiGetProperty(msiHandle, _T("ProductCode"), productCode, &length); productGuid = productCode; delete[] productCode; // Delete msi file from temp folder, close handles MsiCloseHandle(msiHandle); DeleteFile(path.c_str()); return productGuid; }