//============================================================== void MakeBackupFile(const char *fname) //-------------------------------------------------------------- // PATH_BACKUP にバックアップをとる //-------------------------------------------------------------- // in: file = バックアップを取るファイル名 //-------------------------------------------------------------- // out: なし //============================================================== { char d_name[FNAME_MAXLEN]; void *tmp_buf; sFILE *fd_src, *fd_dst; size_t len, size; // オリジナルのファイルを開く //---------------------------- fd_src = FsOpen(fname); if(!fd_src) { return; } // バックアップファイルの作成 //---------------------------- sprintf(d_name, PATH_BACKUP"/%s.%s", GetFileBaseName(fname), StrMakeUniqueName()); fd_dst = FsCreate(d_name); if (!fd_dst) { FsClose(fd_src); return; } // 作業バッファを確保 //-------------------- tmp_buf = devMalloc(TMPBUF_LEN, "MakeBackupFile"); len = FsGetSizeOrig(fd_src); while(len) { size = (len >= TMPBUF_LEN) ? TMPBUF_LEN : len; FsRead(fd_src, tmp_buf, size); FsWrite(fd_dst, tmp_buf, size); len -= size; } FsClose(fd_src); FsClose(fd_dst); Free(tmp_buf); // SYSINFODSP("Make Backup file"); // SYSINFODSP("%s", MSG_FILE(d_name)); // SYSINFO("Make Backup file"); // SYSINFO("%s", MSG_FILE(d_name)); // SYSINFOCNS("Make Backup file"); // SYSINFOCNS("%s", MSG_FILE(d_name)); }
//============================================================== void MmFileWriteB(const char *file, void *ptr, size_t len) //-------------------------------------------------------------- // ファイルを書き出す // ※ブロックタイプ //-------------------------------------------------------------- // in: file = ファイル名 // ptr = データポインタ // len = データサイズ //-------------------------------------------------------------- // out: なし //============================================================== { sFILE *fp; fp = FsCreate(file); ASSERT(fp); FsWrite(fp, ptr, len); FsClose(fp); }
//============================================================== void PngWrite(char *file, int w, int h, u_char *ptr) //-------------------------------------------------------------- // データ出力 // 32bit → 32bit //-------------------------------------------------------------- // in: file = ファイル名 // w, h = データサイズ // ptr = データポインタ //-------------------------------------------------------------- // out: なし //============================================================== { sFILE *fp; png_structp png_ptr; png_infop info_ptr; png_color_8 sig_bit; png_text text_ptr[1]; png_bytep *row_pointers; int k; #ifdef USE_USER_MEMORY png_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL, NULL, libpng_Malloc, libpng_Free); #else png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); #endif if(!png_ptr) { return; } info_ptr = png_create_info_struct(png_ptr); if(!info_ptr) { png_destroy_write_struct(&png_ptr, png_infopp_NULL); return; } // ファイルの新規作成 //-------------------- fp = FsCreate(file); ASSERT(fp); png_set_write_fn(png_ptr, (png_voidp)fp, writeFunc, flushFunc); png_set_IHDR(png_ptr, info_ptr, w, h, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_BASE); sig_bit.red = 8; sig_bit.green = 8; sig_bit.blue = 8; sig_bit.alpha = 0; png_set_sBIT(png_ptr, info_ptr, &sig_bit); text_ptr[0].key = "Description"; text_ptr[0].text = "ktcDIB::Save() Data"; text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE; png_set_text(png_ptr, info_ptr, text_ptr, 1); png_write_info(png_ptr, info_ptr); png_set_bgr(png_ptr); row_pointers = (png_bytep *)fsMalloc(sizeof(png_bytep *) * h, "png_bytep"); ASSERT(row_pointers); for(k = 0; k < h; ++k) { png_byte *p; p = (png_byte *)fsMalloc(sizeof(png_byte) * w * 3, "png_byte"); ASSERT(p); row_pointers[k] = (png_bytep)p; memcpy(p, ptr, w * 3); ptr += w * 3; } png_write_image(png_ptr, row_pointers); png_write_end(png_ptr, info_ptr); for(k = 0; k < h; ++k) { Free(row_pointers[k]); } Free(row_pointers); png_destroy_write_struct(&png_ptr, &info_ptr); FsClose(fp); }
int mainCRTStartup(void) { handle_t server, client; unsigned i; params_vid_t params; font_t *font; vid = FsOpen(SYS_DEVICES L"/Classes/video0", FILE_READ | FILE_WRITE); if (vid == NULL) { _wdprintf(L"console: " SYS_DEVICES L"/Classes/video0: %s\n", _wcserror(errno)); return errno; } memset(&mode, 0, sizeof(mode)); params.vid_setmode = mode; if (!FsRequestSync(vid, VID_SETMODE, ¶ms, sizeof(params), NULL)) { _wdprintf(L"console: failed to set video mode: %s\n", _wcserror(errno)); HndClose(vid); return errno; } mode = params.vid_setmode; if (mode.flags & VIDEO_MODE_TEXT) { _wdprintf(L"console: text mode not supported\n"); return 0; } if (mode.bitsPerPixel == 4) { vidmem = NULL; if (!AccelCreateSurface(&mode, vid, &surf)) { _wdprintf(L"console: AccelCreateSurface failed\n"); return errno; } } else { handle_t handle_vidmem; handle_vidmem = HndOpen(mode.framebuffer); if (handle_vidmem == 0) { _wdprintf(L"console: unable to open framebuffer %s\n", mode.framebuffer); return errno; } vidmem = VmmMapSharedArea(handle_vidmem, 0, VM_MEM_USER | VM_MEM_READ | VM_MEM_WRITE); HndClose(handle_vidmem); if (!FramebufCreateSurface(&mode, vidmem, &surf)) { _wdprintf(L"console: video mode not supported: %u bits per pixel\n", mode.bitsPerPixel); return errno; } } FontInit(); font = FontLoad(font_name, 10 * 64, mode.bitsPerPixel < 8 ? FB_FONT_MONO : FB_FONT_SMOOTH); if (font == NULL) { _wdprintf(L"console: failed to load font %s\n", font_name); return errno; } cookies[0] = (void*) 0x12345678; num_buffers = 1; LmuxInit(&lmux_consoles); for (i = 0; i < _countof(consoles); i++) { LmuxInit(&consoles[i].lmux); consoles[i].width = consoles[i].height = 0; consoles[i].fg_colour = consoles[i].default_fg_colour = 0xc0c0c0; consoles[i].bg_colour = consoles[i].default_bg_colour = 0x000000; consoles[i].cookie = cookies[0]; consoles[i].buf_chars = NULL; consoles[i].font = font; FontGetMaxSize(consoles[i].font, &consoles[i].char_width, &consoles[i].char_height); } num_consoles = _countof(consoles); ConTileBuffer(0); num_consoles = 0; current = consoles; for (i = 0; i < _countof(consoles); i++) ConClear(consoles + i); server = FsCreate(server_name, 0); ThrCreateThread(ConKeyboardThread, NULL, 16, L"ConKeyboardThread"); ThrCreateThread(ConCursorThread, NULL, 16, L"ConCursorThread"); ConDisplaySignonMessage(); while ((client = PortAccept(server, FILE_READ | FILE_WRITE))) { if (num_consoles < _countof(consoles)) { consoles[num_consoles].client = client; ThrCreateThread(ConClientThread, consoles + num_consoles, 15, L"ConClientThread"); num_consoles++; } else HndClose(client); } for (i = 0; i < _countof(consoles); i++) { LmuxDelete(&consoles[i].lmux); free(consoles[i].buf_chars); } LmuxDelete(&lmux_consoles); FontDelete(font); HndClose(server); if (vidmem != NULL) VmmFree(vidmem); HndClose(vid); return EXIT_SUCCESS; }