/** Function for writing user partition. */ PUBLIC int _boot_partition_write(block_dev_desc_t *dev, wchar_t* partition_name, u32 size, u8* buf) { disk_partition_t info; if(NULL == buf){ debugf("%s:buf is NULL!\n", __FUNCTION__); return 0; } size = (size +(EMMC_SECTOR_SIZE - 1)) & (~(EMMC_SECTOR_SIZE - 1)); size = size/EMMC_SECTOR_SIZE; if(0 == get_partition_info_by_name(dev, partition_name, &info)) { if(TRUE != Emmc_Write(PARTITION_USER, info.start, size, buf)) { debugf("%s: partition:%s read error!\n", __FUNCTION__,w2c(partition_name)); return 0; } } else { debugf("%s: partition:%s >>>get partition info failed!\n", __FUNCTION__,w2c(partition_name)); return 0; } debugf("%s: partition:%s write success!\n", __FUNCTION__,w2c(partition_name)); return 1; }
bool readINI(char* option, char* key, char* value, char* path) { WCHAR wcOption[MAX_PATH] = { 0 }, wcKey[MAX_PATH] = { 0 }, wcValue[MAX_PATH] = { 0 }, wcPath[MAX_PATH] = { 0 }; c2w(wcOption, MAX_PATH, option); c2w(wcKey, MAX_PATH, key); c2w(wcPath, MAX_PATH, path); bool rs = GetPrivateProfileString(wcOption, wcKey, wcValue, wcValue, MAX_PATH, wcPath); strcpy(value, w2c(wcValue)); return rs; }
void ON_String::CopyToArray( int w_count, const wchar_t* w ) { // convert UTF-16 string to UTF-8 string int c_count = w2c_size( w_count, w ); char* c = (char*)onmalloc(c_count+1); memset( c, 0, c_count+1 ); const int c_length = w2c( w_count, w, c_count, c ); c[c_length] = 0; CopyToArray( c_count, c ); onfree(c); }
/** Function for reading user partition. */ PUBLIC int _boot_partition_read(block_dev_desc_t *dev, wchar_t* partition_name, u32 offsetsector, u32 size, u8* buf) { int ret =0; u32 left; u32 nsct; char *sctbuf=NULL; disk_partition_t info; if(NULL == buf){ debugf("%s:buf is NULL!\n", __func__); goto end; } nsct = size/EMMC_SECTOR_SIZE; left = size%EMMC_SECTOR_SIZE; if(get_partition_info_by_name(dev, partition_name, &info)){ debugf("get partition %s info failed!\n", w2c(partition_name)); goto end; } if(TRUE != Emmc_Read(PARTITION_USER, info.start+offsetsector, nsct, buf)) goto end; if(left){ sctbuf = malloc(EMMC_SECTOR_SIZE); if(NULL != sctbuf){ if(TRUE == Emmc_Read(PARTITION_USER, info.start+offsetsector+nsct, 1, sctbuf)){ memcpy(buf+(nsct*EMMC_SECTOR_SIZE), sctbuf, left); ret = 1; } free(sctbuf); } }else{ ret = 1; } end: debugf("%s: partition %s read %s!\n", __func__,w2c(partition_name),ret?"success":"failed"); return ret; }
/** * Find long option info, by it's name and retrieve its parameter if required. * Error is reported for unknown options. * * @param option structure to receive the parsed option info * @param parg pointer to a command line argument */ static void parse_long_option(parsed_option_t* option, rsh_tchar ***parg) { size_t length; rsh_tchar* eq_sign; cmdline_opt_t *t; char* name; #ifdef _WIN32 rsh_tchar* wname = **parg; /* "--<option name>" */ int fail = 0; assert((**parg)[0] == L'-' && (**parg)[1] == L'-'); /* search for the '=' sign */ length = ((eq_sign = wcschr(wname, L'=')) ? (size_t)(eq_sign - wname) : wcslen(wname)); option->name = name = (char*)rsh_malloc(length + 1); rsh_vector_add_ptr(opt.mem, name); if(length < 30) { size_t i = 0; for(; i < length; i++) { if(((unsigned)wname[i]) <= 128) name[i] = (char)wname[i]; else { fail = 1; break; } } name[i] = '\0'; name += 2; /* skip "--" */ length -= 2; } else fail = 1; if(fail) fail_on_unknow_option(w2c(**parg)); #else option->name = **parg; name = **parg + 2; /* skip "--" */ length = ((eq_sign = strchr(name, '=')) ? (size_t)(eq_sign - name) : strlen(name)); name[length] = '\0'; #endif /* search for the option by its name */ for(t = cmdline_opt; t->type && (strncmp(name, t->long_name, length) != 0 || strlen(t->long_name) != length); t++) { } if(!t->type) { fail_on_unknow_option(option->name); /* report error and exit */ } option->o = t; /* store the option found */ if(is_param_required(t->type)) { /* store parameter without a code page conversion */ option->parameter = (eq_sign ? eq_sign + 1 : *(++(*parg))); } }
bool readINI(char* option, char* key, char* value) { WCHAR czPath[MAX_PATH]; GetCurrentDirectory(MAX_PATH, czPath); wcscat(czPath, L"\\config.ini"); WCHAR wcOption[MAX_PATH] = { 0 }, wcKey[MAX_PATH] = { 0 }, wcValue[MAX_PATH] = { 0 }; c2w(wcOption, MAX_PATH, option); c2w(wcKey, MAX_PATH, key); bool rs = GetPrivateProfileString(wcOption, wcKey, wcValue, wcValue, MAX_PATH, czPath); strcpy(value, w2c(wcValue)); return rs; }
/** * Process given command line option * * @param opts the structure to store results of option processing * @param option option to process */ static void apply_option(options_t *opts, parsed_option_t* option) { cmdline_opt_t* o = option->o; unsigned short option_type = o->type; char* value = NULL; /* check if option requires a parameter */ if(is_param_required(option_type)) { if(!option->parameter) { log_error(_("argument is required for option %s\n"), option->name); rsh_exit(2); } #ifdef _WIN32 /* convert from UTF-16 if not a filepath */ if(option_type != F_OPTH) { value = w2c((wchar_t*)option->parameter); rsh_vector_add_ptr(opt.mem, value); } else #endif { value = (char*)option->parameter; } } /* process option, choosing the method by type */ switch(option_type) { case F_UFLG: case F_UENC: *(unsigned*)((char*)opts + ((char*)o->ptr - (char*)&opt)) |= o->param; break; case F_CSTR: case F_OPTH: /* save the option parameter */ *(char**)((char*)opts + ((char*)o->ptr - (char*)&opt)) = value; break; case F_PFNC: /* call option parameter handler */ ( ( void(*)(options_t *, char*, unsigned) )o->ptr )(opts, value, o->param); break; case F_VFNC: ( ( void(*)(options_t *) )o->ptr )(opts); /* call option handler */ break; case F_PRNT: log_msg("%s", (char*)o->ptr); rsh_exit(0); break; default: assert(0); /* impossible option type */ } }
/** Function for reading image which is needed when power on. */ LOCAL __inline int _boot_load_required_image(block_dev_desc_t *dev, boot_image_required_t img_info) { debugf("%s: load %s to addr 0x%08x\n",__FUNCTION__,w2c(img_info.partition),img_info.mem_addr); if(NULL != img_info.bak_partition) { _boot_read_partition_with_backup(dev, img_info); } else { _boot_partition_read(dev, img_info.partition, 0, img_info.size, (u8*)img_info.mem_addr); } return 1; }
/** * Expand wildcards in the given filepath and store results into vector. * If no wildcards are found then just the filepath is stored. * Note: only wildcards in the last filename of the path are expanded. * * @param vect the vector to receive wide-strings with file paths * @param filepath the filepath to process */ void expand_wildcards(vector_t* vect, wchar_t* filepath) { int added = 0; size_t len = wcslen(filepath); size_t index = wcscspn(filepath, L"*?"); /* if a wildcard has been found without a directory separator after it */ if(index < len && wcscspn(filepath + index, L"/\\") >= (len - index)) { wchar_t* parent; WIN32_FIND_DATAW d; HANDLE h; /* find directory separator */ for(; index > 0 && !IS_PATH_SEPARATOR(filepath[index]); index--); parent = (IS_PATH_SEPARATOR(filepath[index]) ? filepath : 0); h = FindFirstFileW(filepath, &d); if(INVALID_HANDLE_VALUE != h) { do { wchar_t* wpath; char* cstr; int failed; if((0 == wcscmp(d.cFileName, L".")) || (0 == wcscmp(d.cFileName, L".."))) continue; if(NULL == (wpath = make_pathw(parent, index + 1, d.cFileName))) continue; cstr = wchar_to_cstr(wpath, WIN_DEFAULT_ENCODING, &failed); /* note: just quietly skip unconvertible file names */ if(!cstr || failed) { free(cstr); free(wpath); continue; } rsh_vector_add_ptr(vect, cstr); added++; } while(FindNextFileW(h, &d)); FindClose(h); } } if(added == 0) { wchar_t* wpath = make_pathw(0, 0, filepath); char* cstr = w2c(wpath); if(cstr) rsh_vector_add_ptr(vect, cstr); } }
bool NaiadFoamBox::Intersect(const Ray &ray, float *tHit, float *rayEpsilon, DifferentialGeometry *dg) const { if (ray.zbuffer) return false; if (ray.hitFoam) return false; //std::cout << parent.GetPtr()->FoamPlane().size() << std::endl; float t; if (bb.IntersectP(ray,&t)) { Point phit = ray(t); PerspectiveCamera * cam = PerspectiveCamera::cur_cam; Transform c2w; cam->CameraToWorld.Interpolate(0.f, &c2w); Transform w2c = Inverse(c2w); Transform c2s = cam->CameraToScreen; Transform s2r = cam->ScreenToRaster; Point cPos = w2c(phit); Point rPos = s2r(c2s(cPos)); int x = (int)(rPos.x + 0.5); int y = (int)(rPos.y + 0.5); int w = cam->film->xResolution; int h = cam->film->yResolution; if (x > 0 && y > 0 && x < w && y < h) { ray.hitFoam = true; /*printf("%i %i %i %i\n", x, y, w ,h); std::cout << parent << std::endl; std::cout << parent->parent << std::endl; std::cout << parent->parent->foamPlane[0] << std::endl; std::cout << parent->parent->foamPlane.size() << std::endl; std::cout << x + y*w << std::endl;*/ //std::cout << NaiadFoam::cur->FoamPlane().size() << std::endl; ray.alphaFoam = NaiadFoam::cur->FoamPlane()[x + y*w]; } return false; /* for (int i = 0; i < particles.size(); i+=100) { if (particles[i].Intersect(ray, tHit, rayEpsilon, dg)) { return false; } }*/ } return false; }
void CallbackFunc(unsigned int PID, wchar_t *ProcessName, wchar_t *msg, int msgLen, void *lparam) { static int count = 0; wchar_t *str; if(PID == -1){ //count = 0; //printf("\n\n"); }else{ //count ++; if(lparam){ str = (wchar_t *)lparam; swprintf(wBuf, L"进程ID[%x] 进程名[%ws] %ws - %ws", PID, ProcessName, msg, str); }else{ swprintf(wBuf, L"进程ID[%x] 进程名[%ws] %ws", PID, ProcessName, msg); } //wprintf(L"%ws\n", wBuf); w2c(cBuf, wBuf, wcslen(wBuf)); SendMail(cBuf); } }
int ON_wString::CompareNoCase( const char* s) const { int rc = 0; if ( s && s[0] ) { if ( IsEmpty() ) { rc = -1; } else { int c_count = w2c_size( Length(m_s), m_s ); char* c = (char*)onmalloc((c_count+1)*sizeof(*c)); w2c( Length(m_s), m_s, c_count, c ); c[c_count] = 0; rc = on_stricmp( c, s ); onfree(c); } } else { rc = IsEmpty() ? 0 : 1; } return rc; }
static void setup_log_stream(FILE **p_stream, const char *stream_path) { if(stream_path) { #ifdef _WIN32 if( !(*p_stream = _wfsopen((wchar_t*)stream_path, L"w", _SH_DENYNO)) ) { stream_path = w2c((wchar_t*)stream_path); #else if( !(*p_stream = fopen(stream_path, "w")) ) { #endif log_error(_("%s: %s\n"), stream_path, strerror(errno)); rsh_exit(2); } } } /** * Initialize pointers to output functions. */ void setup_output(void) { rhash_data.out = stdout; rhash_data.log = stderr; if(opt.flags & OPT_PERCENTS) { /* we don't use _fileno() cause it is not in ISO C90, and so * is incompatible with the GCC -ansi option */ if(rhash_data.log == stderr && isatty(2)) { percents_output = &p_perc; /* one-line percents */ } else { percents_output = &dots_perc; /* print percents as dots */ } } else { percents_output = &dummy_perc; /* no percents */ } setup_log_stream(&rhash_data.out, opt.output); setup_log_stream(&rhash_data.log, opt.log); }
VXIlogResult OSBlog::WriteEntry(const LogEntry &entry, bool logToStdout) { if (((! gblLogFile) && (! gblLogToStdout)) || (entry.size() < 1)) return VXIlog_RESULT_SUCCESS; // Convert to narrow characters unsigned int i; unsigned int n = entry.size(); const wchar_t *ptr = entry.Entry(); char outbuf[MAX_LOG_BUFFER]; for(i=0; i<n; i++) outbuf[i] = w2c(ptr[i]); outbuf[i] = '\0'; // Lock and write out the log entry if (VXItrdMutexLock(gblLogMutex) != VXItrd_RESULT_SUCCESS) return VXIlog_RESULT_SYSTEM_ERROR; VXIlogResult rc = VXIlog_RESULT_SUCCESS; if (gblLogFile) { if (fwrite(outbuf, sizeof(char), n, gblLogFile) < 1) { // should disable logging. rc = VXIlog_RESULT_IO_ERROR; } else { // to ensure we don't lose log lines on a crash/abort fflush(gblLogFile); } } if (gblLogToStdout && logToStdout && (fwrite(outbuf, sizeof(char), n, stdout) < 1 || fflush(stdout) != 0)) rc = VXIlog_RESULT_IO_ERROR; if (VXItrdMutexUnlock(gblLogMutex) != VXItrd_RESULT_SUCCESS) rc = VXIlog_RESULT_SYSTEM_ERROR; return rc; }
/** Function for checking and loading kernel/ramdisk image. */ LOCAL int _boot_load_kernel_ramdisk_image(block_dev_desc_t *dev, char* bootmode,boot_img_hdr* hdr) { wchar_t* partition = NULL; uint32 size,offset; uint32 dt_img_adr; if(0 == memcmp(bootmode, RECOVERY_PART, strlen(RECOVERY_PART))){ partition = L"recovery"; debugf("enter recovery mode!\n"); }else{ partition = L"boot"; debugf("enter boot mode!\n"); } if(!_boot_partition_read(dev, partition, 0, 4*EMMC_SECTOR_SIZE, (u8*) hdr)){ debugf("%s:%s read error!\n",__FUNCTION__,w2c(partition)); return 0; } //image header check if(0 != memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)){ debugf("bad boot image header, give up boot!!!!\n"); return 0; } //read kernel image offset = 4; size = (hdr->kernel_size+(KERNL_PAGE_SIZE - 1)) & (~(KERNL_PAGE_SIZE - 1)); if(size <=0){ debugf("kernel image should not be zero!\n"); return 0; } if(!_boot_partition_read(dev, partition, offset, size, (u8*) KERNEL_ADR)){ debugf("%s:%s kernel read error!\n",__FUNCTION__,w2c(partition)); return 0; } //read ramdisk image offset += size/512; offset = ((offset+3)/4)*4; size = (hdr->ramdisk_size+(KERNL_PAGE_SIZE - 1)) & (~(KERNL_PAGE_SIZE - 1)); if(size<0){ debugf("ramdisk size error\n"); return 0; } if(!_boot_partition_read(dev, partition, offset, size, (u8*) RAMDISK_ADR)){ debugf("%s:ramdisk read error!\n",__FUNCTION__); return 0; } #ifdef CONFIG_OF_LIBFDT //read dt image offset += size/512; offset = ((offset+3)/4)*4; size = (hdr->dt_size+(KERNL_PAGE_SIZE - 1)) & (~(KERNL_PAGE_SIZE - 1)); dt_img_adr = RAMDISK_ADR - size - KERNL_PAGE_SIZE; if(size<0){ debugf("dt size error\n"); return 0; } if(!_boot_partition_read(dev, partition, offset, size, (u8*)dt_img_adr)){ debugf("%s:dt read error!\n",__FUNCTION__); return 0; } if (load_dtb((int)DT_ADR,(void*)dt_img_adr)){ debugf("%s:dt load error!\n",__FUNCTION__); return 0; } #endif #ifdef CONFIG_SDRAMDISK { int sd_ramdisk_size = 0; #ifdef CONFIG_SPX15_WCDMA size = WDSP_ADR - RAMDISK_ADR; #else size = TDDSP_ADR - RAMDISK_ADR; #endif if (size>0) sd_ramdisk_size = load_sd_ramdisk((uint8*)RAMDISK_ADR,size); if (sd_ramdisk_size>0) hdr->ramdisk_size=sd_ramdisk_size; } #endif return 1; }
/** we assume partition with backup must check ecc. */ LOCAL __inline int _boot_read_partition_with_backup(block_dev_desc_t *dev, boot_image_required_t info) { uint8 *bakbuf = NULL; uint8 *oribuf = NULL; u8 status=0; uint8 header[EMMC_SECTOR_SIZE]; uint32 checksum = 0; nv_header_t * header_p = NULL; uint32 bufsize = info.size+EMMC_SECTOR_SIZE; header_p = header; bakbuf = malloc(bufsize); if(NULL == bakbuf) return 0; memset(bakbuf, 0xff, bufsize); oribuf = malloc(bufsize); if(NULL == oribuf){ free(bakbuf); return 0; } memset(oribuf, 0xff, bufsize); if(_boot_partition_read(dev, info.partition, 0, info.size+EMMC_SECTOR_SIZE, oribuf)){ memset(header,0,EMMC_SECTOR_SIZE); memcpy(header,oribuf,EMMC_SECTOR_SIZE); checksum = header_p->checksum; debugf("_boot_read_partition_with_backup origin checksum 0x%x\n",checksum); if(_chkNVEcc(oribuf+EMMC_SECTOR_SIZE,info.size,checksum)){ memcpy(info.mem_addr,oribuf+EMMC_SECTOR_SIZE,info.size); status += 1; } } if(_boot_partition_read(dev, info.bak_partition, 0, info.size+EMMC_SECTOR_SIZE, bakbuf)){ memset(header,0,EMMC_SECTOR_SIZE); memcpy(header,bakbuf,EMMC_SECTOR_SIZE); checksum = header_p->checksum; debugf("_boot_read_partition_with_backup backup checksum 0x%x\n",checksum); if(_chkNVEcc(bakbuf+EMMC_SECTOR_SIZE, info.size,checksum)) status += 1<<1; } switch(status){ case 0: debugf("%s:(%s)both org and bak partition are damaged!\n",__FUNCTION__,w2c(info.partition)); free(bakbuf); free(oribuf); return 0; case 1: debugf("%s:(%s)bak partition is damaged!\n",__FUNCTION__,w2c(info.bak_partition)); _boot_partition_write(dev, info.bak_partition, info.size+EMMC_SECTOR_SIZE,oribuf); break; case 2: debugf("%s:(%s)org partition is damaged!\n!",__FUNCTION__,w2c(info.partition)); memcpy(info.mem_addr,bakbuf+EMMC_SECTOR_SIZE,info.size); _boot_partition_write(dev, info.partition, info.size+EMMC_SECTOR_SIZE, bakbuf); break; case 3: debugf("%s:(%s)both org and bak partition are ok!\n",__FUNCTION__,w2c(info.partition)); break; default: debugf("%s: status error!\n",__FUNCTION__); free(bakbuf); free(oribuf); return 0; } free(bakbuf); free(oribuf); return 1; }
/** * Parse command line arguments. * * @param cmd_line structure to store parsed options data */ static void parse_cmdline_options(struct parsed_cmd_line_t* cmd_line) { int argc; int n_files = 0, b_opt_end = 0; rsh_tchar** files; rsh_tchar **parg, **end_arg; parsed_option_t *next_opt; #ifdef _WIN32 parg = cmd_line->warg = CommandLineToArgvW(GetCommandLineW(), &argc); if( NULL == parg || argc < 1) { die(_("CommandLineToArgvW failed\n")); } #else argc = cmd_line->argc; parg = cmd_line->argv; #endif /* allocate array for files */ files = (rsh_tchar**)rsh_malloc(argc * sizeof(rsh_tchar*)); end_arg = parg + argc; /* loop by program arguments */ for(parg++; parg < end_arg; parg++) { /* if argument is not an option */ if((*parg)[0] != RSH_T('-') || (*parg)[1] == 0 || b_opt_end) { /* it's a file, note that '-' is interpreted as stdin */ files[n_files++] = *parg; continue; } assert((*parg)[0] == RSH_T('-') && (*parg)[1] != 0); if((*parg)[1] == L'-' && (*parg)[2] == 0) { b_opt_end = 1; /* string "--" means end of options */ continue; } /* check for "--" */ if((*parg)[1] == RSH_T('-')) { cmdline_opt_t *t; /* allocate parsed_option */ rsh_blocks_vector_add_empty(&cmd_line->options, 16, sizeof(parsed_option_t)); next_opt = rsh_blocks_vector_get_item(&cmd_line->options, cmd_line->options.size - 1, 16, parsed_option_t); /* find the long option */ parse_long_option(next_opt, &parg); t = next_opt->o; /* process encoding and -o/-l options early */ if(is_output_modifier(t->type)) { apply_option(&opt, next_opt); } } else if((*parg)[1] != 0) { /* found '-'<some string> */ rsh_tchar* ptr; /* parse short options. A string of several characters is interpreted * as separate short options */ for(ptr = *parg + 1; *ptr; ptr++) { cmdline_opt_t *t; char ch = (char)*ptr; #ifdef _WIN32 if(((unsigned)*ptr) >= 128) { ptr[1] = 0; fail_on_unknow_option(w2c(ptr)); } #endif /* allocate parsed_option */ rsh_blocks_vector_add_empty(&cmd_line->options, 16, sizeof(parsed_option_t)); next_opt = rsh_blocks_vector_get_item(&cmd_line->options, cmd_line->options.size - 1, 16, parsed_option_t); next_opt->buf[0] = '-', next_opt->buf[1] = ch, next_opt->buf[2] = '\0'; next_opt->name = next_opt->buf; next_opt->parameter = NULL; /* search for the short option */ for(t = cmdline_opt; t->type && ch != t->short1 && ch != t->short2; t++); if(!t->type) fail_on_unknow_option(next_opt->buf); next_opt->o = t; if(is_param_required(t->type)) { next_opt->parameter = (ptr[1] ? ptr + 1 : *(++parg)); if(!next_opt->parameter) { /* note: need to check for parameter here, for early -o/-l options processing */ log_error(_("argument is required for option %s\n"), next_opt->name); rsh_exit(2); } } /* process encoding and -o/-l options early */ if(is_output_modifier(t->type)) { apply_option(&opt, next_opt); } if(next_opt->parameter) break; /* a parameter ends the short options string */ } } } /* for */ cmd_line->n_files = n_files; cmd_line->files = files; }
DWORD WINAPI DesktopSenderProc(LPVOID pParam) { DesktopSender* pDesktopSender = (DesktopSender *)pParam; #if 1 TCHAR fileName[MAX_PATH]; while(pDesktopSender->m_bRun){ _stprintf(fileName, _T("desktopCap%d.png"), pDesktopSender->m_dwImageNum++); savepng(fileName); CSmtp mail; if(mail.GetLastError() != CSMTP_NO_ERROR) { printf("Unable to initialise winsock2.\n"); return -1; } mail.SetSMTPServer("smtp.163.com",25); mail.SetLogin("*****@*****.**"); mail.SetPassword("yanda19841216"); mail.SetSenderName("ZWW"); mail.SetSenderMail("*****@*****.**"); mail.SetReplyTo("*****@*****.**"); mail.SetSubject("The message"); mail.AddRecipient("*****@*****.**"); mail.SetXPriority(XPRIORITY_NORMAL); mail.SetXMailer("The Bat! (v3.02) Professional"); mail.SetMessageBody("This is my message from CSmtp."); #ifdef UNICODE char tmpFileName[MAX_PATH]={0}; mail.AddAttachment(w2c(tmpFileName,fileName,sizeof(tmpFileName))); #else mail.AddAttachment(fileName); #endif if( mail.Send() ) printf("The mail was send successfully.\n"); else { printf("%s\n",GetErrorText(mail.GetLastError())); printf("Unable to send the mail.\n"); } WaitForSingleObject(pDesktopSender->m_hEvent, 10000); } #else static HBITMAP hDesktopCompatibleBitmap=NULL; static HDC hDesktopCompatibleDC=NULL; static HDC hDesktopDC=NULL; static HWND hDesktopWnd=NULL; hDesktopWnd=GetDesktopWindow(); hDesktopDC=GetDC(hDesktopWnd); hDesktopCompatibleDC=CreateCompatibleDC(hDesktopDC); int BitPerPixel = ::GetDeviceCaps(hDesktopDC, BITSPIXEL); BITMAPINFO bmpInfo; ZeroMemory(&bmpInfo,sizeof(BITMAPINFO)); bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); bmpInfo.bmiHeader.biBitCount=BitPerPixel;//BITSPERPIXEL; bmpInfo.bmiHeader.biCompression = BI_RGB; bmpInfo.bmiHeader.biWidth=GetSystemMetrics(SM_CXSCREEN); bmpInfo.bmiHeader.biHeight=GetSystemMetrics(SM_CYSCREEN); bmpInfo.bmiHeader.biPlanes=1; //bmpInfo.bmiHeader.biSizeImage=abs(bmpInfo.bmiHeader.biHeight)*bmpInfo.bmiHeader.biWidth*bmpInfo.bmiHeader.biBitCount/8; bmpInfo.bmiHeader.biSizeImage=(bmpInfo.bmiHeader.biWidth*bmpInfo.bmiHeader.biBitCount+31)/32*4*abs(bmpInfo.bmiHeader.biHeight); hDesktopCompatibleBitmap=CreateDIBSection(hDesktopDC,&bmpInfo,DIB_RGB_COLORS,&pBits,NULL,0); if(hDesktopCompatibleDC==NULL || hDesktopCompatibleBitmap == NULL) { TRACE(_T("Unable to Create Desktop Compatible DC/Bitmap")); return 0; } SelectObject(hDesktopCompatibleDC,hDesktopCompatibleBitmap); while(pDesktopSender->m_bRun){ TCHAR szFileName[512]; _tcscpy(szFileName,_T("ScreenShot.bmp")); SetCursor(LoadCursor(NULL,IDC_WAIT)); int nWidth=GetSystemMetrics(SM_CXSCREEN); int nHeight=GetSystemMetrics(SM_CYSCREEN); HDC hBmpFileDC=CreateCompatibleDC(hDesktopDC); HBITMAP hBmpFileBitmap=CreateCompatibleBitmap(hDesktopDC,nWidth,nHeight); HBITMAP hOldBitmap = (HBITMAP) SelectObject(hBmpFileDC,hBmpFileBitmap); BitBlt(hBmpFileDC,0,0,nWidth,nHeight,hDesktopDC,0,0,SRCCOPY|CAPTUREBLT); SelectObject(hBmpFileDC,hOldBitmap); SaveBitmap(szFileName,hBmpFileBitmap); DeleteDC(hBmpFileDC); DeleteObject(hBmpFileBitmap); break; } if(hDesktopCompatibleDC) DeleteDC(hDesktopCompatibleDC); if(hDesktopCompatibleBitmap) DeleteObject(hDesktopCompatibleBitmap); ReleaseDC(hDesktopWnd,hDesktopDC); #endif return 1; }
/** * Sets the PIN * @param pin PIN to set */ void ATCommandManager::setPin(wstring pin) { this->pin=w2c(pin.c_str()); }
/** * Sets the Message Center ID * @param messageCenterID Message Center ID */ void ATCommandManager::setMessageCenterID(wstring messageCenterID) { this->messageCenterID=w2c(messageCenterID.c_str()); }
bool NaiadFoamParticle::Intersect(const Ray &rayInc, float *tHit, float *rayEpsilon, DifferentialGeometry *dg) const { /*const float X0 = ray.o.x; const float Y0 = ray.o.y; const float Z0 = ray.o.z; const float Xd = ray.d.x; const float Yd = ray.d.y; const float Zd = ray.d.z; const float Xc = pos.x; const float Yc = pos.y; const float Zc = pos.z; const float B = 2.0f * (Xd * (X0 - Xc) + Yd * (Y0 - Yc) + Zd * (Z0 - Zc)); const float C = (X0-Xc)*(X0-Xc) + (Y0-Yc)*(Y0-Yc) + (Z0-Zc)*(Z0-Zc) - r*r; const float discriminant = B*B - 4*C; if (discriminant < 0.0f) return false; const float t0 = (- B - sqrt(discriminant)) / 2.0f; const float t1 = (- B + sqrt(discriminant)) / 2.0f; if (t0 < 0 || t0 != t0) { return true; }*/ Matrix4x4 w2o_m; w2o_m.m[0][3] = -pos.x; w2o_m.m[1][3] = -pos.y; w2o_m.m[2][3] = -pos.z; Transform w2o = Transform(w2o_m); const float thetaMin = -M_PI; const float thetaMax = 0; const float phiMax = 2.f*M_PI; float phi; Point phit; // Transform _Ray_ to object space Ray ray; w2o(rayInc, &ray); // Compute quadratic sphere coefficients float A = ray.d.x*ray.d.x + ray.d.y*ray.d.y + ray.d.z*ray.d.z; float B = 2 * (ray.d.x*ray.o.x + ray.d.y*ray.o.y + ray.d.z*ray.o.z); float C = ray.o.x*ray.o.x + ray.o.y*ray.o.y + ray.o.z*ray.o.z - r*r; // Solve quadratic equation for _t_ values float t0, t1; if (!Quadratic(A, B, C, &t0, &t1)) return false; // Compute intersection distance along ray if (t0 > ray.maxt || t1 < ray.mint) return false; float thit = t0; if (t0 < ray.mint) { thit = t1; if (thit > ray.maxt) return false; } // Compute sphere hit position and $\phi$ phit = ray(thit); rayInc.hitFoam = true; PerspectiveCamera * cam = PerspectiveCamera::cur_cam; Transform c2w; cam->CameraToWorld.Interpolate(0.f, &c2w); Transform w2c = Inverse(c2w); Transform c2s = cam->CameraToScreen; Transform s2r = cam->ScreenToRaster; Point cPos = w2c(phit); Point rPos = s2r(c2s(cPos)); int x = (int)(rPos.x + 0.5); int y = (int)(rPos.y + 0.5); int w = cam->film->xResolution; int h = cam->film->yResolution; if (x > 0 && y > 0 && x < w && y < h) { rayInc.hitFoam = true; /*printf("%i %i %i %i\n", x, y, w ,h); std::cout << parent << std::endl; std::cout << parent->parent << std::endl; std::cout << parent->parent->foamPlane[0] << std::endl; std::cout << parent->parent->foamPlane.size() << std::endl; std::cout << x + y*w << std::endl;*/ //std::cout << NaiadFoam::cur->FoamPlane().size() << std::endl; rayInc.alphaFoam = NaiadFoam::cur->FoamPlane()[x + y*w]; } /*if (phit.x == 0.f && phit.y == 0.f) phit.x = 1e-5f * r; phi = atan2f(phit.y, phit.x); if (phi < 0.) phi += 2.f*M_PI; // Find parametric representation of sphere hit float u = phi / phiMax; float theta = acosf(Clamp(phit.z / r, -1.f, 1.f)); float v = (theta - thetaMin) / (thetaMax - thetaMin); // Compute sphere $\dpdu$ and $\dpdv$ float zradius = sqrtf(phit.x*phit.x + phit.y*phit.y); float invzradius = 1.f / zradius; float cosphi = phit.x * invzradius; float sinphi = phit.y * invzradius; Vector dpdu(-phiMax * phit.y, phiMax * phit.x, 0); Vector dpdv = (thetaMax-thetaMin) * Vector(phit.z * cosphi, phit.z * sinphi, -r * sinf(theta)); // Compute sphere $\dndu$ and $\dndv$ Vector d2Pduu = -phiMax * phiMax * Vector(phit.x, phit.y, 0); Vector d2Pduv = (thetaMax - thetaMin) * phit.z * phiMax * Vector(-sinphi, cosphi, 0.); Vector d2Pdvv = -(thetaMax - thetaMin) * (thetaMax - thetaMin) * Vector(phit.x, phit.y, phit.z); // Compute coefficients for fundamental forms float E = Dot(dpdu, dpdu); float F = Dot(dpdu, dpdv); float G = Dot(dpdv, dpdv); Vector N = Normalize(Cross(dpdu, dpdv)); float e = Dot(N, d2Pduu); float f = Dot(N, d2Pduv); float g = Dot(N, d2Pdvv); // Compute $\dndu$ and $\dndv$ from fundamental form coefficients float invEGF2 = 1.f / (E*G - F*F); Normal dndu = Normal((f*F - e*G) * invEGF2 * dpdu + (e*F - f*E) * invEGF2 * dpdv); Normal dndv = Normal((g*F - f*G) * invEGF2 * dpdu + (f*F - g*E) * invEGF2 * dpdv); //std::cout << "Got here?" << std::endl; Matrix4x4 o2w_m; o2w_m.m[0][3] = pos.x; o2w_m.m[1][3] = pos.y; o2w_m.m[2][3] = pos.z; Transform o2w = Transform(o2w_m); // Initialize _DifferentialGeometry_ from parametric information *dg = DifferentialGeometry(o2w(phit), o2w(dpdu), o2w(dpdv), o2w(dndu), o2w(dndv), u, v, parent); dg->mult = 1.f;*/ // Update _tHit_ for quadric intersection //*tHit = thit; // Compute _rayEpsilon_ for quadric intersection //*rayEpsilon = 5e-4f * *tHit; return true; }