//--------------------------------------------------------------------------- void TData::Import(const std::wstring &FileName) { if(std::_waccess(FileName.c_str(), 0)) throw EGraphError(LoadRes(RES_FILE_NOT_FOUND, FileName)); TConfigFile ConfigFile; ConfigFile.LoadFromUtf8File(FileName); std::wstring SavedByVersion = ConfigFile.Section(L"Graph").Read(L"Version", L"NA"); if(SavedByVersion == L"NA") throw EGraphError(LoadRes(RES_NOT_GRAPH_FILE, FileName)); if(TVersion(SavedByVersion) <= L"2.4") throw EGraphError(LoadRes(RES_INVALID_VERSION, SavedByVersion, L"2.5")); try { if(SavedByVersion < TVersion(L"4.4.0.414")) ConfigFile.LoadFromAnsiFile(FileName); Import(ConfigFile); } catch(Func32::EFuncError &Error) { throw; } catch(...) { throw EGraphError(LoadRes(RES_ERROR_READING_FILE, FileName)); } }
unsigned char *CNwnKeyFile::LoadRes (const Resource *psRes, UINT32 *pulSize, bool *pfAllocated) { // // Invoke the helper // return LoadRes (GetBifIndexFromRes (psRes), GetBifResIDFromRes (psRes), pulSize, pfAllocated); }
unsigned char *CNwnKeyFile::LoadRes (const char *pszName, NwnResType nResType, UINT32 *pulSize, bool *pfAllocated) { // // Find the resource // const Resource *psRes = FindRes (pszName, nResType); if (psRes == NULL) return NULL; // // Invoke the helper // return LoadRes (psRes, pulSize, pfAllocated); }
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { hge = hgeCreate(HGE_VERSION); hge->System_SetState(HGE_LOGFILE, "50Prob.log"); hge->System_SetState(HGE_SCREENHEIGHT, 600); hge->System_SetState(HGE_SCREENWIDTH, 300); hge->System_SetState(HGE_SCREENBPP, 32); hge->System_SetState(HGE_DONTSUSPEND, true); hge->System_SetState(HGE_SHOWSPLASH, false); hge->System_SetState(HGE_TITLE, "50 Problems"); hge->System_SetState(HGE_WINDOWED, true); hge->System_SetState(HGE_ZBUFFER, true); hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); hge->System_SetState(HGE_RENDERFUNC, RenderFunc); hge->System_SetState(HGE_ICON, "IDI_50PROB"); if(hge->System_Initiate()) { hge->Resource_AttachPack("Res.x2pak", "X2Studio"); rscript = new hgeResourceManager("res"); if(LoadRes()) hge->System_Start(); else MessageBox(NULL, "Wrong resource.", "Wrong", MB_ICONSTOP); } else MessageBox(NULL, "There are problems with initialization.", "Wrong", MB_ICONSTOP); while(!blocklist.empty()) { delete blocklist.front(); blocklist.pop_front(); } hge->System_Shutdown(); hge->Release(); return 0; }
//--------------------------------------------------------------------------- //Saves data to file given in FileName; if empty the user is requested a file name //If Remember is true this will be the new current file name bool TData::Save(const std::wstring &FileName, bool Remember) const { try { TConfigFile IniFile; std::wstring Comment = L"This file was created by Graph (http://www.padowan.dk)\nDo not change this file from other programs."; IniFile.SetComment(Comment); WriteInfoToIni(IniFile); SaveData(IniFile); CustomFunctions.WriteToIni(IniFile.Section(L"CustomFunctions")); AnimationInfo.WriteToIni(IniFile.Section(L"Animate")); TConfigFileSection &Section = IniFile.Section(L"PluginData"); for(std::map<std::wstring,std::wstring>::const_iterator Iter = PluginData.begin(); Iter != PluginData.end(); ++Iter) Section.Write(Iter->first, Iter->second); // SaveImage(IniFile); if(!IniFile.SaveToUtf8File(FileName)) return false; if(Remember) { GrfName = FileName; Application->MainForm->Caption = String(NAME) + " - " + GrfName.c_str(); Application->Title = String(NAME) + " - " + ExtractFileName(GrfName.c_str()); Modified = false; } SendOleAdvise(acDataSaved); //Notify OLE client that data has been saved return true; } catch(EFCreateError &E) { MessageBox(LoadRes(RES_FILE_ACCESS, FileName), LoadString(RES_WRITE_FAILED), MB_ICONSTOP); return false; } }
//--------------------------------------------------------------------------- bool TData::ImportPointSeries(const std::wstring &FileName, char Separator) { const TColor Colors[] = {clRed, clGreen, clBlue, clYellow, clPurple, clAqua, clBlack, clGray, clSkyBlue , clMoneyGreen, clDkGray}; std::ifstream Stream(FileName.c_str()); if(!Stream) { MessageBox(LoadRes(RES_NOT_GRAPH_FILE, FileName), LoadString(RES_FILE_ERROR), MB_ICONSTOP); return false; } std::string Line; while(Stream && Line.empty()) std::getline(Stream, Line); if(Separator == 0) Separator = GetSeparator(Line); std::vector<std::pair<std::wstring, std::vector<TPointSeriesPoint> > > Points; unsigned Row = 0; try { boost::escaped_list_separator<char> Sep("", std::string(1, Separator), ""); unsigned Index = 0; do { ++Row; boost::tokenizer<boost::escaped_list_separator<char> > tok(Line, Sep); boost::tokenizer<boost::escaped_list_separator<char> >::iterator beg = tok.begin(); std::wstring xStr = ToWString(*beg); if(!xStr.empty() && xStr[0] == L'#') { Index = Points.size(); Points.push_back(std::make_pair(xStr.substr(1), std::vector<TPointSeriesPoint>())); while(++beg != tok.end()) Points.push_back(std::make_pair(ToWString(*beg), std::vector<TPointSeriesPoint>())); } else { unsigned Col = Index; while(++beg != tok.end()) { if(Col == Points.size()) Points.push_back(std::make_pair(L"", std::vector<TPointSeriesPoint>())); std::wstring yStr = ToWString(*beg); if(Property.DecimalSeparator != '.') { std::replace(xStr.begin(), xStr.end(), Property.DecimalSeparator, L'.'); std::replace(yStr.begin(), yStr.end(), Property.DecimalSeparator, L'.'); } Points[Col].second.push_back(TPointSeriesPoint(xStr, yStr)); Col++; } } } while(std::getline(Stream, Line)); } catch(Func32::EParseError &E) { MessageBox(LoadRes(526, FileName.c_str(), Row+1), LoadRes(RES_FILE_ERROR), MB_ICONSTOP); return false; } catch(std::out_of_range &E) { MessageBox(LoadRes(526, FileName.c_str(), Row+1), LoadRes(RES_FILE_ERROR), MB_ICONSTOP); return false; } catch(std::bad_alloc &E) { MessageBox(LoadRes(RES_OUT_OF_MEMORY), LoadRes(RES_FILE_ERROR), MB_ICONSTOP); return false; } unsigned ColorIndex = 0; unsigned Style = Property.DefaultPoint.Style; unsigned LineStyle = Property.DefaultPointLine.Style; UndoList.BeginMultiUndo(); for(unsigned I = 0; I < Points.size(); I++) { boost::shared_ptr<TPointSeries> Series(new TPointSeries( clBlack, //FrameColor Colors[ColorIndex], //FillColor Colors[ColorIndex], //LineColor Property.DefaultPoint.Size, //Size Property.DefaultPointLine.Size, //LineSize Style, //Style static_cast<TPenStyle>(LineStyle), //LineStyle iaLinear, //Onterpolation false, //ShowLabels Property.DefaultPointLabelFont, //Font lpBelow, //LabelPosition ptCartesian, //PointType ebtNone, //xErrorBarType 0, //xErrorValues ebtNone, //yErrorBarType 0 //yErrorValue )); Series->Swap(Points[I].second); Series->SetLegendText(Points[I].first.empty() ? CreatePointSeriesDescription() : Points[I].first); Insert(Series); UndoList.Push(TUndoAdd(Series)); Series->Update(); ColorIndex = ++ColorIndex % (sizeof(Colors)/sizeof(TColor)); Style = (Style+1) % 7; LineStyle = (LineStyle+1) % 5; } UndoList.EndMultiUndo(); Modified = true; return true; }
//--------------------------------------------------------------------------- void TData::LoadFromFile(const std::wstring &FileName) { TConfigFile IniFile; IniFile.LoadFromUtf8File(FileName); CheckIniInfo(IniFile); std::wstring SavedByVersion = IniFile.Section(L"Graph").Read(L"Version", L"NA"); if(SavedByVersion == L"NA") { if(std::_waccess(FileName.c_str(), 0)) throw EGraphError(LoadRes(RES_FILE_NOT_FOUND, FileName)); throw EGraphError(LoadRes(RES_NOT_GRAPH_FILE, FileName)); } try { GrfName = FileName; //Free mem in function lists Clear(); if(SavedByVersion < TVersion(L"4.4.0.414")) IniFile.LoadFromAnsiFile(FileName); PreprocessGrfFile(IniFile); Axes.ReadFromIni(IniFile.Section(L"Axes")); //Adjust TickUnit and GridUnit if saved by an outdated version if(SavedByVersion < TVersion(L"3.2")) { if(Axes.xAxis.LogScl) { Axes.xAxis.TickUnit = std::pow(10, Axes.xAxis.TickUnit); Axes.xAxis.GridUnit = std::pow(10, Axes.xAxis.GridUnit); } if(Axes.yAxis.LogScl) { Axes.yAxis.TickUnit = std::pow(10, Axes.yAxis.TickUnit); Axes.yAxis.GridUnit = std::pow(10, Axes.yAxis.GridUnit); } } if(SavedByVersion < TVersion(L"4.0")) { std::swap(Axes.xAxis.AxisCross, Axes.yAxis.AxisCross); } CustomFunctions.ReadFromIni(IniFile.Section(L"CustomFunctions")); CustomFunctions.Update(*this); LoadData(IniFile); AnimationInfo.ReadFromIni(IniFile.Section(L"Animate")); LoadPluginData(IniFile.Section(L"PluginData")); } catch(Func32::EFuncError &Error) { throw; } catch(std::bad_alloc &E) { throw EGraphError(LoadString(RES_OUT_OF_MEMORY)); } catch(...) { throw EGraphError(LoadRes(RES_ERROR_READING_FILE, FileName)); } Modified = false; }
int CDataSourceKey::Export (DataElement *pElement, const char *pszFileName) { // // Based on the type // int nCount = 0; switch (pElement ->usType) { case Type_Root: break; case Type_Bif: { CString strDir (pszFileName); int nBifIndex = pElement ->ulIndex1; int nResCount = m_pKeyFile ->GetResCount (); for (int i = 0; i < nResCount; i++) { if (nBifIndex != m_pKeyFile -> GetBifIndexFromRes (&m_pasRes [i])) continue; CData *pData = LoadRes (&m_pasElements [i]); if (pData) { char szName [_MAX_PATH]; GetResourceText (&m_pasElements [i], szName, _countof (szName)); CString str (strDir + szName); if (pData ->SaveToFile (str)) nCount++; pData ->AddRef (); pData ->Release (); } } } break; case TypeResourceClass: { CString strDir (pszFileName); int nBifIndex = pElement ->ulIndex1; int nResCount = m_pKeyFile ->GetResCount (); for (int i = 0; i < nResCount; i++) { if (nBifIndex != m_pKeyFile -> GetBifIndexFromRes (&m_pasRes [i])) continue; if (pElement ->usIndex2 != GetResourceClass ( (NwnResType) m_pasRes [i] .usType)) continue; CData *pData = LoadRes (&m_pasElements [i]); if (pData) { char szName [_MAX_PATH]; GetResourceText (&m_pasElements [i], szName, _countof (szName)); CString str (strDir + szName); if (pData ->SaveToFile (str)) nCount++; pData ->AddRef (); pData ->Release (); } } } break; case TypeResourceource: { CData *pData = LoadRes (pElement); if (pData) { if (pData ->SaveToFile (pszFileName)) nCount++; pData ->AddRef (); pData ->Release (); } } break; } return nCount; }
AnimationManage::AnimationManage(const char* name) { LoadRes(name); }