/// <summary>Save list of levelsets into file</summary> public FunctionResult SaveList() { try { int i; IniHold.IniFile uList = new IniHold.IniFile();//Use ini engine System.IO.StreamWriter hWrite = new System.IO.StreamWriter(sFileName, false);//Open file for overwriting uList.SetWriter(hWrite);//Transmit file-writer into ini engine for (i = 0; i < iListUsed; i++)//Iterate thru whole list { uList.SaveItem("LevelSet", uLevelSets[i].sFileName);//Save filename uList.SaveItem("LevelsTotal", uLevelSets[i].iLevelsTotal.ToString());//Save total number of levels uList.SaveItem("LevelsSolved", uLevelSets[i].iLevelsSolved.ToString());//Save number of solved levels uList.SaveItem("Comment", uLevelSets[i].sComment);//Save user comment for levelset } hWrite.Close();//Close file } catch { //On any error - exit return FunctionResult.ErrorOnWritingFile; } return FunctionResult.OK;//Saved successfully }
///<summary>Save settings to ini file (filename)</summary> public FunctionResult Save(string sFileName) { IniHold.IniFile uIni = new IniHold.IniFile();//Ini-file parser System.IO.StreamWriter hAppend;//For writing files try { hAppend = new System.IO.StreamWriter(sFileName, false);//Open file for overwriting uIni.SetWriter(hAppend);//Transmit file to ini-file parser //Save all settings uIni.SaveItem("PlayerName",sPlayerName); uIni.SaveItem("Skin",sSkin); uIni.SaveItem("LevelSet",sLastLevelSet); uIni.SaveItem("Level",iLastLevelPlayed.ToString()); uIni.SaveItem("AnimateTravel",bAnimateTravel.ToString()); uIni.SaveItem("AnimateBoxPushing", bAnimateBoxPushing.ToString()); uIni.SaveItem("AnimateMassUndoRedo", bAnimateMassUndoRedo.ToString()); uIni.SaveItem("ShowOnlyUnsolvedLevels", bShowOnlyUnsolvedLevels.ToString()); uIni.SaveItem("AdditionalMessages", bAdditionalMessages.ToString()); uIni.SaveItem("AskRecordName", bAskRecordName.ToString()); uIni.SaveItem("AskSavingFirstSolution", bAskSavingFirstSolution.ToString()); uIni.SaveItem("AutocalcDeadlocks", bAutocalcDeadlocks.ToString()); uIni.SaveItem("DeadlockLimitsAutopush", bDeadlockLimitsAutopush.ToString()); uIni.SaveItem("KeepAliveMinutes", iKeepAliveMinutes.ToString()); uIni.SaveItem("Autosize", bAutosize.ToString()); uIni.SaveItem("AutosizeUseful", bAutosizeUseful.ToString()); uIni.SaveItem("AutosizeLowerLimit", iAutosizeLowerLimit.ToString()); uIni.SaveItem("SkinSet", sSkinSet.ToString()); uIni.SaveItem("BackgroundColor", iBackgroundColor.ToString("X").PadLeft(6,'0')); uIni.SaveItem("BackgroundImageFile", sBackgroundImageFile.ToString()); uIni.SaveItem("AnimationDelayTravel", iAnimationDelayTravel.ToString()); uIni.SaveItem("AnimationDelayBoxPushing", iAnimationDelayBoxPushing.ToString()); uIni.SaveItem("AnimationDelayMassUndoRedo", iAnimationDelayMassUndoRedo.ToString()); uIni.SaveItem("DragMinMove", iDragMinMove.ToString()); uIni.SaveItem("ScrollLock", bScrollLock.ToString()); uIni.SaveItem("LogActions", bLogActions.ToString()); uIni.SaveItem("BackgroundAutoDeadlocksLimit", iBackgroundAutoDeadlocksLimit.ToString()); hAppend.Close();//Close file return FunctionResult.OK;//Successfull } catch { return FunctionResult.ErrorOnWritingFile;//Some problems with writing file } }
///<summary>Save current position into file (filename, levelset name, level number, player name) ///!Recalc of stats should be done before calling</summary> public FunctionResult SavePosition(string sFileName) { System.IO.StreamWriter hWrite; try //Protection from file operations errors { hWrite = new System.IO.StreamWriter(sFileName, false);//Open file with overwrite IniHold.IniFile uIni = new IniHold.IniFile();//IniHold object - to store position as ini-file uIni.SetWriter(hWrite);//Transmit file-writer into inihold //Save level info, player info, statistics of positions uIni.SaveItem("Title", uGame.uStats.sName); uIni.SaveItem("LevelSet", uLevelSet.sFileName); uIni.SaveItem("Level", (uLevelSet.GetCurrentLevel()+1).ToString());//Saved level number is 1-based uIni.SaveItem("Player", uSetting.sPlayerName); uIni.SaveItem("Moves", uGame.uStats.iMoves.ToString()); uIni.SaveItem("Pushes", uGame.uStats.iPushes.ToString()); uIni.SaveItem("LinearMoves", uGame.uStats.iLinearMoves.ToString()); uIni.SaveItem("LinearPushes", uGame.uStats.iLinearPushes.ToString()); uIni.SaveItem("PushSessions", uGame.uStats.iPushSessions.ToString()); uIni.SaveItem("BoxChanges", uGame.uStats.iBoxChanges.ToString()); //And position uIni.SaveItem("Position", uGame.GetPositionLuRd()); hWrite.Close();//Close file return FunctionResult.OK; } catch { return FunctionResult.ErrorOnWritingFile;//On error - return indication } }