/* Finds agup.cfg and add its contents to Allegro's current config. If agup.cfg * is found inside a datafile, the datafile is returned (and loaded if * necessary). */ static DATAFILE * set_theme_config (char const *path, DATAFILE *datafile) { DATAFILE *dat = NULL; if (path) { char *ext = get_extension (path); char str[1024 * 6]; if (!strcmp (ext, "dat")) { dat = load_datafile (path); if (!dat) dat = datafile; } else if (!strcmp (ext, "cfg")) set_config_file (path); else { replace_extension (str, path, "dat", 1024 * 6); dat = load_datafile (str); if (!dat) { replace_extension (str, path, "cfg", 1024 * 6); set_config_file (str); } } } else dat = datafile; if (dat) { override_config_data (dat->dat, dat->size); } return dat; }
void TileRepository::exportBitmap(const char *filename, int tile_w, int tile_h, int tile_spacing, int tiles_in_row) { list<TileType*> tiles_to_save; map<const char*, TileType*, ltstr>::iterator i; list<TileType*>::iterator j; char tempTilename[256]; char tempFilename[256]; replace_extension(tempFilename, get_filename(filename), "", 256); if (!(tiles_in_row > 0 && tile_w > 0 && tile_h > 0)) { allegro_message("WARNING: tiles_in_row (%d), tile_w (%d) and tile_h (%d) must all be larger than 0.", tiles_in_row, tile_w, tile_h); return; } for (i = tileTypes.begin(); i != tileTypes.end(); i++) { TileType* tempTileType = (*i).second; replace_extension(tempTilename, tempTileType->getName(), "", 256); if (ustrcmp(tempFilename, tempTilename) == 0) { tiles_to_save.push_back(tempTileType); } } if (tiles_to_save.empty()) { allegro_message("WARNING: No tiles to save in %s.", filename); return; } BITMAP *tile_bitmap; PALETTE pal; tile_bitmap = create_bitmap ( tiles_in_row * tile_w, (tiles_to_save.size() / tiles_in_row + tiles_to_save.size() % tiles_in_row) * tile_h ); int x = 0; int y = 0; for (j = tiles_to_save.begin(); j != tiles_to_save.end(); j++) { blit((*j)->getBitmap(), tile_bitmap, 0, 0, x * tile_w, y * tile_h, tile_w, tile_h); x++; if (x == tiles_in_row) { y++; x = 0; } } get_palette(pal); save_bitmap(filename, tile_bitmap, pal); destroy_bitmap(tile_bitmap); }
inline int for_each_file(fs::path p, F f) { try { if (fs::exists(p) && fs::is_directory(p)) { for (auto i = fs::directory_iterator(p); i != fs::directory_iterator(); ++i) { auto ext = fs::extension(i->path()); if (ext == ".input") { auto input_path = i->path(); auto expect_path = input_path; expect_path.replace_extension(".expect"); f(input_path, expect_path); } } } else { std::cerr << "Directory: " << fs::absolute(p) << " does not exist." << std::endl; return 1; } } catch (const fs::filesystem_error& ex) { std::cerr << ex.what() << '\n'; return 1; } return 0; }
boost::filesystem::path simulationCaseName( const std::string& casename ) { namespace fs = boost::filesystem; const auto exists = []( const fs::path& f ) -> bool { if( !fs::exists( f ) ) return false; if( fs::is_regular_file( f ) ) return true; return fs::is_symlink( f ) && fs::is_regular_file( fs::read_symlink( f ) ); }; auto simcase = fs::path( casename ); if( exists( simcase ) ) { return simcase; } for( const auto& ext : { std::string("data"), std::string("DATA") } ) { if( exists( simcase.replace_extension( ext ) ) ) { return simcase; } } throw std::invalid_argument( "Cannot find input case " + casename ); }
gchar * get_output_filename (const gchar *in_filename, gchar *out_filename, const gchar *ext) { if (out_filename == NULL) { return replace_extension (in_filename, ext); } else if (g_file_test (out_filename, G_FILE_TEST_IS_DIR)) { gchar *inbase = g_path_get_basename (in_filename); gchar *base = replace_extension (inbase, ext); gchar *of = g_build_filename (out_filename, base, NULL); g_free (base); g_free (inbase); return of; } return out_filename; }
int main(int argc, char *argv[]) { if (argc < 2) { usage(); exit(1); } else if (argc == 2) { int ix = 0; char *in_buffer = alloc(in_buffer_sz); while (fgets(in_buffer, in_buffer_sz, stdin)) { char *nl = strchr(in_buffer, '\n'); if (nl) *nl = 0; replace_extension(ix++, in_buffer, argv[1]); } } else { for (int i = 2; i < argc; ++i) { replace_extension(i - 2, argv[i], argv[1]); } } }
void LogFile::closeFile() { std::stringstream str; str << chila::lib::misc::dateTimeInserter(boost::posix_time::second_clock::local_time()); auto pathToRename = path; pathToRename.replace_extension(str.str() + path.extension().string()); file.close(); boost::filesystem::rename(path, pathToRename); }
RcArchive openResourceDB(int argc, char **argv) { RcArchive rc; char *xfile = NULL; int flags = (GD->bootsession ? RC_WRONLY|RC_CREATE|RC_TRUNC : RC_RDONLY); char tmp[MAXPATHLEN]; int n; if ( !GD->bootsession && (rc = rc_open_archive(GD->paths.executable, flags)) ) return rc; for(n=0; n<argc-1; n++) { if ( argv[n][0] == '-' && argv[n][2] == EOS ) /* -? */ { if ( GD->bootsession ) { if ( argv[n][1] == 'o' ) { xfile = argv[n+1]; break; } } else { if ( argv[n][1] == 'x' ) { xfile = argv[n+1]; break; } } } } if ( xfile ) { if ( !(rc = rc_open_archive(xfile, flags)) ) fatalError("Could not open resource database \"%s\": %s", xfile, OsError()); return rc; } strcpy(tmp, GD->paths.executable); replace_extension(tmp, "prc"); if ( (rc=rc_open_archive(tmp, flags)) ) return rc; if ( systemDefaults.home ) { strcpy(tmp, systemDefaults.home); strcat(tmp, "/"); strcat(tmp, BOOTFILE); return rc_open_archive(tmp, flags); } return NULL; }
void OBJWriter::write(const std::shared_ptr<gameplay::Image>& srcImg, size_t id) const { Expects(srcImg != nullptr); cimg_library::CImg<float> img(glm::value_ptr(srcImg->getData()[0]), 4, srcImg->getWidth(), srcImg->getHeight(), 1); img.permute_axes("yzcx"); img *= 255; auto fullPath = m_basePath / makeTextureName(id); fullPath.replace_extension("png"); img.save_png(fullPath.string().c_str()); }
std::string get_default_rpc_filepath () { boost::system::error_code err; auto running_executable_filepath = boost::dll::program_location (err); // Construct the nano_rpc excutable file path based on where the currently running executable is found. auto rpc_filepath = running_executable_filepath.parent_path () / "nano_rpc"; if (running_executable_filepath.has_extension ()) { rpc_filepath.replace_extension (running_executable_filepath.extension ()); } return rpc_filepath.string (); }
void TileRepository::importBitmap(const char *filename, int tile_w, int tile_h, int tile_spacing) { BITMAP *tileBitmap; BITMAP *tempBitmap; TileType *tempTileType; char tempTilename[256]; char tempFilename[256]; PALETTE pal; int x, y; tileBitmap = load_bitmap(filename, pal); if (!tileBitmap) { allegro_message("Warning, %s is not a valid tile bitmap!\n", filename); return; } set_palette(pal); replace_extension(tempFilename, get_filename(filename), "", 256); ASSERT(tileBitmap); for (y = 0; y < (tileBitmap->h / (tile_h + tile_spacing)); y++) { for (x = 0; x < (tileBitmap->w / (tile_w + tile_spacing)); x++) { // Create a new tile type and add it to the hash_map tempBitmap = create_bitmap(tile_w, tile_h); blit( tileBitmap, tempBitmap, x * (tile_w + tile_spacing), y * (tile_h + tile_spacing), 0, 0, tile_w, tile_h ); sprintf(tempTilename, "%s%03d", tempFilename, y * (tileBitmap->w / tile_w) + x); tempTileType = new TileType(tempBitmap, tempTilename); tileTypes.insert(make_pair(tempTileType->getName(), tempTileType)); } } destroy_bitmap(tileBitmap); }
void ExtensionWindow::MessageReceived(BMessage* message) { switch (message->what) { case kMsgExtensionUpdated: { bool enabled = fExtensionControl->Text() != NULL && fExtensionControl->Text()[0] != '\0'; if (enabled) { // There is some text, but we only accept it, if it // changed the previous extension enabled = strcmp(fExtensionControl->Text(), fExtension.String()); } if (fAcceptButton->IsEnabled() != enabled) fAcceptButton->SetEnabled(enabled); break; } case kMsgAccept: { const char* newExtension = fExtensionControl->Text(); // omit the leading dot if (newExtension[0] == '.') newExtension++; status_t status = replace_extension(fMimeType, newExtension, fExtension.String()); if (status != B_OK) error_alert("Could not change file extensions", status); PostMessage(B_QUIT_REQUESTED); break; } default: BWindow::MessageReceived(message); break; } }
static void RunFragment(const boost::filesystem::path& path) { std::wstring fileNameStr = path.wstring(); const wchar_t* fileName = fileNameStr.c_str(); rage::five::ResourceFlags flags; rage::five::BlockMap* bm = UnwrapRSC7(fileName, &flags); if (!bm) { wprintf(L"couldn't open input file %s...\n", path.filename().c_str()); return; } rage::five::pgStreamManager::SetBlockInfo(bm); auto fragType = (rage::five::fragType*)bm->blocks[0].data; { std::vector<rage::five::rmcDrawable*> drawables; drawables.push_back(fragType->GetPrimaryDrawable()); for (size_t i = 0; i < fragType->GetNumDrawables(); i++) { drawables.push_back(fragType->GetDrawable(i)); } auto physLod = fragType->GetLodGroup()->GetLod(0); for (size_t i = 0; i < physLod->GetNumChildren(); i++) { drawables.push_back(physLod->GetChild(i)->GetDrawable()); auto dr = physLod->GetChild(i)->GetDrawable2(); if (dr) { drawables.push_back(physLod->GetChild(i)->GetDrawable2()); } } for (auto& dr : drawables) { const auto& mp = dr->GetLodGroup().GetMaxPoint(); if (dr->GetLodGroup().GetModel(1) != nullptr) { dr->GetLodGroup().SetModel(1, nullptr); dr->GetLodGroup().SetModel(2, nullptr); } } } auto p2 = path; p2 = p2.replace_extension(".new.yft"); FILE* f = _wfopen(p2.wstring().c_str(), L"wb"); if (!f) { printf("... couldn't open output file for writing.\n"); return; } size_t outputSize = 0; bm->Save(162, [&](const void* d, size_t s) { fwrite(d, 1, s, f); outputSize += s; }, &flags); printf("written successfully - out size %d\n", outputSize); fclose(f); for (int i = 0; i < bm->physicalLen + bm->virtualLen; i++) { delete bm->blocks[i].data; } delete bm; }
/* * Parses the command line, sets the compile options, invokes the * functions and commands necessary to generate the output file. */ int main(int argc, char **argv) { int verbose = 0; /* 1 enables verbosity; 0 disables */ char *arr_size = "30000"; /* Default size of array of cells */ char *asm_filename; /* File name for assembly code */ char *obj_filename; /* File name for object code */ char *exe_filename = "a.out"; /* File name for executable code */ char *command; /* Buffer for command line strings */ size_t i; /* Counter */ size_t len; /* Stores string lengths */ /* Set default compile options */ if ((info.pname = strrchr(argv[0], '/')) == NULL) { info.pname = argv[0]; } else { info.pname++; /* Address of the basename part in argv[0] */ } info.ifilename = NULL; info.ofilename = NULL; info.ostage = LINK; info.arr_size = arr_size; /* Parse command line and set compile options */ for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-s") == 0) { info.arr_size = argv[++i]; } else if (strcmp(argv[i], "-S") == 0 && info.ostage > COMPILE) { info.ostage = COMPILE; } else if (strcmp(argv[i], "-c") == 0 && info.ostage > ASSEMBLE) { info.ostage = ASSEMBLE; } else if (strcmp(argv[i], "-o") == 0) { info.ofilename = argv[++i]; } else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) { verbose = 1; } else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { help(); exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) { version(); exit(EXIT_SUCCESS); } else { info.ifilename = argv[i]; } } /* If input source code file name is not specified, exit */ if (info.ifilename == NULL) { fprintf(stderr, "%s: No input files\n", info.pname); exit(EXIT_FAILURE); } /* * Phase 1: Compile */ /* Determine name for assembly code filename */ if (info.ostage == COMPILE && info.ofilename != NULL) { asm_filename = string(info.ofilename); } else { asm_filename = replace_extension(info.ifilename, "s"); } /* Compile the source file into assembly file */ if (verbose) { printf("Compiling: compile(\"%s\", \"%s\")\n", asm_filename, info.ifilename); } compile(asm_filename, info.ifilename); /* If compile only option was specified, exit */ if (info.ostage == COMPILE) { free(asm_filename); exit(EXIT_SUCCESS); } /* * Phase 2: Assemble */ /* Determine name for object code filename */ if (info.ostage == ASSEMBLE && info.ofilename != NULL) { obj_filename = string(info.ofilename); } else { obj_filename = replace_extension(info.ifilename, "o"); } /* Prepare command line for GNU as */ len = strlen("as -o") + strlen(asm_filename) + strlen(obj_filename) + 2; if ((command = malloc(len)) == NULL) { fprintf(stderr, "%s: Out of memory while assembling", info.pname); } sprintf(command, "as -o %s %s", obj_filename, asm_filename); /* Assemble the assembly code into object code */ if (verbose) { printf("Assembling: %s\n", command); } system(command); free(command); /* Assembly code file is not required after assembling */ unlink(asm_filename); free(asm_filename); /* If compile and assemble only option was specified, exit */ if (info.ostage == ASSEMBLE) { free(obj_filename); exit(EXIT_SUCCESS); } /* * Phase 3: Link */ /* Determine name for executable code filename */ if (info.ostage == LINK && info.ofilename != NULL) { exe_filename = info.ofilename; } /* Prepare command line for GNU ld */ len = strlen("ld -o") + strlen(obj_filename) + strlen(exe_filename) + 2; if ((command = malloc(len)) == NULL) { fprintf(stderr, "%s: Out of memory while compiling", info.pname); } sprintf(command, "ld -o %s %s", exe_filename, obj_filename); /* Link the object code to executable code */ if (verbose) { printf("Linking: %s\n", command); } system(command); free(command); /* Object code file is not required after linking */ unlink(obj_filename); free(obj_filename); exit(EXIT_SUCCESS); }
/* main function */ int main (int argc, char *argv[]) { STREAM *in, *out; char *in_files[MAX_FILES]; char *out_files[MAX_FILES]; int in_nfiles = 0; int out_nfiles = 0; int compile_next = FALSE; int output_next = FALSE; int argument_next = FALSE; int include_next = FALSE; int html_extension_next = FALSE; char *stdout_source = NULL; int quit = -1; char buf[512]; int i, j; /********************************************************************** * Reset variables **********************************************************************/ nargs = 0; _i_stream = NULL; _o_stream = NULL; current_line = NULL; current_col = NULL; ntoken = 0; kill_comments = FALSE; verbose_level = 0; htmlex_name = argv[0]; calculating_deps = FALSE; depstream = NULL; html_extension = "html"; npaths = 0; /********************************************************************** * Preprocess arguments **********************************************************************/ for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { for (j = 1; argv[i][j]; j++) { switch (argv[i][j]) { case 'c': case 'o': case 'a': case 'i': case 'I': case 'E': break; case 'k': kill_comments = TRUE; break; case 'd': calculating_deps = TRUE; break; case 'v': case 'V': verbose_level = (argv[i][j] == 'v')? 1: 2; break; case 'h': quit = 0; break; case '-': break; default: log_printf (0, "in \"%s\", unknown option '%c'\n", argv[i], argv[i][j]); quit = 1; break; } } } } if (quit >= 0) { if (!quit) usage (); else log_printf (0, "try \"htmlex -h\"\n"); exit (quit); } if (verbose_level > 0) log_printf (verbose_level, "verbose level: %d\n", verbose_level); /********************************************************************** * Process arguments **********************************************************************/ log_printf (1, "processing arguments ---\n"); for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { compile_next = FALSE; output_next = FALSE; argument_next = FALSE; include_next = FALSE; html_extension_next = FALSE; for (j = 1; argv[i][j]; j++) { switch (argv[i][j]) { case 'c': compile_next = TRUE; break; case 'o': output_next = TRUE; break; case 'a': argument_next = TRUE; break; case 'i': case 'I': include_next = TRUE; break; case 'E': html_extension_next = TRUE; break; case '-': break; } } } /* new input file */ else if (compile_next) { in_files[in_nfiles++] = argv[i]; log_printf (1, "new input: \"%s\"\n", argv[i]); } /* new output file */ else if (output_next) { out_files[out_nfiles++] = argv[i]; log_printf (1, "new output: \"%s\"\n", argv[i]); } /* new arguments for the input files */ else if (argument_next) { args[nargs++] = argv[i]; log_printf (1, "new argument: \"%s\"\n", argv[i]); } /* new path for inclusion of files */ else if (include_next) { paths[npaths++] = argv[i]; log_printf (1, "new include: \"%s\"\n", argv[i]); } /* new path for inclusion of files */ else if (html_extension_next) { html_extension = argv[i]; log_printf (1, "html extension: \"%s\"\n", argv[i]); } /* default source file to put in STDOUT */ else { stdout_source = argv[i]; argument_next = TRUE; log_printf (1, "main input file: \"%s\"\n", stdout_source); } } log_printf (1, "arguments processed ---\n"); /********************************************************************** * Process STDIN **********************************************************************/ if ((in_nfiles == 0) && (!stdout_source) && (!calculating_deps)) { log_printf (1, "STDIN: compiling\n"); /* open stdin */ in = stfile (stdin); /* get output file */ if (out_nfiles > 0) { log_printf (1, "STDIN: output to %s\n", out_files[0]); out = try_sopen (out_files[0], "w"); if (!out) { log_printf (0, "%s: can't create file\n", out_files[0]); exit (1); } } else { log_printf (1, "STDIN: output to STDOUT\n"); out = stfile (stdout); } prepare_processing (); process_file (in, out); release_processing (); stclose (in); stclose (out); log_printf (1, "STDIN: done\n"); } /********************************************************************** * Process one file (output to STDOUT if there aren't output files) **********************************************************************/ else if (stdout_source) { log_printf (1, "%s: compiling\n", stdout_source); /* open the input file */ in = try_sopen (stdout_source, "r"); if (!in) { log_printf (0, "%s: file not found\n", stdout_source); exit (1); } /* get output file */ if (calculating_deps) { out = NULL; } else { if (out_nfiles > 0) { log_printf (1, "%s: output to %s\n", stdout_source, out_files[0]); out = try_sopen (out_files[0], "w"); if (!out) { log_printf (0, "%s: can't create file\n", out_files[0]); exit (1); } } else { log_printf (1, "%s: output to STDOUT\n", stdout_source, stdout_source); out = stfile (stdout); } } update_state (); add_deps (stdout_source); prepare_processing (); process_file (in, out); release_processing (); stclose (in); stclose (out); out_deps (); } /********************************************************************** * Process all input files (never output to STDOUT) **********************************************************************/ else { for (i=0; i<in_nfiles; i++) { log_printf (1, "%s: compiling\n", in_files[i]); /* open the input file */ in = try_sopen (in_files[i], "r"); if (!in) { log_printf (0, "%s: file not found\n", in_files[i]); exit (1); } /* get an output file name */ if (i < out_nfiles) strcpy (buf, out_files[i]); /* auto generate output file name */ else { if (*html_extension) { char ext[32]; sprintf (ext, ".%s", html_extension); replace_extension (buf, success_path, ext); } else replace_extension (buf, success_path, ""); } log_printf (1, "%s: output to %s\n", in_files[i], buf); if (calculating_deps) { out = NULL; } else { out = try_sopen (buf, "w"); if (!out) { log_printf (0, "%s: can't create file\n", buf); exit (1); } } update_state (); add_deps (buf); add_deps (in_files[i]); prepare_processing (); process_file (in, out); release_processing (); stclose (in); stclose (out); out_deps (); } } log_printf (1, "all done\n"); return 0; }
arg_options *parse_args(int argc, char **argv) { if (argc >= 2 && arg_matches(argv[1], "--help", "-h")) { print_usage(0); } arg_options *args = (arg_options*) malloc(sizeof(arg_options)); CHECK_MEM(args); if (argc < 2) { print_missing_argument("mode"); } if (arg_matches(argv[1], "gen", 0)) { // SNOWFLAKE_GEN args->mode = SNOWFLAKE_GEN; // required args args->gen.output = 0; int output_set = 0; // optional args args->gen.impl = BSP; args->gen.num_particles = -1; args->gen.symmetry_degree = 6; args->gen.symmetry_type = NONE; args->gen.silent = 0; int argi = 2; while (argi < argc) { if (arg_matches(argv[argi], "--num-particles", "-n")) { check_enough_parameters(argv[argi], argc, argi, 1); args->gen.num_particles = atoi(argv[argi+1]); argi += 2; } else if (arg_matches(argv[argi], "--output", "-o")) { check_enough_parameters(argv[argi], argc, argi, 1); args->gen.output = (char*) realloc(args->gen.output, strlen(argv[argi+1]) + 1); CHECK_MEM(args->gen.output); strcpy(args->gen.output, argv[argi+1]); output_set = 1; argi += 2; } else if (arg_matches(argv[argi], "--impl", 0)) { check_enough_parameters(argv[argi], argc, argi, 1); if (arg_matches(argv[argi+1], "BSP", 0)) { args->gen.impl = BSP; } else if (arg_matches(argv[argi+1], "LINEAR", 0)) { args->gen.impl = LINEAR; } else { print_unrecognised_argument(argv[argi+1]); } argi += 2; } else if (arg_matches(argv[argi], "--symmetry-degree", "-d")) { check_enough_parameters(argv[argi], argc, argi, 1); args->gen.symmetry_degree = atoi(argv[argi+1]); argi += 2; } else if (arg_matches(argv[argi], "--symmetry-type", "-t")) { check_enough_parameters(argv[argi], argc, argi, 1); if (arg_matches(argv[argi+1], "none", 0)) { args->gen.symmetry_type = NONE; } else if (arg_matches(argv[argi+1], "rotational", 0)) { args->gen.symmetry_type = ROTATIONAL; } else if (arg_matches(argv[argi+1], "full", 0)) { args->gen.symmetry_type = FULL; } else { print_unrecognised_argument(argv[argi+1]); } argi += 2; } else if (arg_matches(argv[argi], "--silent", "-s")) { args->gen.silent = 1; argi += 1; } else { print_unrecognised_argument(argv[argi]); } } if (!output_set) { print_missing_argument("--output"); } } else if (arg_matches(argv[1], "render", 0)) { // RENDER args->mode = RENDER; // required args args->render.input = 0; int input_set = 0; // optional args args->render.output = 0; int output_set = 0; args->render.colorize = 0; args->render.movie = 0; args->render.num_frames = 0; int num_frames_set = 0; args->render.silent = 0; int argi = 2; while (argi < argc) { if (arg_matches(argv[argi], "--output", "-o")) { check_enough_parameters(argv[argi], argc, argi, 1); args->render.output = (char*) realloc(args->render.output, strlen(argv[argi+1]) + 1); CHECK_MEM(args->render.output); strcpy(args->render.output, argv[argi+1]); output_set = 1; argi += 2; } else if (arg_matches(argv[argi], "--input", "-i")) { check_enough_parameters(argv[argi], argc, argi, 1); args->render.input = (char*) realloc(args->render.input, strlen(argv[argi+1]) + 1); CHECK_MEM(args->render.input); strcpy(args->render.input, argv[argi+1]); input_set = 1; argi += 2; } else if (arg_matches(argv[argi], "--colorize", "-c")) { args->render.colorize = 1; argi += 1; } else if (arg_matches(argv[argi], "--movie", "-m")) { args->render.movie = 1; argi += 1; } else if (arg_matches(argv[argi], "--frames", "-f")) { check_enough_parameters(argv[argi], argc, argi, 1); args->render.num_frames = atoi(argv[argi+1]); num_frames_set = 1; argi += 2; } else if (arg_matches(argv[argi], "--silent", "-s")) { args->render.silent = 1; argi += 1; } else { print_unrecognised_argument(argv[argi]); } } if (!input_set) { print_missing_argument("--input"); } if (!output_set) { args->render.output = replace_extension(args->render.input, "png"); } if (args->render.movie && !num_frames_set) { print_missing_argument("--frames"); } } else if (arg_matches(argv[1], "tests", 0)) { // TESTS args->mode = TESTS; // optional args args->tests.impl = BSP; int argi = 2; while (argi < argc) { if (arg_matches(argv[argi], "--impl", 0)) { check_enough_parameters(argv[argi], argc, argi, 1); if (arg_matches(argv[argi+1], "BSP", 0)) { args->tests.impl = BSP; } else if (arg_matches(argv[argi+1], "LINEAR", 0)) { args->tests.impl = LINEAR; } else { print_unrecognised_argument(argv[argi+1]); } argi += 2; } else { print_unrecognised_argument(argv[argi]); } } } else { print_unrecognised_argument(argv[1]); } return args; }
// Constructor and destructor c_media_file_ffms::c_media_file_ffms(boost::filesystem::path path) : // Path m_path(path), // File m_source(nullptr), // Info m_frames(0), m_rate(0), m_aspect(1), m_width(0), m_height(0) { // Debug //std::cout << boost::format("FFMS: Opening file! path = %1%") % path << std::endl; // FFMS error m_fferr.Buffer = m_ffmsg.data(); m_fferr.BufferSize = m_ffmsg.size(); m_fferr.ErrorType = FFMS_ERROR_SUCCESS; m_fferr.SubType = FFMS_ERROR_SUCCESS; // Library FFMS_Init(0, 1); // Index FFMS_Index* index = nullptr; // Cached index auto path_index = m_path; path_index.replace_extension(".ffindex"); if (boost::filesystem::is_regular_file(path_index)) { // Read index index = FFMS_ReadIndex(path_index.c_str(), &m_fferr); if (index) { // Check validity int result = FFMS_IndexBelongsToFile(index, m_path.c_str(), &m_fferr); if (result) { // Invalid index FFMS_DestroyIndex(index); index = nullptr; // Delete index file too boost::filesystem::remove(path_index); } } } // Create index if (!index) { // Indexer FFMS_Indexer* indexer = FFMS_CreateIndexer(m_path.c_str(), &m_fferr); if (!indexer) throw c_exception("FFMS: Could not create indexer!", { throw_format("path", m_path) }); //index = FFMS_DoIndexing2(indexer, FFMS_IEH_ABORT, &m_fferr); index = FFMS_DoIndexing(indexer, 0, 0, nullptr, nullptr, FFMS_IEH_ABORT, nullptr, nullptr, &m_fferr); if (!index) throw c_exception("FFMS: Failed to index media!", { throw_format("path", m_path) }); // Write index to file FFMS_WriteIndex(path_index.c_str(), index, &m_fferr); } // Track int track_id = FFMS_GetFirstTrackOfType(index, FFMS_TYPE_VIDEO, &m_fferr); if (track_id < 0) { FFMS_DestroyIndex(index); throw c_exception("FFMS: Failed to find any video tracks!", { throw_format("path", m_path) }); } // Source m_source = FFMS_CreateVideoSource(m_path.c_str(), track_id, index, 1, FFMS_SEEK_NORMAL, &m_fferr); if (!m_source) { FFMS_DestroyIndex(index); throw c_exception("FFMS: Failed to create video source!", { throw_format("path", m_path) }); } // Destroy index FFMS_DestroyIndex(index); index = nullptr; // Video properties const FFMS_VideoProperties* props = FFMS_GetVideoProperties(m_source); m_frames = props->NumFrames; if (props->FirstTime < props->LastTime && props->LastTime > 0.0) m_rate = (props->LastTime - props->FirstTime) / static_cast<double>(m_frames); else if (props->FPSNumerator != 0) m_rate = static_cast<double>(props->FPSNumerator) / static_cast<double>(props->FPSDenominator); if (props->SARNum != 0) m_aspect = static_cast<double>(props->SARNum) / static_cast<double>(props->SARDen); // First frame const FFMS_Frame* frame = FFMS_GetFrame(m_source, 0, &m_fferr); if (!frame) throw c_exception("FFMS: Failed to get first video frame!", { throw_format("path", m_path) }); if (frame->ScaledWidth > 0) m_width = frame->ScaledWidth; else m_width = frame->EncodedWidth; if (frame->ScaledHeight > 0) m_height = frame->ScaledHeight; else m_height = frame->EncodedHeight; // Conversion int pixfmts[2]; pixfmts[0] = FFMS_GetPixFmt("rgb24"); pixfmts[1] = -1; if (FFMS_SetOutputFormatV2(m_source, pixfmts, frame->EncodedWidth, frame->EncodedHeight, FFMS_RESIZER_POINT, &m_fferr)) throw c_exception("FFMS: Failed to set output format!", { throw_format("path", m_path) }); // Info std::cout << boost::format("FFMS: width = %d, height = %d, frames = %d, rate = %.3f, aspect = %.3f") % m_width % m_height % m_frames % m_rate % m_aspect << std::endl; }
Config *init_paths(const char *talk_ref) { Config *config = new Config(); const char *sys_prefix = "/usr/local/share"; config->talk_path = replace_extension(talk_ref, "talk"); config->graph_path = replace_extension(talk_ref, "graph"); config->project_dir = get_path(talk_ref); config->latex_dir = replace_extension(talk_ref, "latex"); config->html_dir = replace_extension(talk_ref, "html"); config->sys_dir = combine_path(sys_prefix, "multitalk"); config->sys_image_dir = combine_path(config->sys_dir, "gfx"); config->sys_style_dir = combine_path(config->sys_dir, "styles"); config->sys_font_dir = combine_path(config->sys_dir, "fonts"); config->proj_style_dir = combine_path(config->project_dir, "styles"); config->proj_font_dir = combine_path(config->project_dir, "fonts"); config->sys_rc_dir = sdup("/etc"); config->caption = new char[strlen(config->talk_path) + 20]; sprintf(config->caption, "Multitalk - %s", config->talk_path); char *e = getenv("MULTITALK_DIR"); if(e == NULL) { config->env_dir = NULL; config->env_style_dir = NULL; config->env_font_dir = NULL; config->env_image_dir = NULL; } else { config->env_dir = sdup(e); config->env_style_dir = combine_path(config->env_dir, "styles"); config->env_font_dir = combine_path(config->env_dir, "fonts"); config->env_image_dir = combine_path(config->env_dir, "gfx"); } uid_t id; struct passwd *pw; id = getuid(); pw = getpwuid(id); if(pw == NULL) error("Can't lookup home directory"); config->home_dir = sdup(pw->pw_dir); config->home_style_dir = combine_path(config->home_dir, ".multitalk/styles"); config->home_font_dir = combine_path(config->home_dir, ".multitalk/fonts"); config->home_image_dir = combine_path(config->home_dir, ".multitalk/gfx"); config->home_rc_dir = combine_path(config->home_dir, ".multitalk"); if(debug & DEBUG_PATHS) { printf("=== Directories ===\n"); printf("talk_path = %s\n", config->talk_path); printf("project_dir = %s\n", config->project_dir); printf("latex_dir = %s\n", config->latex_dir); printf("html_dir = %s\n", config->html_dir); printf("sys_style_dir = %s\n", config->sys_style_dir); printf("home_style_dir = %s\n", config->home_style_dir); printf("===================\n"); } return config; }
/* main: * Guess what this function does. */ int main(int argc, char *argv[]) { PACKFILE *f; CFURLRef cf_url_ref; FSRef fs_ref; FSSpec fs_spec; IconFamilyHandle icon_family; Handle raw_data; char datafile[MAX_STRING_SIZE]; char bundle[MAX_STRING_SIZE]; char bundle_dir[MAX_STRING_SIZE]; char bundle_contents_dir[MAX_STRING_SIZE]; char bundle_contents_resources_dir[MAX_STRING_SIZE]; char bundle_contents_macos_dir[MAX_STRING_SIZE]; char bundle_contents_frameworks_dir[MAX_STRING_SIZE]; char *bundle_exe = NULL; char bundle_plist[MAX_STRING_SIZE]; char bundle_pkginfo[MAX_STRING_SIZE]; char bundle_icns[MAX_STRING_SIZE]; char bundle_version[MAX_STRING_SIZE]; char bundle_long_version[MAX_STRING_SIZE]; char *buffer = NULL; int arg, type = 0, result = 0; int i, size, x, y, mask_bit, mask_byte; unsigned char *data; install_allegro(SYSTEM_NONE, &errno, &atexit); set_color_depth(32); set_color_conversion(COLORCONV_TOTAL | COLORCONV_KEEP_TRANS); if (argc < 2) usage(); datafile[0] = '\0'; bundle[0] = '\0'; select_palette(black_palette); /* Parse command line and load any given resource */ for (arg = 2; arg < argc; arg++) { if (!strcmp(argv[arg], "-m")) flags |= F_MOVE; else if (!strcmp(argv[arg], "-e")) flags |= F_EMBED_FRAMEWORK; else if (!strcmp(argv[arg], "-o")) { if ((argc < arg + 2) || (bundle[0] != '\0')) usage(); strcpy(bundle, argv[++arg]); } else if (!strcmp(argv[arg], "-v")) { if (argc < arg + 2) usage(); flags |= F_GOT_VERSION; strcpy(bundle_version, argv[++arg]); } else if (!strcmp(argv[arg], "-V")) { if (argc < arg + 2) usage(); flags |= F_GOT_LONG_VERSION; strcpy(bundle_long_version, argv[++arg]); } else if (!strcmp(argv[arg], "-d")) { if (argc < arg + 2) usage(); strcpy(datafile, argv[++arg]); } else if ((!strcmp(argv[arg], "-16")) || (!strcmp(argv[arg], "-32")) || (!strcmp(argv[arg], "-48")) || (!strcmp(argv[arg], "-128"))) { if (argc < arg + 2) usage(); switch (atoi(&argv[arg][1])) { case 16: type = 0; break; case 32: type = 1; break; case 48: type = 2; break; case 128: type = 3; break; } if (load_resource(datafile, argv[++arg], &icon_data[type])) { result = -1; goto exit_error; } } else { if (load_resource(datafile, argv[arg], NULL)) { result = -1; goto exit_error; } } } buffer = malloc(4096); if (!buffer) { result = -1; goto exit_error_bundle; } bundle_exe = argv[1]; if (!exists(bundle_exe)) { fprintf(stderr, "Cannot locate executable file '%s'\n", bundle_exe); result = -1; goto exit_error; } if (bundle[0] == '\0') strcpy(bundle, bundle_exe); replace_extension(bundle_dir, bundle, "app", MAX_STRING_SIZE); strcpy(bundle_contents_dir, bundle_dir); strcat(bundle_contents_dir, "/Contents"); strcpy(bundle_contents_resources_dir, bundle_contents_dir); strcat(bundle_contents_resources_dir, "/Resources"); strcpy(bundle_contents_macos_dir, bundle_contents_dir); strcat(bundle_contents_macos_dir, "/MacOS"); strcpy(bundle_contents_frameworks_dir, bundle_contents_dir); strcat(bundle_contents_frameworks_dir, "/Frameworks"); bundle_icns[0] = '\0'; bundle_plist[0] = '\0'; bundle_pkginfo[0] = '\0'; /* Create bundle structure */ if ((mkdir(bundle_dir, 0777) && (errno != EEXIST)) || (mkdir(bundle_contents_dir, 0777) && (errno != EEXIST)) || (mkdir(bundle_contents_resources_dir, 0777) && (errno != EEXIST)) || (mkdir(bundle_contents_macos_dir, 0777) && (errno != EEXIST))) { fprintf(stderr, "Cannot create %s\n", bundle_dir); result = -1; goto exit_error_bundle; } /* Copy/move executable into the bundle */ if (copy_file(bundle_exe, bundle_contents_macos_dir)) { fprintf(stderr, "Cannot create %s\n", bundle_contents_macos_dir); result = -1; goto exit_error_bundle; } strcat(bundle_contents_macos_dir, "/"); strcat(bundle_contents_macos_dir, get_filename(bundle_exe)); chmod(bundle_contents_macos_dir, 0755); if (flags & F_MOVE) unlink(bundle_exe); /* Embed Allegro framework if requested */ if (flags & F_EMBED_FRAMEWORK) { if (!file_exists("/Library/Frameworks/Allegro.framework", FA_RDONLY | FA_DIREC, NULL)) { fprintf(stderr, "Cannot find Allegro framework\n"); result = -1; goto exit_error_bundle; } if (!exists("/Library/Frameworks/Allegro.framework/Resources/Embeddable")) { fprintf(stderr, "Cannot embed system wide Allegro framework; install embeddable version first!\n"); result = -1; goto exit_error_bundle; } sprintf(buffer, "/Developer/Tools/pbxcp -exclude .DS_Store -exclude CVS -resolve-src-symlinks /Library/Frameworks/Allegro.framework %s", bundle_contents_frameworks_dir); if ((mkdir(bundle_contents_frameworks_dir, 0777) && (errno != EEXIST)) || (system(buffer))) { fprintf(stderr, "Cannot create %s\n", bundle_contents_frameworks_dir); result = -1; goto exit_error_bundle; } } /* Setup the .icns resource */ if (flags & F_ICONS_DEFINED) { strcat(bundle_contents_resources_dir, "/"); strcat(bundle_contents_resources_dir, get_filename(bundle)); replace_extension(bundle_icns, bundle_contents_resources_dir, "icns", MAX_STRING_SIZE); icon_family = (IconFamilyHandle)NewHandle(0); for (i = 0; i < 4; i++) { if (flags & icon_data[i].defined) { /* Set 32bit RGBA data */ raw_data = NewHandle(icon_data[i].size * icon_data[i].size * 4); data = *(unsigned char **)raw_data; for (y = 0; y < icon_data[i].size; y++) { for (x = 0; x < icon_data[i].size; x++) { *data++ = geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]); *data++ = getr32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]); *data++ = getg32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]); *data++ = getb32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]); } } if (SetIconFamilyData(icon_family, icon_data[i].data, raw_data) != noErr) { DisposeHandle(raw_data); fprintf(stderr, "Error setting %dx%d icon resource RGBA data\n", icon_data[i].size, icon_data[i].size); result = -1; goto exit_error_bundle; } DisposeHandle(raw_data); /* Set 8bit mask */ raw_data = NewHandle(icon_data[i].size * icon_data[i].size); data = *(unsigned char **)raw_data; for (y = 0; y < icon_data[i].size; y++) { for (x = 0; x < icon_data[i].size; x++) { *data++ = geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]); } } if (SetIconFamilyData(icon_family, icon_data[i].mask8, raw_data) != noErr) { DisposeHandle(raw_data); fprintf(stderr, "Error setting %dx%d icon resource 8bit mask\n", icon_data[i].size, icon_data[i].size); result = -1; goto exit_error_bundle; } DisposeHandle(raw_data); /* Set 1bit mask */ if (icon_data[i].mask1) { size = ((icon_data[i].size * icon_data[i].size) + 7) / 8; raw_data = NewHandle(size * 2); data = *(unsigned char **)raw_data; mask_byte = 0; mask_bit = 7; for (y = 0; y < icon_data[i].size; y++) { for (x = 0; x < icon_data[i].size; x++) { if (geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]) >= 0xfd) mask_byte |= (1 << mask_bit); mask_bit--; if (mask_bit < 0) { *data++ = mask_byte; mask_byte = 0; mask_bit = 7; } } } memcpy(*raw_data + size, *raw_data, size); if (SetIconFamilyData(icon_family, icon_data[i].mask1, raw_data) != noErr) { DisposeHandle(raw_data); fprintf(stderr, "Error setting %dx%d icon resource 1bit mask\n", icon_data[i].size, icon_data[i].size); result = -1; goto exit_error_bundle; } DisposeHandle(raw_data); } } } f = pack_fopen(bundle_icns, F_WRITE); if (!f) { fprintf(stderr, "Cannot create %s\n", bundle_icns); result = -1; goto exit_error_bundle; } pack_fclose(f); cf_url_ref = CFURLCreateWithBytes(kCFAllocatorDefault, (unsigned char *)bundle_icns, strlen(bundle_icns), 0, NULL); if (!cf_url_ref) { fprintf(stderr, "Cannot create %s\n", bundle_icns); result = -1; goto exit_error_bundle; } CFURLGetFSRef(cf_url_ref, &fs_ref); CFRelease(cf_url_ref); if ((FSGetCatalogInfo(&fs_ref, kFSCatInfoNone, NULL, NULL, &fs_spec, NULL)) || (WriteIconFile(icon_family, &fs_spec) != noErr)) { fprintf(stderr, "Cannot create %s\n", bundle_icns); result = -1; goto exit_error_bundle; } DisposeHandle((Handle)icon_family); } /* Setup Info.plist */ sprintf(bundle_plist, "%s/Info.plist", bundle_contents_dir); f = pack_fopen(bundle_plist, F_WRITE); if (!f) { fprintf(stderr, "Cannot create %s\n", bundle_plist); result = -1; goto exit_error_bundle; } sprintf(buffer, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" "<plist version=\"1.0\">\n" "<dict>\n" "\t<key>CFBundleExecutable</key>\n" "\t<string>%s</string>\n" "\t<key>CFBundleInfoDictionaryVersion</key>\n" "\t<string>6.0</string>\n" "\t<key>CFBundlePackageType</key>\n" "\t<string>APPL</string>\n" "\t<key>CFBundleSignature</key>\n" "\t<string>%s</string>\n" "\t<key>CFBundleVersion</key>\n" "\t<string>%s</string>\n" "\t<key>CFBundleDocumentTypes</key>\n" "\t<array>\n" "\t\t<dict>\n" "\t\t\t<key>CFBundleTypeExtensions</key>\n" "\t\t\t<array>\n" "\t\t\t\t<string>*</string>\n" "\t\t\t</array>\n" "\t\t\t<key>CFBundleTypeName</key>\n" "\t\t\t<string>NSStringPboardType</string>\n" "\t\t\t<key>CFBundleTypeOSTypes</key>\n" "\t\t\t<array>\n" "\t\t\t\t<string>****</string>\n" "\t\t\t</array>\n" "\t\t\t<key>CFBundleTypeRole</key>\n" "\t\t\t<string>Viewer</string>\n" "\t\t</dict>\n" "\t</array>\n", get_filename(bundle_exe), "????", (flags & F_GOT_VERSION) ? bundle_version : "1.0"); pack_fputs(buffer, f); if (flags & F_GOT_LONG_VERSION) { sprintf(buffer, "\t<key>CFBundleGetInfoString</key>\n" "\t<string>%s</string>\n", bundle_long_version); pack_fputs(buffer, f); } if (flags & F_ICONS_DEFINED) { sprintf(buffer, "\t<key>CFBundleIconFile</key>\n" "\t<string>%s</string>\n", get_filename(bundle_icns)); pack_fputs(buffer, f); } pack_fputs("</dict>\n</plist>\n", f); pack_fclose(f); /* Setup PkgInfo */ sprintf(bundle_pkginfo, "%s/PkgInfo", bundle_contents_dir); f = pack_fopen(bundle_pkginfo, F_WRITE); if (!f) { fprintf(stderr, "Cannot create %s\n", bundle_pkginfo); result = -1; goto exit_error_bundle; } pack_fputs("APPL????", f); pack_fclose(f); exit_error: if (buffer) free(buffer); for (i = 0; i < 4; i++) { if (icon_data[i].original) destroy_bitmap(icon_data[i].original); if (icon_data[i].workspace) destroy_bitmap(icon_data[i].workspace); if (icon_data[i].scaled) destroy_bitmap(icon_data[i].scaled); } return result; exit_error_bundle: sprintf(buffer, "%s/%s", bundle_contents_macos_dir, get_filename(bundle_exe)); unlink(buffer); unlink(bundle_plist); unlink(bundle_pkginfo); unlink(bundle_icns); rmdir(bundle_dir); rmdir(bundle_contents_dir); rmdir(bundle_contents_resources_dir); rmdir(bundle_contents_macos_dir); goto exit_error; }
int main(int argc, char* argv[]) { if (argc < 2) { std::cerr << "Error: no file given\n"; print_usage(argv[0]); return EXIT_FAILURE; } // include paths std::vector<std::string> paths; std::string file_name, target_name, output_file; bool ignore_non_existing = true; // -MG bool add_empty_phony_targets = false; // -MP for (int i = 1; i < argc; i++) { const std::string arg(argv[i]); if (starts_with(arg, "-I") && arg.length() > 2) { paths.push_back(arg.substr(2)); continue; } if (arg == "-MG") { ignore_non_existing = false; continue; } if (arg == "-MM") { // ignore headers from system directories (default) continue; } if (arg == "-M") { std::cerr << "Warning: ignoring unsupported option " << arg << '\n'; continue; } if (arg == "-MD" || arg == "-MQ") { std::cerr << "Warning: ignoring unsupported option " << arg << '\n'; i++; continue; } if (arg == "-MP") { add_empty_phony_targets = true; continue; } if (arg == "-MT" && i + 1 < argc) { target_name = argv[++i]; continue; } if ((arg == "-MF" || arg == "-MMD" || arg == "-o") && i + 1 < argc) { output_file = argv[++i]; continue; } if (arg == "--help" || arg == "-h") { print_usage(argv[0]); return EXIT_SUCCESS; } // interpret last argument as file name if (i + 1 == argc) { file_name = arg; if (!file_exists(file_name)) { std::cerr << "Error: file does not exist: " << file_name << '\n'; return EXIT_FAILURE; } continue; } std::cerr << "Error: unknown option: " << arg << '\n'; print_usage(argv[0]); return EXIT_FAILURE; } // select output stream std::ofstream fstr(output_file); std::ostream* ostr = &std::cout; if (!output_file.empty()) { if (!fstr.good()) { std::cerr << "Error: cannot write to file " << output_file << '\n'; return EXIT_FAILURE; } ostr = &fstr; } // include paths paths.insert(paths.begin(), directory(file_name)); paths.push_back("."); paths = delete_duplicates(paths); // search for header inclusions in file const std::vector<std::string> dependencies = delete_duplicates( search_includes(file_name, paths, ignore_non_existing), Is_not_duplicate_ignore_path()); // prepend file itself to dependency list std::vector<std::string> dependencies_and_main(dependencies); dependencies_and_main.insert(dependencies_and_main.begin(), file_name); if (target_name.empty()) target_name = replace_extension(filename(file_name), "o"); // output print_dependencies(target_name, dependencies_and_main, *ostr); if (add_empty_phony_targets) print_empty_phony_targets(dependencies, *ostr); return EXIT_SUCCESS; }
void HOSTFXR_UTILITY::GetHostFxrParameters( const fs::path &processPath, const fs::path &applicationPhysicalPath, const std::wstring &applicationArguments, fs::path &hostFxrDllPath, fs::path &dotnetExePath, std::vector<std::wstring> &arguments ) { LOG_INFOF(L"Resolving hostfxr parameters for application: '%ls' arguments: '%ls' path: '%ls'", processPath.c_str(), applicationArguments.c_str(), applicationPhysicalPath.c_str()); arguments = std::vector<std::wstring>(); fs::path expandedProcessPath = Environment::ExpandEnvironmentVariables(processPath); const auto expandedApplicationArguments = Environment::ExpandEnvironmentVariables(applicationArguments); LOG_INFOF(L"Known dotnet.exe location: '%ls'", dotnetExePath.c_str()); if (!expandedProcessPath.has_extension()) { // The only executable extension inprocess supports expandedProcessPath.replace_extension(".exe"); } else if (!ends_with(expandedProcessPath, L".exe", true)) { throw InvalidOperationException(format(L"Process path '%s' doesn't have '.exe' extension.", expandedProcessPath.c_str())); } // Check if the absolute path is to dotnet or not. if (IsDotnetExecutable(expandedProcessPath)) { LOG_INFOF(L"Process path '%ls' is dotnet, treating application as portable", expandedProcessPath.c_str()); if (applicationArguments.empty()) { throw InvalidOperationException(L"Application arguments are empty."); } if (dotnetExePath.empty()) { dotnetExePath = GetAbsolutePathToDotnet(applicationPhysicalPath, expandedProcessPath); } hostFxrDllPath = GetAbsolutePathToHostFxr(dotnetExePath); arguments.push_back(dotnetExePath); AppendArguments( expandedApplicationArguments, applicationPhysicalPath, arguments, true); } else { LOG_INFOF(L"Process path '%ls' is not dotnet, treating application as standalone or portable with bootstrapper", expandedProcessPath.c_str()); auto executablePath = expandedProcessPath; if (executablePath.is_relative()) { executablePath = applicationPhysicalPath / expandedProcessPath; } // // The processPath is a path to the application executable // like: C:\test\MyApp.Exe or MyApp.Exe // Check if the file exists, and if it does, get the parameters for a standalone application // if (is_regular_file(executablePath)) { auto applicationDllPath = executablePath; applicationDllPath.replace_extension(".dll"); LOG_INFOF(L"Checking application.dll at '%ls'", applicationDllPath.c_str()); if (!is_regular_file(applicationDllPath)) { throw InvalidOperationException(format(L"Application .dll was not found at %s", applicationDllPath.c_str())); } hostFxrDllPath = executablePath.parent_path() / "hostfxr.dll"; LOG_INFOF(L"Checking hostfxr.dll at '%ls'", hostFxrDllPath.c_str()); if (is_regular_file(hostFxrDllPath)) { LOG_INFOF(L"hostfxr.dll found app local at '%ls', treating application as standalone", hostFxrDllPath.c_str()); // For standalone apps we need .exe to be argv[0], dll would be discovered next to it arguments.push_back(executablePath); } else { LOG_INFOF(L"hostfxr.dll found app local at '%ls', treating application as portable with launcher", hostFxrDllPath.c_str()); // passing "dotnet" here because we don't know where dotnet.exe should come from // so trying all fallbacks is appropriate if (dotnetExePath.empty()) { dotnetExePath = GetAbsolutePathToDotnet(applicationPhysicalPath, L"dotnet"); } hostFxrDllPath = GetAbsolutePathToHostFxr(dotnetExePath); // For portable with launcher apps we need dotnet.exe to be argv[0] and .dll be argv[1] arguments.push_back(dotnetExePath); arguments.push_back(applicationDllPath); } AppendArguments( expandedApplicationArguments, applicationPhysicalPath, arguments); } else { // // If the processPath file does not exist and it doesn't include dotnet.exe or dotnet // then it is an invalid argument. // throw InvalidOperationException(format(L"Executable was not found at '%s'", executablePath.c_str())); } } }