static const char *findfile (lua_State *L, const char *name, const char *pname) { get_current_path(L, 2); /* ROCKLUA ADDED */ const char *current_path = lua_tostring(L, -1); const char *path; name = luaL_gsub(L, name, ".", LUA_DIRSEP); lua_getfield(L, LUA_ENVIRONINDEX, pname); path = lua_tostring(L, -1); if (path == NULL) luaL_error(L, LUA_QL("package.%s") " must be a string", pname); lua_pushliteral(L, ""); /* error accumulator */ while ((path = pushnexttemplate(L, path)) != NULL) { const char *filename; filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); if(current_path != NULL) filename = luaL_gsub(L, filename, "$", current_path); lua_remove(L, -2); /* remove path template */ if (readable(filename)) /* does file exist and is readable? */ return filename; /* return that file name */ lua_pushfstring(L, "\n\tno file " LUA_QS, filename); lua_remove(L, -2); /* remove file name */ lua_concat(L, 2); /* add entry to possible error message */ } return NULL; /* not found */ }
static void menu_position (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, PlumaDocumentsPanel *panel) { GtkTreePath *path; GdkRectangle rect; gint wx, wy; GtkAllocation allocation; GtkRequisition requisition; GtkWidget *w; w = panel->priv->treeview; #if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_get_allocation(w, &allocation); #else allocation = w->allocation; #endif path = get_current_path (panel); gtk_tree_view_get_cell_area (GTK_TREE_VIEW (w), path, NULL, &rect); wx = rect.x; wy = rect.y; #if GTK_CHECK_VERSION (3, 0, 0) gdk_window_get_origin (gtk_widget_get_window (w), x, y); #else gdk_window_get_origin (w->window, x, y); #endif gtk_widget_size_request (GTK_WIDGET (menu), &requisition); if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL) { *x += allocation.x + allocation.width - requisition.width - 10; } else { *x += allocation.x + 10; } wy = MAX (*y + 5, *y + wy + 5); wy = MIN (wy, *y + allocation.height - requisition.height - 5); *y = wy; *push_in = TRUE; }
static ofFloatColor ofpath_color(fz_device *dev, fz_colorspace *colorspace, float *color, float alpha) { ofPath &p = get_current_path(dev); float rgb[3]; colorspace->to_rgb(dev->ctx, colorspace, color, rgb); return ofFloatColor(rgb[0], rgb[1], rgb[2], alpha); }
static void menu_position (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, GeditDocumentsPanel *panel) { GtkTreePath *path; GdkRectangle rect; gint wy; GtkRequisition requisition; GtkWidget *w; GtkAllocation allocation; gedit_debug (DEBUG_PANEL); w = panel->priv->treeview; path = get_current_path (panel); gtk_tree_view_get_cell_area (GTK_TREE_VIEW (w), path, NULL, &rect); gtk_tree_path_free (path); wy = rect.y; gdk_window_get_origin (gtk_widget_get_window (w), x, y); gtk_widget_get_preferred_size (GTK_WIDGET (menu), &requisition, NULL); gtk_widget_get_allocation (w, &allocation); if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL) { *x += allocation.x + allocation.width - requisition.width - 10; } else { *x += allocation.x + 10; } wy = MAX (*y + 5, *y + wy + 5); wy = MIN (wy, *y + allocation.height - requisition.height - 5); *y = wy; *push_in = TRUE; }
void EditorFileDialog::_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata) { set_process(false); preview_waiting = false; if (p_preview.is_valid() && get_current_path() == p_path) { preview->set_texture(p_preview); if (display_mode == DISPLAY_THUMBNAILS) { preview_vb->hide(); } else { preview_vb->show(); } } else { preview_vb->hide(); preview->set_texture(Ref<Texture>()); } }
static void ofpath_path(fz_device *dev, fz_path *path) { ofPath &p = get_current_path(dev); ofMatrix4x4 &mat = get_current_matrix(dev); ofPoint cp1, cp2, pp; float x, y; int i = 0; int n; while (i < path->len) { switch (path->items[i++].k) { case FZ_MOVETO: x = path->items[i++].v; y = path->items[i++].v; p.moveTo(mat.preMult(ofVec3f(x, y))); break; case FZ_LINETO: x = path->items[i++].v; y = path->items[i++].v; p.lineTo(mat.preMult(ofVec3f(x, y))); break; case FZ_CURVETO: x = path->items[i++].v; y = path->items[i++].v; cp1.set(mat.preMult(ofVec3f(x, y))); x = path->items[i++].v; y = path->items[i++].v; cp2.set(mat.preMult(ofVec3f(x, y))); x = path->items[i++].v; y = path->items[i++].v; pp.set(mat.preMult(ofVec3f(x, y))); p.bezierTo(cp1, cp2, pp); break; case FZ_CLOSE_PATH: p.close(); break; } } }
jpgx_compress_container write_jpgx(char *filename, jpeg_decompress_container container, secure_container **sc_array, int sc_arr_count, char *user_key) { struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; int i, j, k = 0; des3_context ctx3; JSAMPROW row_pointer = NULL; JSAMPROW secure_rp = NULL; char *out_temp_folder = str_concat(3, get_current_path(filename), ".", get_file_name(filename)); char *core_file_path = str_concat(2, out_temp_folder, "/core.jpg"); FILE *core_file = fopen(core_file_path, "wb"); FILE **sc_file = NULL; char **sc_file_path = NULL; char **sc_enc_file_path = NULL; char **pack_file_path = NULL; char *jpgx_file_path = str_concat(3, get_current_path(filename), get_file_name(filename), ".jpgx"); char *prop_file_path = str_concat(2, out_temp_folder, "/prop.xml"); char * key = make_des_key(user_key); int pack_file_count = 0; jpgx_compress_container jpgx_container; /* output jpgx container */ struct jpeg_compress_struct **secure_item_info; if (!core_file) { printf("Error opening output jpeg file %s\n!", filename); return; } /* deep copy decompress info */ cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); jpeg_stdio_dest(&cinfo, core_file); cinfo.image_width = container.dcinfo.image_width; cinfo.image_height = container.dcinfo.image_height; cinfo.input_components = container.dcinfo.num_components; cinfo.in_color_space = container.dcinfo.out_color_space; jpeg_set_defaults(&cinfo); jpeg_start_compress(&cinfo, TRUE); /* malloc secure item */ secure_item_info = (struct jpeg_compress_struct**)malloc(sizeof(struct jpeg_compress_struct*) * sc_arr_count); sc_file = (FILE**)malloc(sizeof(FILE*)* sc_arr_count); sc_file_path = (char **)malloc(sizeof(char*)*sc_arr_count); sc_enc_file_path = (char **)malloc(sizeof(char*)*sc_arr_count); for (i = 0; i < sc_arr_count; i++) { secure_container sc = *sc_array[i]; char *out_file_name = "core.jpg"; /* malloc secure item */ sc_file_path[i] = (char*)malloc(strlen(out_temp_folder) + 128); sc_enc_file_path[i] = (char*)malloc(strlen(out_temp_folder) + 128); secure_item_info[i] = (struct jpeg_compress_struct*)malloc(sizeof(struct jpeg_compress_struct)); /* set file path */ sprintf(sc_file_path[i], "%s/item%d.jpg", out_temp_folder, i); sprintf(sc_enc_file_path[i], "%s/item%d.ise", out_temp_folder, i); /* log */ printf("sc_file_path : %s\n", sc_file_path[i]); printf("sc_enc_file_path : %s\n", sc_enc_file_path[i]); printf("\n"); sc_file[i] = fopen(sc_file_path[i], "wb"); secure_item_info[i]->err = jpeg_std_error(&jerr); jpeg_create_compress(secure_item_info[i]); jpeg_stdio_dest(secure_item_info[i], sc_file[i]); secure_item_info[i]->image_width = sc.width; secure_item_info[i]->image_height = sc.height; secure_item_info[i]->input_components = container.dcinfo.num_components; secure_item_info[i]->in_color_space = container.dcinfo.out_color_space; jpeg_set_defaults(secure_item_info[i]); jpeg_start_compress(secure_item_info[i], TRUE); } while (cinfo.next_scanline < cinfo.image_height) { /* read jpeg row pointer */ row_pointer = &container.image[cinfo.next_scanline * cinfo.image_width * cinfo.input_components]; /* find each container exists. */ for (j = 0; j < sc_arr_count; j++) { secure_container sc = *sc_array[j]; /* if secure container is matching, then copy to ise */ if (sc.pos_y <= cinfo.next_scanline && sc.pos_y + sc.height > cinfo.next_scanline) { secure_rp = &container.image[cinfo.next_scanline * cinfo.image_width * cinfo.input_components + sc.pos_x * cinfo.input_components]; jpeg_write_scanlines(secure_item_info[j], &secure_rp, 1); for (i = sc.pos_x * cinfo.input_components; i < (sc.pos_x + sc.width) * cinfo.input_components; i++) { row_pointer[i] = 0; } } } jpeg_write_scanlines(&cinfo, &row_pointer, 1); } for (i = 0; i < sc_arr_count; i++) { jpeg_finish_compress(secure_item_info[i]); jpeg_destroy_compress(secure_item_info[i]); fclose(sc_file[i]); if (encode_file_des(sc_file_path[i], sc_enc_file_path[i], key) > 0) { printf("encode file : %s\n", sc_file_path[i]); printf("\n"); } else { printf("encode file failed: %s\n", sc_file_path[i]); printf("\n"); } } jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); fclose(core_file); /* make property file */ make_prop_xml(sc_array, sc_arr_count, prop_file_path, key, "normal"); /* packing files */ pack_file_count = sc_arr_count + 2; pack_file_path = (char **)malloc(sizeof(char*)*pack_file_count); pack_file_path[0] = core_file_path; pack_file_path[1] = prop_file_path; /* prop path */ for (i = 0; i < sc_arr_count; i++) { pack_file_path[i + 2] = sc_enc_file_path[i]; printf("pack_file_path[%d] : %s\n", (i + 2), pack_file_path[i + 2]); } if (make_compress(pack_file_path, pack_file_count, jpgx_file_path, "jpgx") == ZIP_OK) { printf("compress : success\n"); } else { printf("compress : fail\n"); } /* remove temp files */ for (i = 0; i < sc_arr_count; i++) { remove(sc_file_path[i]); /* item files */ } for (i = 0; i < pack_file_count; i++) { remove(pack_file_path[i]); /* packing files */ } #if WIN32 _rmdir(out_temp_folder); #else rmdir(out_temp_folder); #endif /* return jpgx container */ free(container.image); free(sc_file); jpgx_container.file_path = jpgx_file_path; jpgx_container.sc_arr = &secure_item_info; jpgx_container.sc_cnt = sc_arr_count; return jpgx_container; }
jpgx_decompress_container read_jpgx_container(char* filename, char* user_key) { jpgx_decompress_container jpgx_container; int i, j = 0; secure_container **sc_array; jpeg_decompress_container container; JSAMPROW row_pointer = NULL; prop_info_container prop; char * key = make_des_key(user_key); /* set file path */ char *out_temp_folder = str_concat(3, get_current_path(filename), ".", get_file_name(filename)); char *decode_path = str_concat(2, out_temp_folder, "/.decode"); if (make_decompress(filename) == UNZ_OK) { /* init struct prop_xml, jpeg_container */ prop = parse_prop_xml(str_concat(2, out_temp_folder, "/prop.xml")); container = read_jpeg_container(str_concat(2, out_temp_folder, "/core.jpg")); sc_array = prop.sc_arr; for (i = 0; i < prop.sc_count; i++) { int core_pos = 0; int sc_pos = 0; printf("file name : %s\n", prop.file_name[i]); decode_file_des(str_concat(3, out_temp_folder, "/", prop.file_name[i]), decode_path, key); jpeg_decompress_container jdc = read_jpeg_container(decode_path); JSAMPROW secure_row_pointer; if (jdc.status > 0) { for (core_pos = sc_array[i]->pos_y, sc_pos = 0; core_pos < (int)(sc_array[i]->pos_y + sc_array[i]->height); core_pos++, sc_pos++) { row_pointer = &container.image[core_pos * container.dcinfo.image_width * container.dcinfo.output_components]; secure_row_pointer = &jdc.image[sc_pos * jdc.dcinfo.image_width * jdc.dcinfo.output_components]; for (j = 0; j < jdc.dcinfo.image_width*jdc.dcinfo.output_components; j++) { /* combine buffers uinsg core.jpg and ise files */ row_pointer[j + (sc_array[i]->pos_x)*jdc.dcinfo.output_components] = secure_row_pointer[j]; } } } /* remove temp decode files */ remove(decode_path); remove(str_concat(3, out_temp_folder, "/", prop.file_name[i])); } remove(str_concat(2, out_temp_folder, "/core.jpg")); remove(str_concat(2, out_temp_folder, "/prop.xml")); #if WIN32 _rmdir(out_temp_folder); #else rmdir(out_temp_folder); #endif /* test code char *out = "./test/test1234.jpg"; FILE *file = NULL; struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; file = fopen(out, "wb"); cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); jpeg_stdio_dest(&cinfo, file); cinfo.image_width = container.dcinfo.image_width; cinfo.image_height = container.dcinfo.image_height; cinfo.input_components = container.dcinfo.num_components; cinfo.in_color_space = container.dcinfo.out_color_space; jpeg_set_defaults(&cinfo); jpeg_start_compress(&cinfo, TRUE); while (cinfo.next_scanline < cinfo.image_height) { row_pointer = &container.image[cinfo.next_scanline * cinfo.image_width * cinfo.input_components]; jpeg_write_scanlines(&cinfo, &row_pointer, 1); } jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); fclose(file); */ jpgx_container.jdcinfo = container; jpgx_container.sc_cnt = prop.sc_count; jpgx_container.sc_arr = sc_array; jpgx_container.status = ISE_STATUS_OK; return jpgx_container; } jpgx_container.status = ISE_STATUS_ERROR_UNPACKING; return jpgx_container; }
//----------------------------------------------------------------------------- int main( int argc, char* argv[] ) { std::string path; std::string temp_path, root_path; // names of files and directories std::string test_file = "test.txt"; std::string subdir1_name = "subdir1"; std::string subdir2_name = "subdir2"; std::string subsubdir1_name = "subsubdir1"; std::string subdir_test_file = "subtest.txt"; // get the current working path from the system std::string working_path = get_current_path(); // attempt to create a temporary directory if( !get_temp_directory( temp_path ) ) return 5; // temp path just reported to be successfully created. test existence method if( !path_exists( temp_path ) ) return 1; // temp path is a path to a directory, so test is_directory if( !is_directory( temp_path ) ) return 2; // create a file in the temp path if( !create_test_file( temp_path, test_file ) ) return 8; // already know temp path is not a file, so test is_file for negative case if( is_file( temp_path ) ) return 3; // test whether the is file method reports the test file correctly path = combine_path( temp_path, test_file ); if( !is_file( path ) ) return 3; // attempt to remove the temporary directory if( !remove_directory( temp_path ) ) return 6; //-- // get another temporary directory this time call it the root path if( !get_temp_directory( root_path ) ) return 7; // create a file in the root path if( !create_test_file( root_path, test_file ) ) return 8; // create a directory in the root path std::string subdir1_path = combine_path( root_path, subdir1_name ); if( !get_directory( subdir1_path ) ) return 9; // create another directory in the root path std::string subdir2_path = combine_path( root_path, subdir2_name ); if( !get_directory( subdir2_path ) ) return 9; // create a directory in the first child directory of the root path std::string subsubdir1_path = combine_path( subdir1_path, subsubdir1_name ); if( !get_directory( subsubdir1_path ) ) return 9; // create a file in the child of the child directory if( !create_test_file( subsubdir1_path, subdir_test_file ) ) return 8; /* // get the subdirectories of the root std::vector<std::string> dirs = get_subdirectories( root_path ); for( std::vector<std::string>::iterator it = dirs.begin(); it != dirs.end(); it++ ) { printf( "dir: %s\n", it->c_str() ); } */ // test find file without recursion. search for the test file in the root if( !find_file( path, test_file, root_path ) ) return 1; // validate the path returned from find file temp_path = combine_path( root_path, test_file ); if( temp_path != path ) return 1; // test find file with recursion. search for the subtest file in the dirs if( !find_file( path, subdir_test_file, root_path, true ) ) return 1; temp_path = combine_path( subsubdir1_path, subdir_test_file ); if( temp_path != path ) return 1; // clean up the root path if( !remove_directory( root_path ) ) return 6; if( find_file( path, "gzserver", "/usr/local", true ) ) { printf( "path: %s\n", path.c_str() ); } return 0; }