private static string getDataFile (Configuration.dataLevel type)
		{
			switch (type) {
			case Configuration.dataLevel.game:
				// This happens when this is called before a save is loaded or created
				if (HighLogic.SaveFolder == "DestructiblesTest")
					return "";
				return(KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/" + TT_DATAFILE);

			case Configuration.dataLevel.install:
				return(CONFIG_BASE_FOLDER + TT_DATAFILE);

			case Configuration.dataLevel.global:
				if (TotalTime.config.totalTimeDataPath == "")
					return "";
				return(TotalTime.config.totalTimeDataPath + "/" + FileOperations.TT_DATAFILE);
			}
			return "";
		}
		public static bool saveData (Configuration.dataLevel type)
		{
			Log.Info ("saveData dataLevel: " + type.ToString ());
			string path = getDataFile (type);
			Log.Info ("saveData: " + path);
			if (path == "")
				return false;
			
			ConfigNode root = new ConfigNode ();
			ConfigNode top = new ConfigNode (FileOperations.TT_NODENAME);
			root.SetNode (FileOperations.TT_NODENAME, top, true);

			switch (type) {
			case Configuration.dataLevel.game:
				top.SetValue ("secInGame", TotalTime.secInGame.ToString (), true);
				break;
			case Configuration.dataLevel.install:
				top.SetValue ("secInInstall", TotalTime.secInInstall.ToString (), true);
				break;
			case Configuration.dataLevel.global:
				top.SetValue ("secTotal", TotalTime.secTotal.ToString (), true);
				break;
			}


			root.Save (path);
			return false;
		}
示例#3
0
        void setGuiVars(ref Configuration config)
        {
            strtotalTimeDataPath = config.totalTimeDataPath;
            strinterval = config.interval.ToString();
            boollogGameTime = config.logGameTime;
            boollogInstallTime = config.logInstallTime;
            boollogGlobalTime = config.logGlobalTime;

            booldisplayGameTime = config.displayGameTime;
            booldisplayInstallTime = config.displayInstallTime;
            booldisplayGlobalTime = config.displayGlobalTime;
            booldisplayOnScreen = config.displayOnScreen;
            booldisplayInWindow = config.displayInWindow;
            booldisplaySessionTime = config.displaySessionTime;
            boolincludePauseTime = config.includePauseTime;
            boolenableEscapePause = config.enableEscapePause;
        }
		public static  bool getData (Configuration.dataLevel type)
		{
			Log.Info ("getData dataLevel: " + type.ToString ());
			string path = getDataFile (type);
			Log.Info ("getData path: " + path);
			if (path == "" || !System.IO.File.Exists (path)) {
				switch (type) {
				case Configuration.dataLevel.game:
					TotalTime.secInGame = 0;
					break;

				case Configuration.dataLevel.install:
					TotalTime.secInInstall = 0;
					break;

				case Configuration.dataLevel.global:
					TotalTime.secTotal = 0;
					break;
				}
				Log.Info ("path/file not found");
				return false;
			}

			ConfigNode root = new ConfigNode ();
			root = ConfigNode.Load (path);
			ConfigNode top = root.GetNode (FileOperations.TT_NODENAME);
			if (top != null) {
				switch (type) {
				case Configuration.dataLevel.game:
					TotalTime.secInGame = int.Parse (SafeLoad (top.GetValue ("secInGame"), TotalTime.secInGame.ToString ()));
					Log.Info ("getData: dataLevel.game: " + TotalTime.secInGame);
					TotalTime.strSecInGameTime = TotalTime.formatTime (TotalTime.secInGame);

					break;

				case Configuration.dataLevel.install:
					TotalTime.secInInstall = int.Parse (SafeLoad (top.GetValue ("secInInstall"), TotalTime.secInInstall.ToString ()));
					Log.Info ("getData: dataLevel.install: " + TotalTime.secInInstall);
					TotalTime.strSecInInstallTime = TotalTime.formatTime (TotalTime.secInInstall);
					break;

				case Configuration.dataLevel.global:
					TotalTime.secTotal = int.Parse (SafeLoad (top.GetValue ("secTotal"), TotalTime.secTotal.ToString ()));
					Log.Info ("getData: dataLevel.global: " + TotalTime.secTotal);
					TotalTime.strSecTotalTime = TotalTime.formatTime (TotalTime.secTotal);
					break;
				}
			}
			return false;
		}
示例#5
0
        private void ConfigWindow(int id)
        {
            if (cfgWinData == false)
            {
                cfgWinData = true;

                setGuiVars(ref TotalTime.config);

            }

            //SetConfigVisible (true);
            GUI.enabled = true;

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.EndHorizontal();

            //GUILayout.BeginArea (new Rect (10, 50, 375, 500));

            GUILayout.BeginHorizontal();
            GUILayout.Label("Save total time for individual saves:");
            GUILayout.FlexibleSpace();
            boollogGameTime = GUILayout.Toggle(boollogGameTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Save total time for this KSP install:");
            GUILayout.FlexibleSpace();
            boollogInstallTime = GUILayout.Toggle(boollogInstallTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Save total time for all KSP games in external file:");
            GUILayout.FlexibleSpace();
            boollogGlobalTime = GUILayout.Toggle(boollogGlobalTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Directory for global count file:");
            GUILayout.FlexibleSpace();
            strtotalTimeDataPath = GUILayout.TextField(strtotalTimeDataPath, GUILayout.MinWidth(30F), GUILayout.MaxWidth(300F));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Update interval:");
            GUILayout.FlexibleSpace();
            strinterval = GUILayout.TextField(strinterval, GUILayout.MinWidth(30F), GUILayout.MaxWidth(30F));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Include time while paused:");
            GUILayout.FlexibleSpace();
            boolincludePauseTime = GUILayout.Toggle(boolincludePauseTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Enable Escape key in the Editors and SpaceCenter scenes:");
            GUILayout.FlexibleSpace();
            boolenableEscapePause = GUILayout.Toggle(boolenableEscapePause, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Display on screen:");
            GUILayout.FlexibleSpace();
            booldisplayOnScreen = GUILayout.Toggle(booldisplayOnScreen, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Display in window:");
            GUILayout.FlexibleSpace();
            booldisplayInWindow = GUILayout.Toggle(booldisplayInWindow, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Display game time:");
            GUILayout.FlexibleSpace();
            booldisplayGameTime = GUILayout.Toggle(booldisplayGameTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Display install time:");
            GUILayout.FlexibleSpace();
            booldisplayInstallTime = GUILayout.Toggle(booldisplayInstallTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Display total time:");
            GUILayout.FlexibleSpace();
            booldisplayGlobalTime = GUILayout.Toggle(booldisplayGlobalTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Display session time:");
            GUILayout.FlexibleSpace();
            booldisplaySessionTime = GUILayout.Toggle(booldisplaySessionTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Defaults", GUILayout.Width(125.0f)))
            {
                Configuration c = new Configuration();
                //TotalTime.config.setDefaults ();
                //cfgWinData = false;
                setGuiVars(ref c);
                return;
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Save", GUILayout.Width(125.0f)))
            {
                //writeConfig (newconfig);
                //	bool hasWriteAccess = true;
            #if false
                string tmpFileName = strtotalTimeDataPath + "/tmp.tmp";
                FileInfo testfileInfo = new FileInfo (tmpFileName);

                Log.Info ("testing write access to: " + tmpFileName);

                try {
                    Log.Info("testfileInfo.Directory.Create");
                    testfileInfo.Directory.Create();
                } catch (Exception SystemSecurityException) {
                    //hasWriteAccess = false;
                    Log.Info("SystemSecurityException");
                    Log.Info(SystemSecurityException.ToString());
                    TotalTime.config.totalTimeDataPath = "";
                    boollogGlobalTime = false;
                }

                if (File.Exists (tmpFileName)) {
                    testfileInfo.Delete ();
                    TotalTime.config.totalTimeDataPath = strtotalTimeDataPath;
                } else {
                    TotalTime.config.totalTimeDataPath = "";
                    boollogGlobalTime = false;
                }
            #else
                TotalTime.config.totalTimeDataPath = strtotalTimeDataPath;
            #endif
                if (TotalTime.config.totalTimeDataPath == "")
                    booldisplayGlobalTime = false;
                TotalTime.config.logGameTime = boollogGameTime;
                if (TotalTime.config.logInstallTime == false && boollogInstallTime)
                {
                    FileOperations.getData(Configuration.dataLevel.install);
                }
                TotalTime.config.logInstallTime = boollogInstallTime;
                if (TotalTime.config.logGlobalTime == false && boollogGameTime)
                {
                    FileOperations.getData(Configuration.dataLevel.global);
                }
                TotalTime.config.logGlobalTime = boollogGlobalTime;

                TotalTime.config.displayGameTime = booldisplayGameTime;
                TotalTime.config.displayInstallTime = booldisplayInstallTime;
                TotalTime.config.displayGlobalTime = booldisplayGlobalTime;
                TotalTime.config.displayOnScreen = booldisplayOnScreen;

                TotalTime.config.displayInWindow = booldisplayInWindow;

                TotalTime.config.displaySessionTime = booldisplaySessionTime;
                TotalTime.config.includePauseTime = boolincludePauseTime;
                TotalTime.config.enableEscapePause = boolenableEscapePause;

                try
                {
                    TotalTime.config.interval = Convert.ToUInt16(strinterval);
                }
                catch (Exception)
                {
                }
                GUIToggleConfig();
                TotalTime.config.SaveConfiguration();

            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Cancel", GUILayout.Width(125.0f)))
            {
                GUIToggleConfig();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("");
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Set global file counter file in home directory", GUILayout.Width(300.0f)))
            {
                strtotalTimeDataPath = FileOperations.GetHomeDir();
                strtotalTimeDataPath = strtotalTimeDataPath.Replace("\\", "/");

                int i = TotalTime.secTotal;
                FileOperations.getData(Configuration.dataLevel.global);
                TotalTime.secTotal += i;

            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Reset Save counter", GUILayout.Width(150.0f)))
            {
                TotalTime.secInGame = 0;
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Reset Install counter", GUILayout.Width(150.0f)))
            {
                TotalTime.secInInstall = 0;
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Reset Global counter", GUILayout.Width(150.0f)))
            {
                TotalTime.secTotal = 0;
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUI.DragWindow();
        }