static int op_removesl(ops_t *ops, void *data, const char *src, const char *dst) { if(cfg.delete_prg[0] != '\0') { #ifndef _WIN32 char *escaped; char cmd[2*PATH_MAX + 1]; const int cancellable = (data == NULL); escaped = shell_like_escape(src, 0); if(escaped == NULL) { return -1; } snprintf(cmd, sizeof(cmd), "%s %s", cfg.delete_prg, escaped); free(escaped); LOG_INFO_MSG("Running trash command: \"%s\"", cmd); return background_and_wait_for_errors(cmd, cancellable); #else char cmd[PATH_MAX*2 + 1]; snprintf(cmd, sizeof(cmd), "%s \"%s\"", cfg.delete_prg, src); to_back_slash(cmd); return os_system(cmd); #endif } if(!cfg.use_system_calls) { #ifndef _WIN32 char *escaped; char cmd[16 + PATH_MAX]; int result; const int cancellable = data == NULL; escaped = shell_like_escape(src, 0); if(escaped == NULL) return -1; snprintf(cmd, sizeof(cmd), "rm -rf %s", escaped); LOG_INFO_MSG("Running rm command: \"%s\"", cmd); result = background_and_wait_for_errors(cmd, cancellable); free(escaped); return result; #else if(is_dir(src)) { char path[PATH_MAX]; int err; copy_str(path, sizeof(path), src); to_back_slash(path); wchar_t *const utf16_path = utf8_to_utf16(path); SHFILEOPSTRUCTW fo = { .hwnd = NULL, .wFunc = FO_DELETE, .pFrom = utf16_path, .pTo = NULL, .fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI, }; err = SHFileOperationW(&fo); log_msg("Error: %d", err); free(utf16_path); return err; } else { int ok; wchar_t *const utf16_path = utf8_to_utf16(src); DWORD attributes = GetFileAttributesW(utf16_path); if(attributes & FILE_ATTRIBUTE_READONLY) { SetFileAttributesW(utf16_path, attributes & ~FILE_ATTRIBUTE_READONLY); } ok = DeleteFileW(utf16_path); if(!ok) { LOG_WERROR(GetLastError()); } free(utf16_path); return !ok; } #endif }
void process_build_chart::on_not_impl(std::string const & message) { _CP_LOG << L"[process_draw_chart visitor] : not impliment for \"" << utf8_to_utf16(message) << L"\"" << std::endl; }
int iop_cp(io_args_t *const args) { const char *const src = args->arg1.src; const char *const dst = args->arg2.dst; const IoCrs crs = args->arg3.crs; const io_confirm confirm = args->confirm; const int cancellable = args->cancellable; struct stat st; char block[BLOCK_SIZE]; FILE *in, *out; size_t nread; int error; struct stat src_st; const char *open_mode = "wb"; ioeta_update(args->estim, src, dst, 0, 0); #ifdef _WIN32 if(is_symlink(src) || crs != IO_CRS_APPEND_TO_FILES) { DWORD flags; int error; wchar_t *utf16_src, *utf16_dst; flags = COPY_FILE_COPY_SYMLINK; if(crs == IO_CRS_FAIL) { flags |= COPY_FILE_FAIL_IF_EXISTS; } else if(path_exists(dst, DEREF)) { /* Ask user whether to overwrite destination file. */ if(confirm != NULL && !confirm(args, src, dst)) { return 0; } } utf16_src = utf8_to_utf16(src); utf16_dst = utf8_to_utf16(dst); error = CopyFileExW(utf16_src, utf16_dst, &win_progress_cb, args, NULL, flags) == 0; if(error) { /* FIXME: use real system error message here. */ (void)ioe_errlst_append(&args->result.errors, dst, IO_ERR_UNKNOWN, "Copy file failed"); } free(utf16_src); free(utf16_dst); ioeta_update(args->estim, NULL, NULL, 1, 0); return error; } #endif /* Create symbolic link rather than copying file it points to. This check * should go before directory check as is_dir() resolves symbolic links. */ if(is_symlink(src)) { char link_target[PATH_MAX]; int error; io_args_t ln_args = { .arg1.path = link_target, .arg2.target = dst, .arg3.crs = crs, .cancellable = cancellable, .result = args->result, }; if(get_link_target(src, link_target, sizeof(link_target)) != 0) { (void)ioe_errlst_append(&args->result.errors, src, IO_ERR_UNKNOWN, "Failed to get symbolic link target"); return 1; } error = iop_ln(&ln_args); args->result = ln_args.result; if(error != 0) { (void)ioe_errlst_append(&args->result.errors, src, IO_ERR_UNKNOWN, "Failed to make symbolic link"); return 1; } return 0; } if(is_dir(src)) { (void)ioe_errlst_append(&args->result.errors, src, EISDIR, strerror(EISDIR)); return 1; } if(os_stat(src, &st) != 0) { (void)ioe_errlst_append(&args->result.errors, src, errno, strerror(errno)); return 1; } #ifndef _WIN32 /* Fifo/socket/device files don't need to be opened, their content is not * accessed. */ if(S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode) || S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode)) { in = NULL; } else #endif { in = os_fopen(src, "rb"); if(in == NULL) { (void)ioe_errlst_append(&args->result.errors, src, errno, strerror(errno)); return 1; } } if(crs == IO_CRS_APPEND_TO_FILES) { open_mode = "ab"; } else if(crs != IO_CRS_FAIL) { int ec; if(path_exists(dst, DEREF)) { /* Ask user whether to overwrite destination file. */ if(confirm != NULL && !confirm(args, src, dst)) { if(in != NULL && fclose(in) != 0) { (void)ioe_errlst_append(&args->result.errors, src, errno, strerror(errno)); } return 0; } } ec = unlink(dst); if(ec != 0 && errno != ENOENT) { (void)ioe_errlst_append(&args->result.errors, dst, errno, strerror(errno)); if(in != NULL && fclose(in) != 0) { (void)ioe_errlst_append(&args->result.errors, src, errno, strerror(errno)); } return ec; } /* XXX: possible improvement would be to generate temporary file name in the * destination directory, write to it and then overwrite destination file, * but this approach has disadvantage of requiring more free space on * destination file system. */ } else if(path_exists(dst, DEREF)) { (void)ioe_errlst_append(&args->result.errors, src, EEXIST, strerror(EEXIST)); if(in != NULL && fclose(in) != 0) { (void)ioe_errlst_append(&args->result.errors, src, errno, strerror(errno)); } return 1; } #ifndef _WIN32 /* Replicate fifo without even opening it. */ if(S_ISFIFO(st.st_mode)) { if(mkfifo(dst, st.st_mode & 07777) != 0) { (void)ioe_errlst_append(&args->result.errors, src, errno, strerror(errno)); return 1; } return 0; } /* Replicate socket or device file without even opening it. */ if(S_ISSOCK(st.st_mode) || S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode)) { if(mknod(dst, st.st_mode & (S_IFMT | 07777), st.st_rdev) != 0) { (void)ioe_errlst_append(&args->result.errors, src, errno, strerror(errno)); return 1; } return 0; } #endif out = os_fopen(dst, open_mode); if(out == NULL) { (void)ioe_errlst_append(&args->result.errors, dst, errno, strerror(errno)); if(fclose(in) != 0) { (void)ioe_errlst_append(&args->result.errors, src, errno, strerror(errno)); } return 1; } error = 0; if(crs == IO_CRS_APPEND_TO_FILES) { fpos_t pos; /* The following line is required for stupid Windows sometimes. Why? * Probably because it's stupid... Won't harm other systems. */ fseek(out, 0, SEEK_END); error = fgetpos(out, &pos) != 0 || fsetpos(in, &pos) != 0; if(!error) { ioeta_update(args->estim, NULL, NULL, 0, get_file_size(dst)); } } /* TODO: use sendfile() if platform supports it. */ while((nread = fread(&block, 1, sizeof(block), in)) != 0U) { if(cancellable && ui_cancellation_requested()) { error = 1; break; } if(fwrite(&block, 1, nread, out) != nread) { (void)ioe_errlst_append(&args->result.errors, dst, errno, strerror(errno)); error = 1; break; } ioeta_update(args->estim, NULL, NULL, 0, nread); } if(nread == 0U && !feof(in) && ferror(in)) { (void)ioe_errlst_append(&args->result.errors, src, errno, strerror(errno)); } if(fclose(in) != 0) { (void)ioe_errlst_append(&args->result.errors, src, errno, strerror(errno)); } if(fclose(out) != 0) { (void)ioe_errlst_append(&args->result.errors, dst, errno, strerror(errno)); } if(error == 0 && os_lstat(src, &src_st) == 0) { error = os_chmod(dst, src_st.st_mode & 07777); if(error != 0) { (void)ioe_errlst_append(&args->result.errors, dst, errno, strerror(errno)); } } ioeta_update(args->estim, NULL, NULL, 1, 0); return error; } #ifdef _WIN32 static DWORD CALLBACK win_progress_cb(LARGE_INTEGER total, LARGE_INTEGER transferred, LARGE_INTEGER stream_size, LARGE_INTEGER stream_transfered, DWORD stream_num, DWORD reason, HANDLE src_file, HANDLE dst_file, LPVOID param) { static LONGLONG last_size; io_args_t *const args = param; const char *const src = args->arg1.src; const char *const dst = args->arg2.dst; ioeta_estim_t *const estim = args->estim; if(transferred.QuadPart < last_size) { last_size = 0; } ioeta_update(estim, src, dst, 0, transferred.QuadPart - last_size); last_size = transferred.QuadPart; if(args->cancellable && ui_cancellation_requested()) { return PROGRESS_CANCEL; } return PROGRESS_CONTINUE; } #endif /* TODO: implement iop_chown(). */ int iop_chown(io_args_t *const args); /* TODO: implement iop_chgrp(). */ int iop_chgrp(io_args_t *const args); /* TODO: implement iop_chmod(). */ int iop_chmod(io_args_t *const args); int iop_ln(io_args_t *const args) { const char *const path = args->arg1.path; const char *const target = args->arg2.target; const int overwrite = args->arg3.crs != IO_CRS_FAIL; int result; #ifdef _WIN32 char cmd[6 + PATH_MAX*2 + 1]; char *escaped_path, *escaped_target; char base_dir[PATH_MAX + 2]; #endif #ifndef _WIN32 result = symlink(path, target); if(result != 0 && errno == EEXIST && overwrite && is_symlink(target)) { result = remove(target); if(result == 0) { result = symlink(path, target); if(result != 0) { (void)ioe_errlst_append(&args->result.errors, path, errno, strerror(errno)); } } else { (void)ioe_errlst_append(&args->result.errors, target, errno, strerror(errno)); } } else if(result != 0 && errno != 0) { (void)ioe_errlst_append(&args->result.errors, target, errno, strerror(errno)); } #else if(!overwrite && path_exists(target, DEREF)) { (void)ioe_errlst_append(&args->result.errors, target, EEXIST, strerror(EEXIST)); return -1; } if(overwrite && !is_symlink(target)) { (void)ioe_errlst_append(&args->result.errors, target, IO_ERR_UNKNOWN, "Target is not a symbolic link"); return -1; } escaped_path = shell_like_escape(path, 0); escaped_target = shell_like_escape(target, 0); if(escaped_path == NULL || escaped_target == NULL) { (void)ioe_errlst_append(&args->result.errors, target, IO_ERR_UNKNOWN, "Not enough memory"); free(escaped_target); free(escaped_path); return -1; } if(GetModuleFileNameA(NULL, base_dir, ARRAY_LEN(base_dir)) == 0) { (void)ioe_errlst_append(&args->result.errors, target, IO_ERR_UNKNOWN, "Failed to find win_helper"); free(escaped_target); free(escaped_path); return -1; } break_atr(base_dir, '\\'); snprintf(cmd, sizeof(cmd), "%s\\win_helper -s %s %s", base_dir, escaped_path, escaped_target); result = os_system(cmd); if(result != 0) { (void)ioe_errlst_append(&args->result.errors, target, IO_ERR_UNKNOWN, "Running win_helper has failed"); } free(escaped_target); free(escaped_path); #endif return result; }
void CCommonSeqReference::OutputRefrence( const char* szFileName ) { char charEnter[4] = {0x0D,0x00,0x0A,0x00}; char charTab[2] = {0x09,0x00}; vector<wstring> vecColName; vecColName.push_back(L"Project 1"); vecColName.push_back(L"Key 1"); vecColName.push_back(L"Project 2"); vecColName.push_back(L"Key 2"); vecColName.push_back(L"Mode of Referency"); vecColName.push_back(L"Reference Description"); CreateFileDirectory(szFileName); ofstream ofsRefrence(szFileName, ios_base::binary | ios_base::out); char headArray[2]; headArray[0] = uint8(15*16+15); headArray[1] = uint8(15*16+14); ofsRefrence.write(headArray, 2); for (int i=0; i<(int)(vecColName.size()-1); i++) { ofsRefrence.write((const char*)vecColName[i].c_str(), vecColName[i].length()*2); ofsRefrence.write(charTab, 2); } ofsRefrence.write((const char*)vecColName[vecColName.size()-1].c_str(), vecColName[vecColName.size()-1].length()*2); ofsRefrence.write(charEnter, 4); typedef hash_map<string, uint32>::iterator IterHmapSU; uint32 uCommSeqIndex; char szCommonIndex[2048]; string strSrcIndex; string strSrcProject; string strSrcKey; string strCommonProject; string strCommonKey; wchar_t* szMode = L"two-way"; //wchar_t* szRefDesc = L"690108"; wchar_t* szRefDesc = L"similar_content"; for (IterHmapSU iter=s_hmapSrcIndex2CommSeqIndex.begin(); iter!=s_hmapSrcIndex2CommSeqIndex.end(); ++iter) { strSrcIndex = iter->first; uCommSeqIndex = iter->second; _i64toa(uCommSeqIndex, szCommonIndex, 10); strSrcProject = GetProject(s_hmapSrcIndex2FileName[strSrcIndex]); strSrcKey = GetKeyPrefix(s_hmapSrcIndex2FileName[strSrcIndex]) + strSrcIndex; strCommonProject = GetProject(m_strCommonFileName); strCommonKey = GetKeyPrefix(m_strCommonFileName) + szCommonIndex; ofsRefrence.write((const char*)utf8_to_utf16(strSrcProject).c_str(), utf8_to_utf16(strSrcProject).length()*2); ofsRefrence.write(charTab, 2); ofsRefrence.write((const char*)utf8_to_utf16(strSrcKey).c_str(), utf8_to_utf16(strSrcKey).length()*2); ofsRefrence.write(charTab, 2); ofsRefrence.write((const char*)utf8_to_utf16(strCommonProject).c_str(), utf8_to_utf16(strCommonProject).length()*2); ofsRefrence.write(charTab, 2); ofsRefrence.write((const char*)utf8_to_utf16(strCommonKey).c_str(), utf8_to_utf16(strCommonKey).length()*2); ofsRefrence.write(charTab, 2); ofsRefrence.write((char*)szMode, wcslen(szMode)*2); ofsRefrence.write(charTab, 2); ofsRefrence.write((char*)szRefDesc, wcslen(szRefDesc)*2); ofsRefrence.write(charEnter, 4); } ofsRefrence.close(); }
static utf16_string utf(utf8_char const* str, size_t size) { return utf8_to_utf16(str, size); }
/* * Prepare a host kvp msg based on user kvp msg (utf8 to utf16) */ static int hv_kvp_convert_usermsg_to_hostmsg(struct hv_kvp_msg *umsg, struct hv_kvp_msg *hmsg) { int hkey_len = 0, hvalue_len = 0, utf_err = 0; struct hv_kvp_exchg_msg_value *host_exchg_data; char *key_name, *value; struct hv_kvp_ip_msg *host_ip_msg = (struct hv_kvp_ip_msg *)hmsg; switch (hmsg->kvp_hdr.operation) { case HV_KVP_OP_GET_IP_INFO: return (hv_kvp_convert_utf8_ipinfo_to_utf16(umsg, host_ip_msg)); case HV_KVP_OP_SET_IP_INFO: case HV_KVP_OP_SET: case HV_KVP_OP_DELETE: return (KVP_SUCCESS); case HV_KVP_OP_ENUMERATE: host_exchg_data = &hmsg->body.kvp_enum_data.data; key_name = umsg->body.kvp_enum_data.data.key; hkey_len = utf8_to_utf16((uint16_t *)host_exchg_data->key, ((HV_KVP_EXCHANGE_MAX_KEY_SIZE / 2) - 2), key_name, strlen(key_name), 1, &utf_err); /* utf16 encoding */ host_exchg_data->key_size = 2 * (hkey_len + 1); value = umsg->body.kvp_enum_data.data.msg_value.value; hvalue_len = utf8_to_utf16( (uint16_t *)host_exchg_data->msg_value.value, ((HV_KVP_EXCHANGE_MAX_VALUE_SIZE / 2) - 2), value, strlen(value), 1, &utf_err); host_exchg_data->value_size = 2 * (hvalue_len + 1); host_exchg_data->value_type = HV_REG_SZ; if ((hkey_len < 0) || (hvalue_len < 0)) return (HV_KVP_E_FAIL); return (KVP_SUCCESS); case HV_KVP_OP_GET: host_exchg_data = &hmsg->body.kvp_get.data; value = umsg->body.kvp_get.data.msg_value.value; hvalue_len = utf8_to_utf16( (uint16_t *)host_exchg_data->msg_value.value, ((HV_KVP_EXCHANGE_MAX_VALUE_SIZE / 2) - 2), value, strlen(value), 1, &utf_err); /* Convert value size to uft16 */ host_exchg_data->value_size = 2 * (hvalue_len + 1); /* Use values by string */ host_exchg_data->value_type = HV_REG_SZ; if ((hkey_len < 0) || (hvalue_len < 0)) return (HV_KVP_E_FAIL); return (KVP_SUCCESS); default: return (HV_KVP_E_FAIL); } }
int get_link_target(const char *link, char *buf, size_t buf_len) { LOG_FUNC_ENTER; #ifndef _WIN32 char *filename; ssize_t len; if(buf_len == 0) { return -1; } filename = strdup(link); chosp(filename); len = readlink(filename, buf, buf_len - 1); free(filename); if(len == -1) { return -1; } buf[len] = '\0'; return 0; #else char filename[PATH_MAX]; DWORD attr; wchar_t *utf16_filename; HANDLE hfile; char rdb[2048]; char *t; REPARSE_DATA_BUFFER *sbuf; WCHAR *path; if(!is_symlink(link)) { return -1; } copy_str(filename, sizeof(filename), link); chosp(filename); utf16_filename = utf8_to_utf16(filename); hfile = CreateFileW(utf16_filename, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL); free(utf16_filename); if(hfile == INVALID_HANDLE_VALUE) { LOG_WERROR(GetLastError()); return -1; } if(!DeviceIoControl(hfile, FSCTL_GET_REPARSE_POINT, NULL, 0, rdb, sizeof(rdb), &attr, NULL)) { LOG_WERROR(GetLastError()); CloseHandle(hfile); return -1; } CloseHandle(hfile); sbuf = (REPARSE_DATA_BUFFER *)rdb; path = sbuf->SymbolicLinkReparseBuffer.PathBuffer; path[sbuf->SymbolicLinkReparseBuffer.PrintNameOffset/sizeof(WCHAR) + sbuf->SymbolicLinkReparseBuffer.PrintNameLength/sizeof(WCHAR)] = L'\0'; t = to_multibyte(path + sbuf->SymbolicLinkReparseBuffer.PrintNameOffset/sizeof(WCHAR)); if(strncmp(t, "\\??\\", 4) == 0) strncpy(buf, t + 4, buf_len); else strncpy(buf, t, buf_len); buf[buf_len - 1] = '\0'; free(t); to_forward_slash(buf); return 0; #endif }
int render_character(FT_Face face, char *text){ FT_GlyphSlot slot; // FT_UInt glyph_index; FT_Vector pen; FT_Error error; int *text_int; int target_height; int n, num_chars; target_height = HEIGHT; if ( 1 > (num_chars = strlen( text )) ) return(0); if ( 0 == (text_int = new int[num_chars]) ){ return(-1); } if ( 0 > (num_chars = utf8_to_utf16(text, text_int)) ){ delete []text_int; return(-1); } /* use 50pt at 100dpi */ FT_F26Dot6 cs = (FT_F26Dot6)(CHARSIZE_Norm * (64 * 72.27 / 100)); error = FT_Set_Char_Size( face, cs, cs, 100, 100 ); /* set character size */ /* error handling omitted */ slot = face->glyph; pen.x = 8 * 64; pen.y = ( target_height /4 ) * 64; for ( int y=0 ; y<HEIGHT ; y++ ){ for ( int x=0 ; x<WIDTH ; x++ ){ image[y][x] = 0; } } for ( n = 0; n < num_chars; n++ ){ /* set transformation */ FT_Set_Transform( face, 0, &pen ); /* load glyph image into the slot (erase previous one) */ error = FT_Load_Char( face, text_int[n], FT_LOAD_RENDER ); // error = FT_Load_Char( face, 0x3042, FT_LOAD_RENDER ); if ( error ) continue; /* ignore errors */ /* now, draw to our target surface (convert position) */ draw_bitmap( &slot->bitmap, slot->bitmap_left, \ target_height - slot->bitmap_top ); /* increment pen position */ pen.x += slot->advance.x; pen.y += slot->advance.y; if ( pen.x > 64 * WIDTH ){ delete []text_int; return(1); } } delete []text_int; return(0); }
static void change(struct gpt_ent *ent, void *v) { uint8_t *name = v; utf8_to_utf16(name, ent->ent_name, __arraycount(ent->ent_name)); }
void CWndImageList::OnLvnKeydown(NMHDR *pNMHDR, LRESULT *pResult) { LPNMLVKEYDOWN pLVKeyDow = reinterpret_cast<LPNMLVKEYDOWN>(pNMHDR); // TODO: Add your control notification handler code here *pResult = 0; m_FileLoader.ShowWindow( SW_HIDE ); SQRWnd* pEditWnd = m_pWndGroup->GetEditWnd(); if( pEditWnd == NULL ) return; IMAGE_PARAM IP ( SM_BS_BK, m_nImageType ); WND_IMAGE_LIST* pImageList = pEditWnd->GetWndBkImage( IP ); if( pLVKeyDow->wVKey == VK_INSERT ) { string szTextName = ""; CFRect rt( 0.0f, 0.0f, float(pEditWnd->GetWndWidth()), float(pEditWnd->GetWndHeight()) ); CFPos pos(0.0f, 0.0f); unsigned uColor = 0xffffffff; unsigned uLockFlag = 0; if( m_nEditItem < pImageList->GetImageCount() ) { IMAGE& Image = pImageList->GetImage( m_nEditItem ); szTextName = Image.pTexture ? Image.pTexture->GetName() : ""; rt = Image.rtTexture; pos = Image.posWnd; uColor = Image.dwColor; uLockFlag = Image.dwLockFlag; } InsertItem( m_nEditItem, utf8_to_utf16(szTextName).c_str(), 0 ); pImageList->AddImage( pEditWnd->GetGraphic(), m_nEditItem, szTextName.c_str(), &rt, pos, uColor, uLockFlag ); } if( pLVKeyDow->wVKey == VK_ADD ) { m_nEditItem = GetItemCount(); InsertItem( m_nEditItem, L"", 0 ); CFRect rt( 0.0f, 0.0f, float(pEditWnd->GetWndWidth()), float(pEditWnd->GetWndHeight()) ); pImageList->AddImage( pEditWnd->GetGraphic(), m_nEditItem, "", &rt, CFPos(0.0f, 0.0f), 0xffffffff, 0 ); } //解决无法删除最后一张贴图和删除列表最下面的贴图宕掉的问题(方法有待再考虑) if( pLVKeyDow->wVKey == VK_DELETE ) { if (m_nEditItem != pImageList->GetImageCount()-1) { pImageList->DeleteImage( m_nEditItem ); DeleteItem( m_nEditItem ); m_nEditItem = 0; } else { string szTextName = ""; CFRect rt( 0.0f, 0.0f, float(pEditWnd->GetWndWidth()), float(pEditWnd->GetWndHeight()) ); CFPos pos(0.0f, 0.0f); unsigned uColor = 0xffffffff; unsigned uLockFlag = 0; if( m_nEditItem < pImageList->GetImageCount() ) { IMAGE& Image = pImageList->GetImage( m_nEditItem ); szTextName = ""; rt = Image.rtTexture; pos = Image.posWnd; uColor = 0x00ffffff; uLockFlag = Image.dwLockFlag; } InsertItem( m_nEditItem, utf8_to_utf16(szTextName).c_str(), 0 ); pImageList->AddImage( pEditWnd->GetGraphic(), m_nEditItem, szTextName.c_str(), &rt, pos, uColor, uLockFlag ); pImageList->DeleteImage( m_nEditItem + 1 ); DeleteItem( m_nEditItem + 1 ); m_nEditItem = 0; } } wchar_t Buf[256]; //按住空格键向左移动贴图 if( pLVKeyDow->wVKey == VK_LEFT && (GetKeyState( VK_SPACE )&0x8000) ) { if(!m_vecSelectItem.empty()) { for(int i = 0; i< int(m_vecSelectItem.size()); i++) { int tmp = m_vecSelectItem[i]; pImageList->GetImage(tmp).posWnd.x -= 1; SetItemText( 0, 1, _itow( int32(pImageList->GetImage(tmp).posWnd.x), Buf, 10 ) ); } } } //按住空格键向右移动贴图 if( pLVKeyDow->wVKey == VK_RIGHT && (GetKeyState( VK_SPACE )&0x8000) ) { if(!m_vecSelectItem.empty()) { for(int i = 0; i< int(m_vecSelectItem.size()); i++) { int tmp = m_vecSelectItem[i]; pImageList->GetImage(tmp).posWnd.x += 1; SetItemText( 0, 1, _itow( int32(pImageList->GetImage(tmp).posWnd.x), Buf, 10 ) ); } } } //按住空格键向上移动贴图 if( pLVKeyDow->wVKey == VK_UP && (GetKeyState( VK_SPACE )&0x8000) ) { if(!m_vecSelectItem.empty()) { for(int i = 0; i< int(m_vecSelectItem.size()); i++) { int tmp = m_vecSelectItem[i]; pImageList->GetImage(tmp).posWnd.y -= 1; SetItemText( 1, 1, _itow( int32(pImageList->GetImage(tmp).posWnd.y), Buf, 10 ) ); } } } //不按空格键移动贴图图层 else if( pLVKeyDow->wVKey == VK_UP && m_nEditItem > 0 ) { if( 1 != int(m_vecSelectItem.size())) return; m_vecSelectItem[0]--;//这里是用来控制贴图选择框的渲染 IMAGE Image = pImageList->GetImage( m_nEditItem - 1 ); pImageList->GetImage( m_nEditItem - 1 ) = pImageList->GetImage( m_nEditItem ); pImageList->GetImage( m_nEditItem ) = Image; SetItemText( m_nEditItem, 0, pImageList->GetImage( m_nEditItem ).pTexture ? utf8_to_utf16(pImageList->GetImage( m_nEditItem ).pTexture->GetName()).c_str() : L"" ); SetItemText( m_nEditItem - 1, 0, pImageList->GetImage( m_nEditItem - 1 ).pTexture ? utf8_to_utf16(pImageList->GetImage( m_nEditItem - 1 ).pTexture->GetName()).c_str() : L"" ); m_nEditItem--; } //按住空格键向下移动贴图 if( pLVKeyDow->wVKey == VK_DOWN && (GetKeyState( VK_SPACE )&0x8000) ) { if(!m_vecSelectItem.empty()) { for(int i = 0; i< int(m_vecSelectItem.size()); i++) { int tmp = m_vecSelectItem[i]; pImageList->GetImage(tmp).posWnd.y += 1; SetItemText( 1, 1, _itow( int32(pImageList->GetImage(tmp).posWnd.y), Buf, 10 ) ); } } } //不按空格键移动贴图图层 else if( pLVKeyDow->wVKey == VK_DOWN && m_nEditItem < pImageList->GetImageCount() - 1 ) { if( 1 != int(m_vecSelectItem.size())) return; m_vecSelectItem[0]++;//这里是用来控制贴图选择框的渲染 IMAGE Image = pImageList->GetImage( m_nEditItem + 1 ); pImageList->GetImage( m_nEditItem + 1 ) = pImageList->GetImage( m_nEditItem ); pImageList->GetImage( m_nEditItem ) = Image; SetItemText( m_nEditItem, 0, pImageList->GetImage( m_nEditItem ).pTexture ? utf8_to_utf16(pImageList->GetImage( m_nEditItem ).pTexture->GetName()).c_str() : L"" ); SetItemText( m_nEditItem + 1, 0, pImageList->GetImage( m_nEditItem + 1 ).pTexture ? utf8_to_utf16(pImageList->GetImage( m_nEditItem + 1 ).pTexture->GetName()).c_str() : L"" ); m_nEditItem++; } if( pLVKeyDow->wVKey == 'C' && ( GetKeyState( VK_CONTROL )&0x8000 ) ) { if (!m_vecSelectItem.empty()) { for (int i = 0; i < int(m_vecSelectItem.size()); i++) { m_ImageCopy.AddImageFromImageList(*pImageList,m_vecSelectItem[i],m_vecSelectItem[i]+1); } } m_vecSelectItem.clear(); pEditWnd->GetWndRect( m_rtWndCopy ); m_nEditItem = 0; } if( pLVKeyDow->wVKey == 'V' && ( GetKeyState( VK_CONTROL )&0x8000 ) ) { if (m_ImageCopy.GetImageCount() == 0 ) { return; } CFRect rtPre; pEditWnd->GetWndRect( rtPre ); pEditWnd->SetWndRect( m_rtWndCopy ); if (pImageList->GetImageCount() != 0 ) { int a = pImageList->GetImageCount(); pImageList->AddImageFromImageList(m_ImageCopy,0,m_ImageCopy.GetImageCount()); } pEditWnd->SetWndRect( rtPre ); IMAGE& Image = pImageList->GetImage( m_nEditItem ); m_ImageProp->ResetImageProp( &Image, m_pWndGroup ); SetEditImageType(m_nImageType); m_ImageCopy.ClearImage(); } if( pLVKeyDow->wVKey == 'D' && ( GetKeyState( VK_CONTROL )&0x8000 ) ) { CFRect rtPre; pEditWnd->GetWndRect( rtPre ); pEditWnd->SetWndRect( m_rtWndCopy ); for( int i = 0; i < m_ImageCopy.GetImageCount(); i++ ) { IMAGE& Image = m_ImageCopy.GetImage(i); pImageList->AddImage( pEditWnd->GetGraphic(), -1, Image.pTexture ? Image.pTexture->GetName() : "", &Image.rtTexture, Image.posWnd, Image.dwColor, Image.dwLockFlag ); } pEditWnd->SetWndRect( rtPre ); IMAGE& Image = pImageList->GetImage( m_nEditItem ); m_ImageProp->ResetImageProp( &Image, m_pWndGroup ); SetEditImageType(m_nImageType); } IMAGE& Image = pImageList->GetImage( m_nEditItem ); m_ImageProp->ResetImageProp( &Image, m_pWndGroup ); }
static int op_removesl(ops_t *ops, void *data, const char *src, const char *dst) { const char *const delete_prg = (ops == NULL) ? cfg.delete_prg : ops->delete_prg; if(delete_prg[0] != '\0') { #ifndef _WIN32 char *escaped; char cmd[2*PATH_MAX + 1]; const int cancellable = (data == NULL); escaped = shell_like_escape(src, 0); if(escaped == NULL) { return -1; } snprintf(cmd, sizeof(cmd), "%s %s", delete_prg, escaped); free(escaped); LOG_INFO_MSG("Running trash command: \"%s\"", cmd); return run_operation_command(ops, cmd, cancellable); #else char cmd[PATH_MAX*2 + 1]; snprintf(cmd, sizeof(cmd), "%s \"%s\"", delete_prg, src); to_back_slash(cmd); return os_system(cmd); #endif } if(!ops_uses_syscalls(ops)) { #ifndef _WIN32 char *escaped; char cmd[16 + PATH_MAX]; int result; const int cancellable = data == NULL; escaped = shell_like_escape(src, 0); if(escaped == NULL) return -1; snprintf(cmd, sizeof(cmd), "rm -rf %s", escaped); LOG_INFO_MSG("Running rm command: \"%s\"", cmd); result = run_operation_command(ops, cmd, cancellable); free(escaped); return result; #else if(is_dir(src)) { char path[PATH_MAX]; int err; copy_str(path, sizeof(path), src); to_back_slash(path); wchar_t *utf16_path = utf8_to_utf16(path); /* SHFileOperationW requires pFrom to be double-nul terminated. */ const size_t len = wcslen(utf16_path); utf16_path = reallocarray(utf16_path, len + 1U + 1U, sizeof(*utf16_path)); utf16_path[len + 1U] = L'\0'; SHFILEOPSTRUCTW fo = { .hwnd = NULL, .wFunc = FO_DELETE, .pFrom = utf16_path, .pTo = NULL, .fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI, }; err = SHFileOperationW(&fo); log_msg("Error: %d", err); free(utf16_path); return err; } else { int ok; wchar_t *const utf16_path = utf8_to_utf16(src); DWORD attributes = GetFileAttributesW(utf16_path); if(attributes & FILE_ATTRIBUTE_READONLY) { SetFileAttributesW(utf16_path, attributes & ~FILE_ATTRIBUTE_READONLY); } ok = DeleteFileW(utf16_path); if(!ok) { LOG_WERROR(GetLastError()); } free(utf16_path); return !ok; } #endif }