bool SharedUtil::FileSave(const SString& strFilename, const SString& strBuffer, bool bForce) { return FileSave(strFilename, strBuffer.length() ? &strBuffer.at(0) : NULL, strBuffer.length(), bForce); }
void CKeyBindings::Print() const { FileSave(stdout); }
/* Sheet_HandleCommand: Handles all commands routed to property sheet (mostly menuitem stuff). */ bool Sheet_HandleCommand(HWND sheet, WORD code, WORD id, HWND control) { bool ret = true; Player *p = propdata.p; switch (id) { case ID_FILE_REOPEN: FileOpen(sheet, false, 0); break; case ID_TS_FILE_OPEN: FileOpen(sheet, true, -1); break; case ID_TS_FILE_NEW: case ID_TS_FILE_CLOSE: FileClose(sheet, control); break; case ID_TS_APP_EXIT: if (scen.needsave()) { int sel = MessageBox(sheet, "Do you want to save your changes?", "Save", MB_YESNOCANCEL); if (sel == IDYES) FileSave(sheet, false, true); else if (sel == IDCANCEL) break; //stop closing } DestroyWindow(sheet); break; case ID_TS_FILE_SAVE: FileSave(sheet, false, true); break; case ID_TS_FILE_SAVE_AS: FileSave(sheet, true, true); break; case ID_TS_FILE_SAVE_AS2: FileSave(sheet, true, false); case ID_FILE_DUMP: if (!scen.exFile("dump", -1)) { MessageBox(sheet, "Dump failed.", "Scenario Dump", MB_ICONWARNING); } else { SetWindowText(propdata.statusbar, "Per files saved to disk"); } break; case IDC_U_CLEARAICPVC: scen.clearaicpvc(); SetWindowText(propdata.statusbar, "Removed All AI, City Plan and VC files"); SendMessage(PropSheet_GetCurrentPageHwnd(sheet), AOKTS_Loading, 0, 0); break; case IDC_U_RANDOMIZE_ROT: scen.randomize_unit_frames(); SetWindowText(propdata.statusbar, "Randomized unit frames and rotations"); break; case ID_UNITS_TERRAIN_ELEV: scen.set_unit_z_to_map_elev(); SetWindowText(propdata.statusbar, "Unit z positions set to terrain elevation"); break; case ID_UNITS_DELETE_ALL: scen.delete_player_units(propdata.pindex); SetWindowText(propdata.statusbar, "Player's units deleted"); SendMessage(propdata.mapview, MAP_Reset, 0, 0); break; case ID_MAP_WATER_CLIFF_INVISIBLE: scen.water_cliffs_visibility(FALSE); SetWindowText(propdata.statusbar, "Water cliffs are now invisible"); break; case ID_MAP_WATER_CLIFF_VISIBLE: scen.water_cliffs_visibility(TRUE); SetWindowText(propdata.statusbar, "Water cliffs are now visible"); break; case ID_TRIGGERS_SORT_CONDS_EFFECTS: scen.sort_conds_effects(); SetWindowText(propdata.statusbar, "Trigger contitions and effects sorted alphanumerically"); break; case ID_TRIGGERS_NOINSTRUCTIONSSOUND: scen.instructions_sound_text_set(); SetWindowText(propdata.statusbar, "Sound text set to null"); break; case ID_TRIGGERS_NOINSTRUCTIONSSOUNDID: scen.instructions_sound_id_set(-1); SetWindowText(propdata.statusbar, "Sound ID set to -1 for all display instructions effects"); break; case ID_TRIGGERS_ZEROINSTRUCTIONSSOUNDID: scen.instructions_sound_id_set(0); SetWindowText(propdata.statusbar, "Sound ID set to 0 for all display instructions effects"); break; case ID_TRIGGERS_NOPANEL: scen.instructions_panel_set(-1); SetWindowText(propdata.statusbar, "Panel ID removed from all display instructions effects"); break; case ID_TRIGGERS_ZEROPANEL: scen.instructions_panel_set(0); SetWindowText(propdata.statusbar, "Panel ID set to 0 for all display instructions effects"); break; case ID_TRIGGERS_ZERODI: scen.instructions_string_zero(); SetWindowText(propdata.statusbar, "String ID set to 0 for all display instructions effects"); break; case ID_TRIGGERS_RESETDI: scen.instructions_string_reset(); SetWindowText(propdata.statusbar, "String ID set to -1 for all display instructions effects"); break; case ID_TRIGGERS_HIDENAMES: scen.remove_trigger_names(); SetWindowText(propdata.statusbar, "Trigger names removed"); break; case ID_TRIGGERS_COPY_SCRAWL: { std::ostringstream ss; scen.accept(TrigScrawlVisitor(ss)); std::string scrawl = std::string(""); scrawl.append(ss.str()); const char* output = scrawl.c_str(); const size_t len = strlen(output) + 1; HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len); memcpy(GlobalLock(hMem), output, len); GlobalUnlock(hMem); OpenClipboard(0); EmptyClipboard(); SetClipboardData(CF_TEXT, hMem); CloseClipboard(); SetWindowText(propdata.statusbar, "Copied trigger scrawl"); } break; case ID_TRIGGERS_SAVE_PSEUDONYMS: scen.save_pseudonyms(); SetWindowText(propdata.statusbar, "Pseudonyms saved"); break; case ID_TRIGGERS_PREFIX_DISPLAY_ORDER: scen.prefix_display_order(); SetWindowText(propdata.statusbar, "Prefixing display order to trigger names"); break; case ID_TRIGGERS_REMOVE_DISPLAY_ORDER_PREFIX: scen.remove_display_order_prefix(); SetWindowText(propdata.statusbar, "Prefixing display order to trigger names"); break; case ID_TRIGGERS_HIDE_DESCRIPTIONS: scen.remove_trigger_descriptions(); SetWindowText(propdata.statusbar, "Trigger descriptions removed"); break; case ID_TRIGGERS_SWAP_NAMES_DESCRIPTIONS: scen.swap_trigger_names_descriptions(); SetWindowText(propdata.statusbar, "Trigger names swapped with descriptions"); break; case ID_TRIGGERS_FIXTRIGGEROUTLIERS: scen.fix_trigger_outliers(); SetWindowText(propdata.statusbar, "Triggers outside of map have been put within the boundaries"); break; case ID_FILE_TRIGWRITE: OnFileTrigWrite(sheet); break; case ID_FILE_TRIGREAD: OnFileTrigRead(sheet); break; case IDC_P_TOUP: if (MessageBox(sheet, "Normally, you will be asked to do this later when you save the scenario to a different format.\nThis menu for fixing broken scenarios. Are you sure you want to do this?", "Convert", MB_YESNOCANCEL) == IDYES) { scen.hd_to_up(); SetWindowText(propdata.statusbar, "Trigger effects converted from AoHD to UserPatch"); } break; case IDC_P_TOHD: if (MessageBox(sheet, "Normally, you will be asked to do this later when you save the scenario to a different format.\nThis menu for fixing broken scenarios. Are you sure you want to do this?", "Convert", MB_YESNOCANCEL) == IDYES) { scen.up_to_hd(); SetWindowText(propdata.statusbar, "Trigger effects converted from UserPatch to AoHD"); } break; case IDC_P_TOAOFE: if (MessageBox(sheet, "Normally, you will be asked to do this later when you save the scenario to a different format.\nThis menu for fixing broken scenarios. Are you sure you want to do this?", "Convert", MB_YESNOCANCEL) == IDYES) { scen.up_to_aofe(); SetWindowText(propdata.statusbar, "Trigger effects converted from UserPatch to AoFE"); } break; case IDC_P_TO1C: if (MessageBox(sheet, "Normally, you will be asked to do this later when you save the scenario to a different format.\nThis menu for fixing broken scenarios. Are you sure you want to do this?", "Convert", MB_YESNOCANCEL) == IDYES) { scen.up_to_10c(); SetWindowText(propdata.statusbar, "Trigger effects converted from UserPatch to 1.0c"); } break; case ID_FILE_RECENT1: case ID_FILE_RECENT2: case ID_FILE_RECENT3: case ID_FILE_RECENT4: FileOpen(sheet, false, id - ID_FILE_RECENT1); break; case IDCANCEL: case IDOK: assert(true); break; case ID_VIEW_STATISTICS: DialogBoxParam(aokts, MAKEINTRESOURCE(IDD_STATS), sheet, StatsDialogProc, 0); break; case ID_VIEW_STAT_BAR: if (GetMenuState(GetMenu(sheet), ID_VIEW_STAT_BAR, MF_BYCOMMAND) & MF_CHECKED) { ShowWindow(propdata.statusbar, SW_HIDE); CheckMenuItem(GetMenu(sheet), ID_VIEW_STAT_BAR, MF_BYCOMMAND); } else { ShowWindow(propdata.statusbar, SW_SHOW); CheckMenuItem(GetMenu(sheet), ID_VIEW_STAT_BAR, MF_BYCOMMAND | MF_CHECKED); } break; case ID_VIEW_MAP: if (GetMenuState(GetMenu(sheet), ID_VIEW_MAP, MF_BYCOMMAND) & MF_CHECKED) { // hide window ShowWindow(propdata.mapview, SW_HIDE); // clear check CheckMenuItem(GetMenu(sheet), ID_VIEW_MAP, MF_BYCOMMAND); } else { ShowWindow(propdata.mapview, SW_SHOW); CheckMenuItem(GetMenu(sheet), ID_VIEW_MAP, MF_BYCOMMAND | MF_CHECKED); } break; case ID_DRAW_TERRAIN: if (GetMenuState(GetMenu(sheet), ID_DRAW_TERRAIN, MF_BYCOMMAND) & MF_CHECKED) { setts.drawterrain = false; // clear check CheckMenuItem(GetMenu(sheet), ID_DRAW_TERRAIN, MF_BYCOMMAND); } else { setts.drawterrain = true; // clear check CheckMenuItem(GetMenu(sheet), ID_DRAW_TERRAIN, MF_BYCOMMAND | MF_CHECKED); } SendMessage(propdata.mapview, MAP_Reset, 0, 0); break; case ID_DRAW_ELEVATION: if (GetMenuState(GetMenu(sheet), ID_DRAW_ELEVATION, MF_BYCOMMAND) & MF_CHECKED) { setts.drawelevation = false; // clear check CheckMenuItem(GetMenu(sheet), ID_DRAW_ELEVATION, MF_BYCOMMAND); } else { setts.drawelevation = true; // clear check CheckMenuItem(GetMenu(sheet), ID_DRAW_ELEVATION, MF_BYCOMMAND | MF_CHECKED); } SendMessage(propdata.mapview, MAP_Reset, 0, 0); break; case ID_DRAW_TRIGGERS: if (GetMenuState(GetMenu(sheet), ID_DRAW_TRIGGERS, MF_BYCOMMAND) & MF_CHECKED) { setts.drawconds = false; setts.draweffects = false; setts.drawlocations = false; } else { setts.drawconds = true; setts.draweffects = true; setts.drawlocations = true; } SetDrawTriggerCheckboxes(sheet); SendMessage(propdata.mapview, MAP_Reset, 0, 0); break; case ID_DRAW_CONDITIONS: if (GetMenuState(GetMenu(sheet), ID_DRAW_CONDITIONS, MF_BYCOMMAND) & MF_CHECKED) { setts.drawconds = false; } else { setts.drawconds = true; } SetDrawTriggerCheckboxes(sheet); SendMessage(propdata.mapview, MAP_Reset, 0, 0); break; case ID_DRAW_EFFECTS: if (GetMenuState(GetMenu(sheet), ID_DRAW_EFFECTS, MF_BYCOMMAND) & MF_CHECKED) { setts.draweffects = false; } else { setts.draweffects = true; } SetDrawTriggerCheckboxes(sheet); SendMessage(propdata.mapview, MAP_Reset, 0, 0); break; case ID_DRAW_LOCATIONS: if (GetMenuState(GetMenu(sheet), ID_DRAW_LOCATIONS, MF_BYCOMMAND) & MF_CHECKED) { setts.drawlocations = false; } else { setts.drawlocations = true; } SetDrawTriggerCheckboxes(sheet); SendMessage(propdata.mapview, MAP_Reset, 0, 0); break; case ID_EDIT_ALL: if (GetMenuState(GetMenu(sheet), ID_EDIT_ALL, MF_BYCOMMAND) & MF_CHECKED) { setts.editall = false; // clear check CheckMenuItem(GetMenu(sheet), ID_EDIT_ALL, MF_BYCOMMAND); } else { setts.editall = true; CheckMenuItem(GetMenu(sheet), ID_EDIT_ALL, MF_BYCOMMAND | MF_CHECKED); } break; case ID_TOOLS_COMPRESS: OnCompressOrDecompress(sheet, true); break; case ID_TOOLS_DECOMPRESS: OnCompressOrDecompress(sheet, false); break; case ID_TS_HELP: WinHelp(sheet, "ts.hlp", HELP_CONTENTS, 0); break; case ID_TS_APP_ABOUT: DialogBoxParam(aokts, (LPCSTR)IDD_ABOUT, sheet, DefaultDialogProc, 0L); break; default: ret = false; } return ret; }
/*------------------------------------------------------------------------------------------------------------------ -- FUNCTION: Window_OnCommand -- -- DATE: November 12, 2013 -- -- REVISIONS: -- November 13, 2013 - Mat Siwoski: Completed implementation of the SendFile -- November 13, 2013 - Mat Siwoski: Implementation of the Config option. -- November 18, 2013 - Robin Hsieh: Added the enabling and disabling menu items. -- November 25, 2013 - Vincent Lau: Added creation of the Transmit thread after successful file read operation -- November 26, 2013 - Mat Siwoski: Added case for saving displayed text. -- November 27, 2013 - Robin Hsieh: Tested ErrorCheck in the file being read in. -- -- DESIGNER: Mat Siwoski -- -- PROGRAMMER: Mat Siwoski -- -- INTERFACE: void Window_OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) -- HWND hwnd: Handle to the window -- int id: The id of the selection. -- HWND hwndCtl: Handle to the control. -- UINT codeNotify: Int for the Notification -- -- RETURNS: - -- -- NOTES: -- This function deals with the selection in the menu on the main window. ------------------------------------------------------------------------------------------------------------------*/ void Window_OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) { static TCHAR szFileName[MAX_PATH], szTitleName[MAX_PATH] ; switch(id) { case IDM_CONNECT: EnableMenuItem(GetMenu(hwnd), IDM_CONNECT, MF_DISABLED); EnableMenuItem(GetMenu(hwnd), IDM_DISCONNECT, MF_ENABLED); DrawMenuBar(hwnd); break; case IDM_SENDFILE: DWORD dwTransmitThreadID; if (FileOpenDlg(hwnd, szFileName, szTitleName)) { if (!FileRead(hwnd, szFileName)) { // error file could not be read OkMessage (hwnd, TEXT ("Could not read file %s!"), szTitleName) ; szFileName[0] = '\0' ; szTitleName[0] = '\0' ; } else // success file read { // Clean up thread TerminateThread(hTransmitThread, 0); CloseHandle(hTransmitThread); ReleaseSemaphore(hFileWaitSemaphore, 1, NULL); // create transmit thread for this file hTransmitThread = CreateThread(NULL, 0, TransmitThread, pszFileText, 0, &dwTransmitThreadID); } } break; case IDM_SAVEFILE: if (FileSaveDlg(hwnd, szFileName, szTitleName)) { if (!FileSave(hwnd, szFileName)) { OkMessage(hwnd, TEXT ("Could not write file %s"), szTitleName) ; break; } } break; case IDM_DISCONNECT: EnableMenuItem(GetMenu(hwnd), IDM_CONNECT, MF_ENABLED); EnableMenuItem(GetMenu(hwnd), IDM_DISCONNECT, MF_DISABLED); DrawMenuBar(hwnd); break; case IDM_CONFIG: DWORD dwReceiveThreadID; TerminateThread(hReceiveThread, 0); CloseHandle(hReceiveThread); if(SetupPort(lpszCommName)) { if (ConfPort(&MainWindow, lpszCommName)) { // Set Read flag true bWantToRead = TRUE; hReceiveThread = CreateThread(NULL, 0, ReceiveThread, &hEdit, 0, &dwReceiveThreadID); break; } } break; case IDM_ABOUT: DialogBox (hInstance, TEXT ("AboutBox"), hwnd, AboutDlgProc) ; break; case IDM_EXIT: Window_OnDestroy(hwnd); break; } }
/* FileOpen: Handles a request to open a file. (Either by menu or generated by the app.) Parameters: HWND sheet: Handle to the property sheet. bool ask: Should AOKTS ask the user which file? int recent: Optionally open from one of the recent file entries. (-1 to disable.) */ void FileOpen(HWND sheet, bool ask, int recent) { OPENFILENAME ofn; struct RecentFile *file = NULL; //the file info will be stored here one way or another char titleBuffer[100]; const char *filename; Game version = scen.game; HWND page = PropSheet_GetCurrentPageHwnd(sheet); //save the scenario if changes have been made (NOT FUNCTIONAL) if (scen.needsave()) { int sel = MessageBox(sheet, askSaveChanges, "Save", MB_YESNOCANCEL); if (sel == IDYES) FileSave(sheet, false, true); else if (sel == IDCANCEL) return; //stop closing } // Hint about whether to open as AOC or SGWB if (setts.recent_first) { scen.game = (Game)setts.recent_first->game; } /* Using a recent file... */ if (recent >= 0) { ofn.Flags = 0; //make sure no random flags set file = setts.recent_first; /* Parse the linked list to find the one we want */ while (recent--) { if (file) file = file->next; else { MessageBox(sheet, "Warning: Recent File open failed.", "Open Warning", MB_ICONWARNING); } } strcpy(setts.ScenPath, file->path); version = (Game)file->game; } /* Prompt the user for a filename. */ else if (ask) { struct RecentFile *r_parse; char dir[_MAX_PATH]; strcpy(dir, setts.BasePath); strcat(dir, "Scenario"); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = sheet; //ofn.hInstance unused ofn.lpstrFilter = extOpen; ofn.lpstrCustomFilter = NULL; //user should not set custom filters ofn.lpstrFile = setts.ScenPath; ofn.nMaxFile = _MAX_PATH; ofn.lpstrFileTitle = NULL; ofn.lpstrInitialDir = dir; ofn.lpstrTitle = NULL; ofn.Flags = OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON | OFN_NOCHANGEDIR; if (scen.header.header_type == HT_AOE2SCENARIO) { ofn.nFilterIndex = 1; ofn.lpstrDefExt = "aoe2scenario"; } else { switch (scen.game) { case AOK: case AOC: case AOHD: case AOF: case AOHD4: case AOF4: case AOHD6: case AOF6: ofn.nFilterIndex = 1; ofn.lpstrDefExt = "scx"; break; case SWGB: case SWGBCC: ofn.nFilterIndex = 2; ofn.lpstrDefExt = "scx"; break; } } if (!GetOpenFileName(&ofn)) return; switch (ofn.nFilterIndex) { case 1: version = AOC; printf_log("Selected %d, AOE 2.\n", ofn.nFilterIndex); break; case 2: version = SWGB; printf_log("Selected %d, Star Wars.\n", ofn.nFilterIndex); break; } /* Now check if selected file is already on recent list. */ r_parse = setts.recent_first; while (r_parse) { if (!strcmp(r_parse->path, setts.ScenPath)) { file = r_parse; break; } r_parse = r_parse->next; } } /* Open it! */ SendMessage(page, AOKTS_Closing, 0, 0); // set hourglass, might take more than 1ms HCURSOR previous = SetCursor(LoadCursor(NULL, IDC_WAIT)); scen.reset(); try { version = scen.open(setts.ScenPath, setts.TempPath, version); /* Handle recent file stuff */ if (!file) { file = setts.recent_getnext(); strcpy(file->path, setts.ScenPath); strcpy(file->display, PathFindFileName(setts.ScenPath)); file->game = (int)version; } setts.recent_push(file); UpdateRecentMenu(propdata.menu); SetCursor(previous); // for some reason this is always read only. on Wine at least //SetSaveState(sheet, ofn.Flags & OFN_READONLY ? MF_GRAYED : MF_ENABLED); SetSaveState(sheet, ofn.Flags & OFN_READONLY ? MF_ENABLED : MF_ENABLED); // set status bar text SetWindowTextW(propdata.statusbar, L"Scenario loaded successfully."); SendMessage(page, AOKTS_Loading, 0, 0); SendMessageW(propdata.mapview, MAP_Recreate, 0, 0); MapView_Reset(propdata.mapview, true); filename = getFilenameFromPath(setts.ScenPath); _snprintf(titleBuffer, sizeof(titleBuffer), "%s - %s", szTitle, filename); SetWindowText(sheet, titleBuffer); } catch (std::exception &ex) { // TODO: better atomic cursor handling? SetCursor(previous); // set status bar text SetWindowText(propdata.statusbar, ex.what()); // report error to user std::string desc = "Failed to open as "; desc.append(gameName(scen.game)); desc.append(" scenario file.\n"); switch (scen.game) { case AOC: desc.append("Try opening as a SWGB scx file instead\nusing File->Open\n"); break; case SWGB: desc.append("Try opening as a Conquerors scx file instead\nusing File->Open\n"); break; } desc.append("\nThe problem: "); desc.append(ex.what()); desc.append("\n\nIf the game is able to open the scenario,\nplease report this error. Thanks."); printf_log("User message: %s\n", desc.c_str()); MessageBox(sheet, desc.c_str(), "Scenario Load Error", MB_ICONWARNING); // unless it's a debug build, clear the bad data #ifndef _DEBUG scen.reset(); SendMessage(page, AOKTS_Closing, 0, 0); #endif /* Updates*/ SendMessage(page, AOKTS_Loading, 0, 0); _snprintf(titleBuffer, sizeof(titleBuffer), "%s", szTitle); SetWindowText(sheet, titleBuffer); } //report errors to logfile fflush(stdout); }
/* Sheet_HandleCommand: Handles all commands routed to property sheet (mostly menuitem stuff). */ bool Sheet_HandleCommand(HWND sheet, WORD code, WORD id, HWND control) { bool ret = true; switch (id) { case ID_FILE_REOPEN: FileOpen(sheet, false, 0); break; case ID_TS_FILE_OPEN: FileOpen(sheet, true, -1); break; case ID_TS_FILE_NEW: case ID_TS_FILE_CLOSE: FileClose(sheet, control); break; case ID_TS_APP_EXIT: if (scen.needsave()) { int sel = MessageBox(sheet, "Do you want to save your changes?", "Save", MB_YESNOCANCEL); if (sel == IDYES) FileSave(sheet, false, true); else if (sel == IDCANCEL) break; //stop closing } DestroyWindow(sheet); break; case ID_TS_FILE_SAVE: FileSave(sheet, false, true); break; case ID_TS_FILE_SAVE_AS: FileSave(sheet, true, true); break; case ID_TS_FILE_SAVE_AS2: FileSave(sheet, true, false); case ID_FILE_DUMP: if (!scen.exFile("dump", -1)) { MessageBox(sheet, "Dump failed.", "Scenario Dump", MB_ICONWARNING); } else { SetWindowText(propdata.statusbar, "Per files saved to disk"); } break; case IDC_U_RANDOMIZE_ROT: scen.randomize_unit_frames(); SetWindowText(propdata.statusbar, "Randomized unit frames and rotations"); break; case ID_UNITS_TERRAIN_ELEV: scen.set_unit_z_to_map_elev(); SetWindowText(propdata.statusbar, "Unit z positions set to terrain elevation"); break; case ID_UNITS_DELETE_ALL: scen.delete_player_units(propdata.pindex); SetWindowText(propdata.statusbar, "Player's units deleted"); SendMessage(propdata.mapview, MAP_Reset, 0, 0); break; case ID_MAP_WATER_CLIFF_INVISIBLE: scen.water_cliffs_visibility(FALSE); SetWindowText(propdata.statusbar, "Water cliffs are now invisible"); break; case ID_MAP_WATER_CLIFF_VISIBLE: scen.water_cliffs_visibility(TRUE); SetWindowText(propdata.statusbar, "Water cliffs are now visible"); break; case ID_TRIGGERS_SORT_CONDS_EFFECTS: scen.sort_conds_effects(); SetWindowText(propdata.statusbar, "Trigger contitions and effects sorted alphanumerically"); break; case ID_TRIGGERS_NOINSTRUCTIONSSOUND: scen.instructions_sound_text_set(); SetWindowText(propdata.statusbar, "Sound text set to null"); break; case ID_TRIGGERS_NOINSTRUCTIONSSOUNDID: scen.instructions_sound_id_set(-1); SetWindowText(propdata.statusbar, "Sound ID set to -1 for all display instructions effects"); break; case ID_TRIGGERS_ZEROINSTRUCTIONSSOUNDID: scen.instructions_sound_id_set(0); SetWindowText(propdata.statusbar, "Sound ID set to 0 for all display instructions effects"); break; case ID_TRIGGERS_NOPANEL: scen.instructions_panel_set(-1); SetWindowText(propdata.statusbar, "Panel ID removed from all display instructions effects"); break; case ID_TRIGGERS_ZEROPANEL: scen.instructions_panel_set(0); SetWindowText(propdata.statusbar, "Panel ID set to 0 for all display instructions effects"); break; case ID_TRIGGERS_ZERODI: scen.instructions_string_zero(); SetWindowText(propdata.statusbar, "String ID set to 0 for all display instructions effects"); break; case ID_TRIGGERS_RESETDI: scen.instructions_string_reset(); SetWindowText(propdata.statusbar, "String ID set to -1 for all display instructions effects"); break; case ID_TRIGGERS_HIDENAMES: scen.remove_trigger_names(); SetWindowText(propdata.statusbar, "Trigger names removed"); break; case ID_TRIGGERS_SAVE_PSEUDONYMS: scen.save_pseudonyms(); SetWindowText(propdata.statusbar, "Pseudonyms saved"); break; case ID_TRIGGERS_HIDE_DESCRIPTIONS: scen.remove_trigger_descriptions(); SetWindowText(propdata.statusbar, "Trigger descriptions removed"); break; case ID_TRIGGERS_SWAP_NAMES_DESCRIPTIONS: scen.swap_trigger_names_descriptions(); SetWindowText(propdata.statusbar, "Trigger names swapped with descriptions"); break; case ID_TRIGGERS_FIXTRIGGEROUTLIERS: scen.fix_trigger_outliers(); SetWindowText(propdata.statusbar, "Triggers outside of map have been put within the boundaries"); break; case ID_FILE_TRIGWRITE: OnFileTrigWrite(sheet); break; case ID_FILE_TRIGREAD: OnFileTrigRead(sheet); break; case IDC_P_TOUP: scen.hd_to_up(); SetWindowText(propdata.statusbar, "Trigger effects converted from AoHD to UserPatch"); break; case IDC_P_TOHD: scen.up_to_hd(); SetWindowText(propdata.statusbar, "Trigger effects converted from UserPatch to AoHD"); break; case IDC_P_TOAOFE: scen.up_to_aofe(); SetWindowText(propdata.statusbar, "Trigger effects converted from UserPatch to AoFE"); break; case IDC_P_TO1C: scen.up_to_10c(); SetWindowText(propdata.statusbar, "Trigger effects converted from UserPatch to 1.0c"); break; case ID_FILE_RECENT1: case ID_FILE_RECENT2: case ID_FILE_RECENT3: case ID_FILE_RECENT4: FileOpen(sheet, false, id - ID_FILE_RECENT1); break; case IDCANCEL: case IDOK: assert(true); break; case ID_VIEW_STATISTICS: DialogBoxParam(aokts, MAKEINTRESOURCE(IDD_STATS), sheet, StatsDialogProc, 0); break; case ID_VIEW_STAT_BAR: if (GetMenuState(GetMenu(sheet), ID_VIEW_STAT_BAR, MF_BYCOMMAND) & MF_CHECKED) { ShowWindow(propdata.statusbar, SW_HIDE); CheckMenuItem(GetMenu(sheet), ID_VIEW_STAT_BAR, MF_BYCOMMAND); } else { ShowWindow(propdata.statusbar, SW_SHOW); CheckMenuItem(GetMenu(sheet), ID_VIEW_STAT_BAR, MF_BYCOMMAND | MF_CHECKED); } break; case ID_VIEW_MAP: if (GetMenuState(GetMenu(sheet), ID_VIEW_MAP, MF_BYCOMMAND) & MF_CHECKED) { // hide window ShowWindow(propdata.mapview, SW_HIDE); // clear check CheckMenuItem(GetMenu(sheet), ID_VIEW_MAP, MF_BYCOMMAND); } else { ShowWindow(propdata.mapview, SW_SHOW); CheckMenuItem(GetMenu(sheet), ID_VIEW_MAP, MF_BYCOMMAND | MF_CHECKED); } break; case ID_DRAW_TERRAIN: if (GetMenuState(GetMenu(sheet), ID_DRAW_TERRAIN, MF_BYCOMMAND) & MF_CHECKED) { setts.drawterrain = false; // clear check CheckMenuItem(GetMenu(sheet), ID_DRAW_TERRAIN, MF_BYCOMMAND); } else { setts.drawterrain = true; // clear check CheckMenuItem(GetMenu(sheet), ID_DRAW_TERRAIN, MF_BYCOMMAND | MF_CHECKED); } SendMessage(propdata.mapview, MAP_Reset, 0, 0); break; case ID_DRAW_ELEVATION: if (GetMenuState(GetMenu(sheet), ID_DRAW_ELEVATION, MF_BYCOMMAND) & MF_CHECKED) { setts.drawelevation = false; // clear check CheckMenuItem(GetMenu(sheet), ID_DRAW_ELEVATION, MF_BYCOMMAND); } else { setts.drawelevation = true; // clear check CheckMenuItem(GetMenu(sheet), ID_DRAW_ELEVATION, MF_BYCOMMAND | MF_CHECKED); } SendMessage(propdata.mapview, MAP_Reset, 0, 0); break; case ID_EDIT_ALL: if (GetMenuState(GetMenu(sheet), ID_EDIT_ALL, MF_BYCOMMAND) & MF_CHECKED) { setts.editall = false; // clear check CheckMenuItem(GetMenu(sheet), ID_EDIT_ALL, MF_BYCOMMAND); } else { setts.editall = true; CheckMenuItem(GetMenu(sheet), ID_EDIT_ALL, MF_BYCOMMAND | MF_CHECKED); } break; case ID_TOOLS_COMPRESS: OnCompressOrDecompress(sheet, true); break; case ID_TOOLS_DECOMPRESS: OnCompressOrDecompress(sheet, false); break; case ID_TS_HELP: WinHelp(sheet, "ts.hlp", HELP_CONTENTS, 0); break; case ID_TS_APP_ABOUT: DialogBoxParam(aokts, (LPCSTR)IDD_ABOUT, sheet, DefaultDialogProc, 0L); break; default: ret = false; } return ret; }
////////////////////////////////////////////////////////// // // CInstallManager::_ProcessLayoutChecks // // Make sure new reg/dir structure is ok // ////////////////////////////////////////////////////////// SString CInstallManager::_ProcessLayoutChecks ( void ) { // // Validation // // Check data dir exists { if ( !DirectoryExists ( GetMTADataPath () ) ) ShowLayoutError ( "[Data directory not present]" ); // Can't find directory } // Check reg key exists //{ // if ( GetRegistryValue ( "", "Last Install Location" ).empty () ) // ShowLayoutError ( "[Registry key not present]" ); // Can't find reg key //} // Check data dir writable { SString strTestFilePath = PathJoin ( GetMTADataPath (), "testdir", "testfile.txt" ); FileDelete ( strTestFilePath ); RemoveDirectory ( ExtractPath ( strTestFilePath ) ); SString strContent = "test"; if ( !FileSave ( strTestFilePath, strContent ) ) ShowLayoutError ( "[Data directory not writable]" ); // Can't save file FileDelete ( strTestFilePath ); RemoveDirectory ( ExtractPath ( strTestFilePath ) ); } // Check reg key writable { RemoveRegistryKey ( "testkeypath" ); SString strValue = GetTimeString( true, true ); SetRegistryValue ( "testkeypath", "testname", strValue ); SString strValueCheck = GetRegistryValue ( "testkeypath", "testname" ); if ( strValueCheck != strValue ) ShowLayoutError ( "[Registry key not writable]" ); // Can't write reg key RemoveRegistryKey ( "testkeypath" ); } // Check install dir writable { SString strTestFilePath = CalcMTASAPath ( PathJoin ( "mta", "writetest.txt" ) ); FileDelete ( strTestFilePath ); SString strContent = "test"; if ( !FileSave ( strTestFilePath, strContent ) ) ShowLayoutError ( "[Install directory not writable]" ); // Can't save file FileDelete ( strTestFilePath ); } // // Migration // // If news/temp/upcache folder doesn't exist in new, but does in old place, move it { const char* folders[] = { "news", "temp", "upcache" }; for ( uint i = 0 ; i < NUMELMS( folders ) ; i++ ) { SString strSrc = PathJoin ( GetSystemLocalAppDataPath (), "MTA San Andreas " + GetMajorVersionString (), folders[i] ); SString strDest = PathJoin ( GetMTADataPath (), folders[i] ); if ( !DirectoryExists ( strDest ) && DirectoryExists ( strSrc ) ) MoveFile ( strSrc, strDest ); } } // If aero option reg entry doesn't exist in new, but does in old place, move it { if ( GetApplicationSetting ( "aero-enabled" ).empty () ) { SString strLegacyValue = GetVersionRegistryValueLegacy ( GetMajorVersionString (), PathJoin ( "Settings", "general" ), "aero-enabled" ); if ( !strLegacyValue.empty () ) SetApplicationSettingInt ( "aero-enabled", atoi ( strLegacyValue ) ); else SetApplicationSettingInt ( "aero-enabled", 1 ); } } return "ok"; }
void CDownload::FileEnd(bool bError) { if (m_bShowProgress) { m_ProgressDialog.Destroy(); m_bShowProgress = false; } if (!InProgress()) return; #ifdef NOTUSED //j Code to examine the data for the MIME type CComObject<CAsyncDownload>* pbsc = NULL; HRESULT hr = CComObject<CAsyncDownload>::CreateInstance(&pbsc); if (SUCCEEDED(hr)) { LPWSTR pMimeOut = NULL; hr = ::FindMimeFromData(pbsc->m_spBindCtx, NULL/*pwzUrl*/, m_pData/*pBuffer*/, m_dwSize/*cbSize*/, NULL/*pwzMimeProposed*/, 0/*dwMimeFlags*/, &pMimeOut/*ppwzMimeOut*/, 0/*dwReserved*/); int i = 0; } #endif NOTUSED bool bPickingUpLeftovers = false; if (m_iFileType > 0) // Anything but a project file { // Is there any data to process? if (m_pData) { FileSave(); free(m_pData); m_pData = NULL; m_dwSize = 0; } // Pop the download item off the list m_List.erase(m_List.begin()); // Are there any more files in the list to download? if (!bError && Next()) return; // Yes, more files to download // No more files to download, so make the final callback after we do the Free() FNDOWNLOADCALLBACK fnCallback = m_fnCallback; LPARAM lParam = m_lParam; if (!m_pDataSaved) // Is there any leftover project data to pick up? Free(); if (fnCallback) fnCallback(lParam, NULL); if (!m_pDataSaved) // Is there any leftover project data to pick up? return; // No more files to download or process // Fall through to pick up any leftover project data bPickingUpLeftovers = true; m_pData = m_pDataSaved; m_pDataSaved = NULL; m_dwSize = m_dwSizeSaved; m_dwSizeSaved = 0; m_fnCallback = m_fnCallbackSaved; m_fnCallbackSaved = NULL; m_iFileType = 0; // A project file } // If this is not a project file, we are done if (m_iFileType != 0) return; // Is there any data to process? if (!m_pData) { Free(); return; } CAGDoc* pAGDoc = new CAGDoc(); if (!pAGDoc) { Free(); return; } // Set the Context License for the document. This must be called // prior to Read() below. CCtp* pCtp = (CCtp*)m_lParam; int iContextLicense = pCtp->GetContextLicense(); pAGDoc->SetContextLicense(iContextLicense); istrstream input((char*)m_pData, m_dwSize); bool bAdjusted = false; if (!pAGDoc->Read(input, bAdjusted)) { delete pAGDoc; CMessageBox::Message("Error reading the project data."); Free(); return; } // See if we need to start downloading any fonts if (!bPickingUpLeftovers) { // Pop the download item off the list m_List.erase(m_List.begin()); LOGFONTLIST lfProjectFontList; pAGDoc->GetFonts(lfProjectFontList); FONTDOWNLOADLIST List; pCtp->GetFontList().GetProjectFontList(lfProjectFontList, List, true/*bMissingOnly*/); if (!List.empty()) { delete pAGDoc; // Save the project data so we can pick it up later m_pDataSaved = m_pData; m_pData = NULL; m_dwSizeSaved = m_dwSize; m_dwSize = 0; m_fnCallbackSaved = m_fnCallback; m_fnCallback = NULL; // A whole new Init() process will begin, with the saved data being picked up when it's over Free(); // Download the fonts pCtp->FontListDownload(List); return; } } // Set the document name CComBSTR bstrSrcURL; pCtp->GetSrc(&bstrSrcURL); pAGDoc->SetFileName(CString(bstrSrcURL)); // Set the document as active CDocWindow* pDocWindow = pCtp->GetDocWindow(); if (pDocWindow) pDocWindow->SetDoc(pAGDoc); // No more files to download, so make the final callback after we do the Free() FNDOWNLOADCALLBACK fnCallback = m_fnCallback; LPARAM lParam = m_lParam; Free(); if (fnCallback) fnCallback(lParam, NULL); // If necessary, send the print command if (pCtp->AutoPrintEnabled()) pCtp->m_pDocWindow->SendMessage(WM_COMMAND, IDC_DOC_PRINT); }
void SharedUtil::SetReportLogContents ( const SString& strText ) { SString strPathFilename = PathJoin ( GetMTADataPath (), "report.log" ); MakeSureDirExists ( strPathFilename ); FileSave ( strPathFilename, strText.length () ? &strText.at ( 0 ) : NULL, strText.length () ); }