void File_SaveByDialog(HWND hwnd, LPTSTR pszFile) { OPENFILENAME ofn; TCHAR pszFileNameBuffer[MAX_PATH] = _T(""); int nLineFeedType = CRLF_STYLE_AUTOMATIC; LPEDITVIEW lpew = MDI_GetEditView(NULL); if (lpew != NULL && lpew->lpes != NULL) nLineFeedType = TextBuffer_GetCRLFMode(lpew->lpes); INITSTRUCT(ofn, TRUE); ofn.hwndOwner = hwnd; ofn.hInstance = g_hInstance; ofn.lpstrFilter = String_MakeFilter(g_FilterSettings.szSaveFilter); ofn.nFilterIndex = 1; ofn.lpstrFile = pszFileNameBuffer; ofn.nMaxFile = MAX_PATH; ofn.lpstrTitle = _T("Save File As"); ofn.Flags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_ALLOWMULTISELECT;// | OFN_ENABLEHOOK | OFN_ENABLETEMPLATE; ofn.lCustData = (LPARAM)&nLineFeedType; ofn.lpfnHook = File_OFNHookProc; ofn.lpTemplateName = MAKEINTRESOURCE(IDD_OPENFILEDIALOG); if (!GetSaveFileName(&ofn)) return; else File_Save(hwnd, pszFileNameBuffer, nLineFeedType); }
/** * Modify exisiting ST desktop configuration files to set resolution(keep user settings) */ static void VDI_ModifyDesktopInf(char *pszFileName) { long InfSize; Uint8 *pInfData; int i; /* Load our '.inf' file */ pInfData = File_Read(pszFileName, &InfSize, NULL); if (pInfData) { /* Scan file for '#E' */ i = 0; while (i < (InfSize-8)) { if ((pInfData[i]=='#') && (pInfData[i+1]=='E')) { /* Modify resolution */ pInfData[i+7] = '1'+VDIRes; break; } i++; } /* And save */ File_Save(pszFileName, pInfData, InfSize, false); /* Free */ free(pInfData); } }
/** * Save .ST file from memory buffer. Returns true is all OK. */ bool ST_WriteDisk(const char *pszFileName, Uint8 *pBuffer, int ImageSize) { #ifdef SAVE_TO_ST_IMAGES /* Just save buffer directly to file */ return File_Save(pszFileName, pBuffer, ImageSize, false); #else /*SAVE_TO_ST_IMAGES*/ /* Oops, cannot save */ return false; #endif /*SAVE_TO_ST_IMAGES*/ }
/** * Save compressed .MSA file from memory buffer. Returns true is all OK */ bool MSA_WriteDisk(const char *pszFileName, Uint8 *pBuffer, int ImageSize) { #ifdef SAVE_TO_MSA_IMAGES MSAHEADERSTRUCT *pMSAHeader; unsigned short int *pMSADataLength; Uint8 *pMSAImageBuffer, *pMSABuffer, *pImageBuffer; Uint16 nSectorsPerTrack, nSides, nCompressedBytes, nBytesPerTrack; bool nRet; int nTracks,nBytesToGo,nBytesRun; int Track,Side; /* Allocate workspace for compressed image */ pMSAImageBuffer = (Uint8 *)malloc(MSA_WORKSPACE_SIZE); if (!pMSAImageBuffer) { perror("MSA_WriteDisk"); return false; } /* Store header */ pMSAHeader = (MSAHEADERSTRUCT *)pMSAImageBuffer; pMSAHeader->ID = SDL_SwapBE16(0x0E0F); Floppy_FindDiskDetails(pBuffer,ImageSize, &nSectorsPerTrack, &nSides); pMSAHeader->SectorsPerTrack = SDL_SwapBE16(nSectorsPerTrack); pMSAHeader->Sides = SDL_SwapBE16(nSides-1); pMSAHeader->StartingTrack = SDL_SwapBE16(0); nTracks = ((ImageSize / NUMBYTESPERSECTOR) / nSectorsPerTrack) / nSides; pMSAHeader->EndingTrack = SDL_SwapBE16(nTracks-1); /* Compress image */ pMSABuffer = pMSAImageBuffer + sizeof(MSAHEADERSTRUCT); for (Track = 0; Track < nTracks; Track++) { for (Side = 0; Side < nSides; Side++) { /* Get track data pointer */ nBytesPerTrack = NUMBYTESPERSECTOR*nSectorsPerTrack; pImageBuffer = pBuffer + (nBytesPerTrack*Side) + ((nBytesPerTrack*nSides)*Track); /* Skip data length (fill in later) */ pMSADataLength = (Uint16 *)pMSABuffer; pMSABuffer += sizeof(Uint16); /* Compress track */ nBytesToGo = nBytesPerTrack; nCompressedBytes = 0; while (nBytesToGo > 0) { nBytesRun = MSA_FindRunOfBytes(pImageBuffer,nBytesToGo); if (nBytesRun == 0) { /* Just copy byte */ *pMSABuffer++ = *pImageBuffer++; nCompressedBytes++; nBytesRun = 1; } else { /* Store run! */ *pMSABuffer++ = 0xE5; /* Marker */ *pMSABuffer++ = *pImageBuffer; /* Byte, and follow with 16-bit length */ do_put_mem_word(pMSABuffer, nBytesRun); pMSABuffer += sizeof(Uint16); pImageBuffer += nBytesRun; nCompressedBytes += 4; } nBytesToGo -= nBytesRun; } /* Is compressed track smaller than the original? */ if (nCompressedBytes < nBytesPerTrack) { /* Yes, store size */ do_put_mem_word(pMSADataLength, nCompressedBytes); } else { /* No, just store uncompressed track */ do_put_mem_word(pMSADataLength, nBytesPerTrack); pMSABuffer = ((Uint8 *)pMSADataLength) + 2; pImageBuffer = pBuffer + (nBytesPerTrack*Side) + ((nBytesPerTrack*nSides)*Track); memcpy(pMSABuffer,pImageBuffer, nBytesPerTrack); pMSABuffer += nBytesPerTrack; } } } /* And save to file! */ nRet = File_Save(pszFileName,pMSAImageBuffer, pMSABuffer-pMSAImageBuffer, false); /* Free workspace */ free(pMSAImageBuffer); return nRet; #else /*SAVE_TO_MSA_IMAGES*/ /* Oops, cannot save */ return false; #endif /*SAVE_TO_MSA_IMAGES*/ }
int window_update(window_t* window) { LOG static unsigned int previous_key = -1; static mouse_state_t prev_mouse_state; int error; /* Mouse */ if (mouse_state.updated) { mouse_state.updated = 0; window->mouse_x += mouse_state.diffx; window->mouse_y -= mouse_state.diffy; /* inverted y axis */ window->mouse_x = clamp(window->mouse_x, 0, window->width); window->mouse_y = clamp(window->mouse_y, 0, window->height); /*error = window_set_title(window, "x: %d, y: %d, w: %d, h: %d", window->mouse_x, window->mouse_y, window->width, window->height); if (error) { printf("window_update: window_set_title failed with error code %d.\n", error); return error; }*/ if (mouse_state.ldown || mouse_state.mdown || mouse_state.rdown) window_mouse_press(window); if ((prev_mouse_state.ldown && !mouse_state.ldown) || (prev_mouse_state.mdown && !mouse_state.mdown) || (prev_mouse_state.rdown && !mouse_state.rdown)) window_mouse_release(window); window->redraw = 1; prev_mouse_state = mouse_state; } /* Keyboard */ if (last_key_pressed != -1) { error = window_key_press(window, last_key_pressed); if (!error) { switch (window->state) { case WIN_STATE_OPEN_ASK_NAME: { if (window->current_tab != TAB_CONSOLE) { window_set_log_message(window, "Open: Cancelled"); window_set_previous_tab(window); window->state = WIN_STATE_NORMAL; } else if (last_key_pressed == KEY_ENTER || last_key_pressed == KEY_NUM_ENTER) { int i; size_t size; char* fileName = tab_to_file(window->tabs[TAB_CONSOLE]); char* fileBuffer = NULL; tab_t* tab = NULL; for (i = 0; i < (TAB_COUNT - 1); i++) { if (!window->tabs[i]) { tab = window->tabs[i]; break; } } if (i >= (TAB_COUNT - 1)) { window_set_log_message(window, "Open: No tabs available to open file!"); window_set_previous_tab(window); window->state = WIN_STATE_NORMAL; break; } if (!File_Load(fileName, &fileBuffer, &size)) { window_set_log_message(window, "Open: Error loading file %s", fileName); window_set_previous_tab(window); window->state = WIN_STATE_NORMAL; break; } fileBuffer[size-1] = 0; window->tabs[i] = tab_create_from_file(fileName, fileBuffer); if (window->tabs[i]) { window_set_log_message(window, "Open: File loaded with success"); } window_set_tab(window, i); window->state = WIN_STATE_NORMAL; } break; } case WIN_STATE_SAVE_ASK_NAME: { if (window->current_tab != TAB_CONSOLE) { window_set_log_message(window, "Save: Cancelled"); window_set_previous_tab(window); window->state = WIN_STATE_NORMAL; } else if (last_key_pressed == KEY_ENTER || last_key_pressed == KEY_NUM_ENTER) { char* fileName = tab_to_file(window->tabs[TAB_CONSOLE]); char* fileBuffer = tab_to_file(window->tabs[window->prev_current_tab]); if (strlen(fileName) != 0) { if (File_Save(fileName, fileBuffer, strlen(fileBuffer))) { window_set_log_message(window, "Save: File saved with success"); tab_remove_all(window->tabs[TAB_CONSOLE]); window_set_previous_tab(window); if ((strcmp(window->tabs[window->current_tab]->file_name, fileName) != 0) && (strlen(window->tabs[window->current_tab]->file_name) != strlen(fileName))) { tab_destroy(window->tabs[window->current_tab]); window->tabs[window->current_tab] = tab_create_from_file(fileName, fileBuffer); } } else { window_set_log_message(window, "Save: Error saving file"); } } else { window_set_log_message(window, "Save: Invalid File name. Save cancelled"); window_set_previous_tab(window); } window->state = WIN_STATE_NORMAL; } break; } default: { if (window->current_tab == TAB_CONSOLE && (last_key_pressed == KEY_ENTER || last_key_pressed == KEY_NUM_ENTER)) { char* command = tab_to_file(window->tabs[TAB_CONSOLE]); if (!command) break; int size = strlen(command); if (size == 0) break; if ((size == 3) && (strcmp("new", command) == 0)) { new_btn_click(new_btn); tab_remove_all(window->tabs[TAB_CONSOLE]); } else if ((size == 4) && (strcmp("save", command) == 0)) { window_set_previous_tab(window); save_btn_click(save_btn); } else if ((size == 4) && (strcmp("open", command) == 0)) { open_btn_click(open_btn); } else if ((size == 4) && (strcmp("exit", command) == 0)) { close_btn_click(close_btn); } else if ((size == 9) && (strcmp("close-tab", command) == 0)) { window_remove_tab(window, window->prev_current_tab); tab_remove_all(window->tabs[TAB_CONSOLE]); } else { window_set_log_message(window, "Invalid Command."); } } break; } } previous_key = last_key_pressed; last_key_pressed = -1; window->redraw = 1; } else { printf("window_update: window_key_press failed with error code %d.\n", error); last_key_pressed = -1; window->redraw = 1; } } /* RTC */ char* date = rtc_get_date(); if (date) { printf("DEBUG: %s, %d\n", __FUNCTION__, __LINE__); if (window->date) free(window->date); window->date = date; window->redraw = 1; } return 0; }
/** * Save .DIM file from memory buffer. Returns TRUE is all OK */ bool DIM_WriteDisk(int Drive, const char *pszFileName, Uint8 *pBuffer, int ImageSize) { #ifdef SAVE_TO_DIM_IMAGES unsigned short int nSectorsPerTrack, nSides; Uint8 *pDimFile; int nTracks; bool bRet; #if HAVE_LIBZ gzFile hGzFile; #else FILE *fhdl; #endif /* Allocate memory for the whole DIM image: */ pDimFile = malloc(ImageSize + 32); if (!pDimFile) { perror("DIM_WriteDisk"); return false; } memset(pDimFile, 0, 32); /* Try to load the old header data to preserve the header fields that are unknown yet: */ #if HAVE_LIBZ hGzFile = gzopen(pszFileName, "rb"); if (hGzFile != NULL) { gzread(hGzFile, pDimFile, 32); gzclose(hGzFile); } #else fhdl = fopen(pszFileName, "rb"); if (fhndl != NULL) { fread(pDimFile, 32, 1, fhndl); fclose(fhndl); } #endif /* Now fill in the new header information: */ Floppy_FindDiskDetails(pBuffer, ImageSize, &nSectorsPerTrack, &nSides); nTracks = ((ImageSize / NUMBYTESPERSECTOR) / nSectorsPerTrack) / nSides; pDimFile[0x00] = pDimFile[0x01] = 0x42; /* ID */ pDimFile[0x03] = 0; /* Image contains all sectors */ pDimFile[0x06] = nSides - 1; /* Sides */ pDimFile[0x08] = nSectorsPerTrack; /* Sectors per track */ pDimFile[0x0A] = 0; /* Starting track */ pDimFile[0x0C] = nTracks - 1; /* Ending track */ pDimFile[0x0D] = (ImageSize > 1024*1024); /* DD / HD flag */ /* Now copy the disk data: */ memcpy(pDimFile + 32, pBuffer, ImageSize); /* And finally save it: */ bRet = File_Save(pszFileName, pDimFile, ImageSize + 32, false); free(pDimFile); return bRet; #else /*SAVE_TO_ST_IMAGES*/ /* Oops, cannot save */ return false; #endif /*SAVE_TO_ST_IMAGES*/ }
/** * Save desktop configuration file for VDI, eg desktop.inf(TOS 1.04) or newdesk.inf(TOS 2.06) */ static void VDI_SaveDesktopInf(char *pszFileName, const Uint8 *Script, long ScriptSize) { /* Just save file */ File_Save(pszFileName, Script, ScriptSize, false); }