Exemplo n.º 1
0
BOOL CDocument::CanCloseFrame(CFrameWnd* pFrameArg)
	// permission to close all views using this frame
	//  (at least one of our views must be in this frame)
{
	ASSERT_VALID(pFrameArg);
	UNUSED(pFrameArg);   // unused in release builds

	POSITION pos = GetFirstViewPosition();
	while (pos != NULL)
	{
		CView* pView = GetNextView(pos);
		ASSERT_VALID(pView);
		CFrameWnd* pFrame = pView->GetParentFrame();
		// assume frameless views are ok to close
		if (pFrame != NULL)
		{
			// assumes 1 document per frame
			ASSERT_VALID(pFrame);
			if (pFrame->m_nWindow > 0)
				return TRUE;        // more than one frame refering to us
		}
	}

	// otherwise only one frame that we know about
	return SaveModified();
}
Exemplo n.º 2
0
void CDocument::OnFileClose()
/***************************/
{
    if( SaveModified() ) {
        OnCloseDocument();
    }
}
Exemplo n.º 3
0
// Goober5000
void CFREDDoc::OnFileImportFSM() 
{
	CString fs1_mission_mfc;
	char fs1_mission[MAX_PATH_LEN];
	char *ch;
	char temp[MAX_PATH_LEN];

	// if mission has been modified, offer to save before continuing.
	if (!SaveModified())
		return;

	// set up import dialog
	CFileDialog dlg(TRUE, "fsm", NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR, "FreeSpace Missions (*.fsm)|*.fsm|All files (*.*)|*.*||");
	dlg.m_ofn.lpstrTitle = "Select a mission to import";

	// set initial path
	strcpy(temp, Fred_exe_dir);
	if ((ch = stristr(temp, "FreeSpace2")) >= 0)
	{
		strcpy(ch, "FreeSpace\\Data\\Missions");
		dlg.m_ofn.lpstrInitialDir = temp;
	}

	// get FSM file
	if (dlg.DoModal() != IDOK)
		return;

	fs1_mission_mfc = dlg.GetPathName();

	if (strlen(fs1_mission_mfc) > MAX_PATH_LEN - 1)
	{
		MessageBox(NULL, "Path name is too long", "Error", MB_OK);
		return;
	}

	if (!strlen(fs1_mission_mfc))
	{
		return;
	}

	strcpy(fs1_mission, fs1_mission_mfc);

	// load mission into memory
	if (Briefing_dialog)
		Briefing_dialog->icon_select(-1);  // clean things up first
	if (load_mission(fs1_mission, 1))
		return;

	// ugh - change the file name
	FREDDoc_ptr->SetPathName("Untitled");

	// we haven't saved it yet
	set_modified(TRUE);

	// error check and notify
	if (!Fred_view_wnd->global_error_check())
	{
		Fred_view_wnd->MessageBox("Mission successfully imported with no errors.", "Woohoo!");
	}
}
Exemplo n.º 4
0
void CDocument::OnFileClose()
{
	if (!SaveModified())
		return;

	// shut it down
	OnCloseDocument();
		// this should destroy the document
}
Exemplo n.º 5
0
BOOL CDocument::CanCloseFrame( CFrameWnd *pFrame )
/************************************************/
{
    POSITION position = m_viewList.GetHeadPosition();
    while( position != NULL ) {
        CView *pView = (CView *)m_viewList.GetNext( position );
        if( pView->GetDocument() == this && pView->GetParentFrame() != pFrame ) {
            return( TRUE );
        }
    }
    return( SaveModified() );
}
Exemplo n.º 6
0
void CCombineTitleByTimeDlg::OnBnClickedBtnBrowstd()
{
	CFile fileOpen;
	if((DoFilePrompt(m_strStdFile))
		&&(fileOpen.Open(m_strStdFile, CFile::modeRead)))
	{
		AfxGetApp()->BeginWaitCursor();
		CTitleFile::DeleteContents(m_TitleRel.GetLeftVT());
		CTitleFile::ReadTitleFile(&fileOpen, m_TitleRel.GetLeftVT(), m_strFmtHdr, m_bStdUnicode);
		SaveModified();

		m_TitleRel.BuildRelation(BUILD_TYPE_ORGTEXT);
		m_ListTitleStd.SetItemCount(m_TitleRel.GetRelCount());
		m_ListTitleTrans.SetItemCount(m_TitleRel.GetRelCount());
		AfxGetApp()->EndWaitCursor();
	}
	UpdateData(FALSE);
}
Exemplo n.º 7
0
void CCombineTitleByTimeDlg::OnBnClickedSave()
{
	CFile fileOpen;
	if(fileOpen.Open(m_strStdFile, CFile::modeWrite))
	{
		CString strExt = PathFindExtension(m_strStdFile);
		DWORD dwFmt = FMTFLAG_SRT;
		if(strExt.CompareNoCase(_T(".ssa")) == 0)
		{
			dwFmt = FMTFLAG_SSA;
		}
		else if(strExt.CompareNoCase(_T(".ass")) == 0)
		{
			dwFmt = FMTFLAG_ASS;
		}
		CTitleFile::WriteTitleFile(&fileOpen, m_TitleRel.GetLeftVT(), m_strFmtHdr, CString(_T("")), CString(_T("")), dwFmt, m_bStdUnicode);
		SaveModified();
	}
}
Exemplo n.º 8
0
void CVisualADSDoc::MyOnClose()
{
	// TODO: 在此添加命令处理程序代码
	if (!SaveModified())
		return;
	
	BOOL bAutoDelete = m_bAutoDelete;
	m_bAutoDelete = FALSE; // don't destroy document while closing views
	while (!m_viewList.IsEmpty())
	{
		// get view attached to the document
		CView* pView = (CView*)m_viewList.GetHead();
		ASSERT_VALID(pView);
		pView->DestroyWindow();
	}
	m_bAutoDelete = bAutoDelete;
	
	// clean up contents of document before destroying the document itself
	DeleteContents();
	
	// delete the document if necessary
	if (m_bAutoDelete)
		delete this;
}
Exemplo n.º 9
0
void CFREDDoc::OnFileImportFSM() {
	char fs1_mission_path[MAX_PATH_LEN];
	char fs2_mission_path[MAX_PATH_LEN];
	char dest_directory[MAX_PATH + 1];

	// path stuff
	{
		char *ch;

		// get base paths
		strcpy_s(fs1_mission_path, Fred_exe_dir);
		ch = strrchr(fs1_mission_path, DIR_SEPARATOR_CHAR);
		if (ch != NULL)
			*ch = '\0';
		strcpy_s(fs2_mission_path, Fred_exe_dir);
		ch = strrchr(fs2_mission_path, DIR_SEPARATOR_CHAR);
		if (ch != NULL)
			*ch = '\0';

		// estimate the mission path for FS1
		if ((ch = stristr(fs1_mission_path, "FreeSpace2")) != NULL) {
			strcpy(ch, "FreeSpace\\Data\\Missions");
		}

		// estimate the mission path for FS2
		strcat_s(fs2_mission_path, "\\Data\\Missions");
	}

	// if mission has been modified, offer to save before continuing.
	if (!SaveModified())
		return;


	// get location to import from
	CFileDialog dlgFile(TRUE, "fsm", NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_ALLOWMULTISELECT, "FreeSpace Missions (*.fsm)|*.fsm|All files (*.*)|*.*||");
	dlgFile.m_ofn.lpstrTitle = "Select one or more missions to import";
	dlgFile.m_ofn.lpstrInitialDir = fs1_mission_path;

	// get FSM files
	if (dlgFile.DoModal() != IDOK)
		return;

	memset(dest_directory, 0, sizeof(dest_directory));

	// get location to save to    
#if ( _MFC_VER >= 0x0700 )
	//ITEMIDLIST fs2_mission_pidl = {0};

	//SHParseDisplayName(A2CW(fs2_mission_path), NULL, fs2_mission_pidl, 0, 0);

	BROWSEINFO bi;
	bi.hwndOwner = theApp.GetMainWnd()->GetSafeHwnd();
	//bi.pidlRoot = &fs2_mission_pidl;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = dest_directory;
	bi.lpszTitle = "Select a location to save in";
	bi.ulFlags = 0;
	bi.lpfn = NULL;
	bi.lParam = NULL;
	bi.iImage = NULL;

	LPCITEMIDLIST ret_val = SHBrowseForFolder(&bi);

	if (ret_val == NULL)
		return;

	SHGetPathFromIDList(ret_val, dest_directory);
#else
	CFolderDialog dlgFolder(_T("Select a location to save in"), fs2_mission_path, NULL);
	if (dlgFolder.DoModal() != IDOK)
		return;

	strcpy_s(dest_directory, dlgFolder.GetFolderPath());
#endif

	// clean things up first
	if (Briefing_dialog)
		Briefing_dialog->icon_select(-1);

	clear_mission();

	// process all missions
	POSITION pos(dlgFile.GetStartPosition());
	while (pos) {
		char *ch;
		char filename[1024];
		char fs1_path[MAX_PATH_LEN];
		char dest_path[MAX_PATH_LEN];

		CString fs1_path_mfc(dlgFile.GetNextPathName(pos));
		CFred_mission_save save;

		DWORD attrib;
		FILE *fp;


		// path name too long?
		if (strlen(fs1_path_mfc) > MAX_PATH_LEN - 1)
			continue;

		// nothing here?
		if (!strlen(fs1_path_mfc))
			continue;

		// get our mission
		strcpy_s(fs1_path, fs1_path_mfc);

		// load mission into memory
		if (load_mission(fs1_path, MPF_IMPORT_FSM))
			continue;

		// get filename
		ch = strrchr(fs1_path, DIR_SEPARATOR_CHAR) + 1;
		if (ch != NULL)
			strcpy_s(filename, ch);
		else
			strcpy_s(filename, fs1_path);

		// truncate extension
		ch = strrchr(filename, '.');
		if (ch != NULL)
			*ch = '\0';

		// add new extension
		strcat_s(filename, ".fs2");

		strcpy_s(Mission_filename, filename);

		// get new path
		strcpy_s(dest_path, dest_directory);
		strcat_s(dest_path, "\\");
		strcat_s(dest_path, filename);

		// check attributes
		fp = fopen(dest_path, "r");
		if (fp) {
			fclose(fp);
			attrib = GetFileAttributes(dest_path);
			if (attrib & FILE_ATTRIBUTE_READONLY)
				continue;
		}

		// try to save it
		if (save.save_mission_file(dest_path))
			continue;

		// success
	}

	create_new_mission();

	MessageBox(NULL, "Import complete.  Please check the destination folder to verify all missions were imported successfully.", "Status", MB_OK);
	recreate_dialogs();
}