void CDrawShapeView::OnFileSave() { if (m_filename.IsEmpty()) { CFileDialog dlg(FALSE, L".vg", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST, L"Shape files (*.vg)|*.vg||", this); if (dlg.DoModal() != IDOK) return; m_filename = dlg.GetPathName(); } MgJsonStorage s; shapes()->setZoomRectW(m_graph->xf.getWndRectW(), m_graph->xf.getViewScale()); if (shapes()->save(s.storageForWrite())) { const char* content = s.stringify(true); CFile file; if (file.Open(m_filename, CFile::modeWrite | CFile::modeCreate)) { file.Write(content, strlen(content)); } } else { AfxMessageBox(L"得到文件内容出错。"); } }
bool GiCoreView::setCommand(GiView* view, const char* name, const char* params) { DrawLocker locker(impl); GcBaseView* aview = impl->_doc->findView(view); bool ret = false; if (aview) { impl->setView(aview); MgJsonStorage s; ret = impl->_cmds->setCommand(&impl->motion, name, s.storageForRead(params)); } return ret; }
bool GiCoreView::loadFromFile(const char* vgfile) { #if defined(_MSC_VER) && _MSC_VER >= 1400 // VC8 FILE *fp = NULL; fopen_s(&fp, vgfile, "rt"); #else FILE *fp = fopen(vgfile, "rt"); #endif DrawLocker locker(impl); MgJsonStorage s; bool ret = loadShapes(s.storageForRead(fp)); if (fp) { fclose(fp); } else { LOGE("Fail to open file: %s", vgfile); } return ret; }
bool GiCoreView::saveToFile(const char* vgfile, bool pretty) { #if defined(_MSC_VER) && _MSC_VER >= 1400 // VC8 FILE *fp = NULL; fopen_s(&fp, vgfile, "wt"); #else FILE *fp = fopen(vgfile, "wt"); #endif MgJsonStorage s; bool ret = (fp != NULL && saveShapes(s.storageForWrite()) && s.save(fp, pretty)); if (fp) { fclose(fp); } else { LOGE("Fail to open file: %s", vgfile); } return ret; }