Example #1
0
/*
	FileSave: Handles a request to save the currently open file.

	Parameters:
	HWND sheet: Handle to the property sheet.
	bool as:		Save or Save As?
*/
void FileSave(HWND sheet, bool as, bool write)
{
	int error;			//error value from Scenario::save()
	HWND cpage;			//the current property page
	HCURSOR previous;	//the mouse cursor before/after save operation
	OPENFILENAME ofn;
	char titleBuffer[100];
	Game startver;
	Game conv = NOCONV;
    SaveFlags::Value flags = SaveFlags::NONE;

    char w1[] = {84, 104, 105, 115, 32, 115, 99, 101, 110, 97, 114, 105, 111, 32, 105, 115, 32, 112, 114, 111, 116, 101, 99, 116, 101, 100, 0};
    char w2[] = {83, 99, 101, 110, 97, 114, 105, 111, 32, 105, 115, 32, 112, 114, 111, 116, 101, 99, 116, 101, 100, 0};
    if (setts.disabletips) {
        MessageBox(sheet, w1, w2, MB_ICONWARNING);
        return;
    }

	//init
	cpage = PropSheet_GetCurrentPageHwnd(sheet);

	//Save As: Ask for filename.
	if (as || *setts.ScenPath == '\0')
	{
		char dir[_MAX_PATH];
		strcpy(dir, setts.BasePath);
		strcat(dir, "Scenario");

		ofn.lStructSize = sizeof(OPENFILENAME);
		ofn.hwndOwner = sheet;
		ofn.lpstrFilter = extSave;
		ofn.lpstrCustomFilter = NULL;
		ofn.lpstrFile = setts.ScenPath;
		ofn.nMaxFile = _MAX_PATH;
		ofn.lpstrFileTitle = NULL;
		ofn.lpstrInitialDir = dir;
		ofn.lpstrTitle = NULL;
		ofn.Flags = OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT;

	    startver = scen.game;

		if (scen.header.header_type == HT_AOE2SCENARIO) {
		    ofn.nFilterIndex =	6;
		    ofn.lpstrDefExt =	"aoe2scenario";
		} else {
		    switch (scen.game) {
		    case AOK:
		        ofn.nFilterIndex =	1;
		        ofn.lpstrDefExt =	"scn";
		        break;
		    case AOC:
		        ofn.nFilterIndex =	2;
		        ofn.lpstrDefExt =	"scx";
		        break;
		    case UP:
		        ofn.nFilterIndex =	3;
		        ofn.lpstrDefExt =	"scx";
		        break;
		    case AOHD:
		    case AOHD4:
		        ofn.nFilterIndex =	4;
		        ofn.lpstrDefExt =	"scx";
		        break;
		    case AOF:
		    case AOF4:
		        ofn.nFilterIndex =	5;
		        ofn.lpstrDefExt =	"scx2";
		        break;
		    case SWGB:
		        ofn.nFilterIndex =	7;
		        ofn.lpstrDefExt =	"scx";
		        break;
		    case SWGBCC:
		        ofn.nFilterIndex =	8;
		        ofn.lpstrDefExt =	"sc1";
		        break;
		    case AOHD6:
		        ofn.nFilterIndex =	9;
		        ofn.lpstrDefExt =	"scx";
		        break;
		    case AOF6:
		        ofn.nFilterIndex =	10;
		        ofn.lpstrDefExt =	"scx2";
		        break;
		    }
		}

		if (!GetSaveFileName(&ofn))
			return;

		switch (ofn.nFilterIndex) {
		case 1:
		    conv = AOK;
		    break;
		case 2:
		    conv = AOC;
		    break;
		case 3:
		    conv = UP;
		    break;
		case 4:
		    conv = AOHD4;
		    break;
		case 5:
		    conv = AOF4;
		    break;
		case 6:
	        scen.header.header_type = HT_AOE2SCENARIO;
		    conv = startver;
		    break;
		case 7:
		    conv = SWGB;
		    break;
		case 8:
		    conv = SWGBCC;
		    break;
		case 9:
		    conv = AOHD6;
		    break;
		case 10:
		    conv = AOF6;
		    break;
		}

		if (!*scen.origname)
			strcpy(scen.origname, setts.ScenPath + ofn.nFileOffset);

		/* Update window title since filename has probably changed */
		_snprintf(titleBuffer, sizeof(titleBuffer),
			"%s - %s", szTitle, setts.ScenPath + ofn.nFileOffset);
		SetWindowText(sheet, titleBuffer);
	} else {
	    conv = scen.game;
	}

    if (isHD(startver) && conv == UP) {
        if (setts.asktoconverteffects &&
            MessageBox(sheet, "Also convert HD effects to UserPatch?", "Convert", MB_YESNOCANCEL) == IDYES) {
            flags = (SaveFlags::Value)(flags | SaveFlags::CONVERT_EFFECTS);
        }
    }

    if (startver == UP && isHD(conv)) {
        if (setts.asktoconverteffects &&
            MessageBox(sheet, "Also convert UserPatch effects to HD?", "Convert", MB_YESNOCANCEL) == IDYES) {
            flags = (SaveFlags::Value)(flags | SaveFlags::CONVERT_EFFECTS);
        }
    }

	//update scenario data
	SendMessage(cpage, AOKTS_Saving, 0, 0);

	//perform before-saving operations
	previous = SetCursor(LoadCursor(NULL, IDC_WAIT));
	// Pretend we're "closing" the scenario because it may change during the
	// save.
	SendMessage(cpage, AOKTS_Closing, 0, 0);
	scen.clean_triggers();

	//save the scenario
	try
	{
 		error = scen.save(setts.ScenPath, setts.TempPath, write, conv, flags);
		SetCursor(previous);

	    struct RecentFile *file = NULL;	//the file info will be stored here one way or another
		struct RecentFile *r_parse;

		/* Now check if 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;
		}

        if (file) {
            file->game = (int)conv;
        } else {
		    file = setts.recent_getnext();
		    strcpy(file->path, setts.ScenPath);
		    strcpy(file->display, PathFindFileName(setts.ScenPath));
		    file->game = (int)conv;
	        setts.recent_push(file);
	    }
	    UpdateRecentMenu(propdata.menu);
	}
	catch (std::exception &ex)
	{
		// TODO: better atomic cursor handling?
		SetCursor(previous);
		MessageBox(sheet, ex.what(), "Scenario Save Error", MB_ICONWARNING);
	}

	//perform after-saving operations
	SendMessage(cpage, AOKTS_Loading, 0, 0);

	//report any errors
	if (error)
	{
		SetWindowText(propdata.statusbar, scen.msg);
		//MessageBox(sheet, scen.msg, "Save Error", MB_OK);
	}
}
Example #2
0
/*
	FileSave: Handles a request to save the currently open file.

	Parameters:
	HWND sheet: Handle to the property sheet.
	bool as:		Save or Save As?
*/
void FileSave(HWND sheet, bool as, bool write)
{
	int error;			//error value from Scenario::save()
	HWND cpage;			//the current property page
	HCURSOR previous;	//the mouse cursor before/after save operation
	OPENFILENAME ofn;
	char titleBuffer[100];
	Game startver;
	Game conv = NOCONV;
    SaveFlags::Value flags = SaveFlags::NONE;

	//init
	cpage = PropSheet_GetCurrentPageHwnd(sheet);

	//Save As: Ask for filename.
	if (as || *setts.ScenPath == '\0')
	{
		char dir[_MAX_PATH];
		strcpy(dir, setts.BasePath);
		strcat(dir, "Scenario");

		ofn.lStructSize = sizeof(OPENFILENAME);
		ofn.hwndOwner = sheet;
		ofn.lpstrFilter = extSave;
		ofn.lpstrCustomFilter = NULL;
		ofn.lpstrFile = setts.ScenPath;
		ofn.nMaxFile = _MAX_PATH;
		ofn.lpstrFileTitle = NULL;
		ofn.lpstrInitialDir = dir;
		ofn.lpstrTitle = NULL;
		ofn.Flags = OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT;

	    startver = scen.game;

		switch (scen.game) {
		case AOK:
		    ofn.nFilterIndex =	1;
		    ofn.lpstrDefExt =	"scn";
		    break;
		case AOC:
		    ofn.nFilterIndex =	2;
		    ofn.lpstrDefExt =	"scx";
		    break;
		case UP:
		    ofn.nFilterIndex =	3;
		    ofn.lpstrDefExt =	"scx";
		    break;
		case AOHD:
		case AOHD4:
		    ofn.nFilterIndex =	4;
		    ofn.lpstrDefExt =	"scx";
		    break;
		case AOF:
		case AOF4:
		    ofn.nFilterIndex =	5;
		    ofn.lpstrDefExt =	"scx2";
		    break;
		case SWGB:
		    ofn.nFilterIndex =	6;
		    ofn.lpstrDefExt =	"scx";
		    break;
		case SWGBCC:
		    ofn.nFilterIndex =	7;
		    ofn.lpstrDefExt =	"sc1";
		    break;
		case AOHD6:
		    ofn.nFilterIndex =	8;
		    ofn.lpstrDefExt =	"scx";
		    break;
		case AOF6:
		    ofn.nFilterIndex =	9;
		    ofn.lpstrDefExt =	"scx2";
		    break;
		}

		if (!GetSaveFileName(&ofn))
			return;

		switch (ofn.nFilterIndex) {
		case 1:
		    conv = AOK;
		    break;
		case 2:
		    conv = AOC;
		    break;
		case 3:
		    conv = UP;
		    break;
		case 4:
		    conv = AOHD4;
		    break;
		case 5:
		    conv = AOF4;
		    break;
		case 6:
		    conv = SWGB;
		    break;
		case 7:
		    conv = SWGBCC;
		    break;
		case 8:
		    conv = AOHD6;
		    break;
		case 9:
		    conv = AOF6;
		    break;
		}

		if (!*scen.origname)
			strcpy(scen.origname, setts.ScenPath + ofn.nFileOffset);

		/* Update window title since filename has probably changed */
		_snprintf(titleBuffer, sizeof(titleBuffer),
			"%s - %s", szTitle, setts.ScenPath + ofn.nFileOffset);
		SetWindowText(sheet, titleBuffer);
	} else {
	    conv = scen.game;
	}

    if ((startver == AOHD || startver == AOF || startver == AOHD4 || startver == AOF4 || startver == AOHD6 || startver == AOF6) && conv == UP) {
        if (setts.asktoconverteffects &&
            MessageBox(sheet, "Also convert HD effects to UserPatch?", "Convert", MB_YESNOCANCEL) == IDYES) {
            flags = (SaveFlags::Value)(flags | SaveFlags::CONVERT_EFFECTS);
        }
    }

    if (startver == UP && (conv == AOHD || conv == AOF || conv == AOHD4 || conv == AOF4 || conv == AOHD6 || conv == AOF6)) {
        if (setts.asktoconverteffects &&
            MessageBox(sheet, "Also convert UserPatch effects to HD?", "Convert", MB_YESNOCANCEL) == IDYES) {
            flags = (SaveFlags::Value)(flags | SaveFlags::CONVERT_EFFECTS);
        }
    }

	//update scenario data
	SendMessage(cpage, AOKTS_Saving, 0, 0);

	//perform before-saving operations
	previous = SetCursor(LoadCursor(NULL, IDC_WAIT));
	// Pretend we're "closing" the scenario because it may change during the
	// save.
	SendMessage(cpage, AOKTS_Closing, 0, 0);
	scen.clean_triggers();

	//save the scenario
	try
	{
 		error = scen.save(setts.ScenPath, setts.TempPath, write, conv, flags);
		SetCursor(previous);
	}
	catch (std::exception &ex)
	{
		// TODO: better atomic cursor handling?
		SetCursor(previous);
		MessageBox(sheet, ex.what(), "Scenario Save Error", MB_ICONWARNING);
	}

	//perform after-saving operations
	SendMessage(cpage, AOKTS_Loading, 0, 0);

	//report any errors
	if (error)
	{
		SetWindowText(propdata.statusbar, scen.msg);
		//MessageBox(sheet, scen.msg, "Save Error", MB_OK);
	}
}