public void Create_New_Project(string name, string type = "no-type", string desc = "no-desc") { if (Can_Create_Project(name)) { TPMP_Project newProj = new TPMP_Project(); newProj.name = name; newProj.type = type; newProj.desc = desc; newProj.time_spent = new TimeSpan(0, 0, 0); Globals.listProjects.Add(newProj); Directory.CreateDirectory(Config.appDataPath + name); XmlWriter file = XmlWriter.Create(Config.appDataPath + name + "/info.xml"); file.WriteStartDocument(true); file.WriteStartElement("general"); file.WriteElementString("name", name); file.WriteElementString("type", type); file.WriteElementString("desc", desc); file.WriteElementString("total_time_spent", "0"); file.WriteEndElement(); file.WriteEndDocument(); file.Close(); file = XmlWriter.Create(Config.appDataPath + name + "/sessions.xml"); file.WriteStartElement("sessions"); file.WriteAttributeString("count", 0 + ""); file.WriteString(""); file.WriteEndDocument(); file.Close(); file = XmlWriter.Create(Config.appDataPath + name + "/log.xml"); file.WriteStartElement("log"); file.WriteStartElement("entry"); file.WriteAttributeString("time", DateTime.Now.ToString()); file.WriteString("Created project"); file.WriteEndElement(); file.WriteString(""); file.WriteEndDocument(); file.Close(); StreamWriter file2 = File.AppendText(Config.appDataPath + "projects"); file2.WriteLine(name); file2.Close(); TPMP_Prompt.Instance.Prompt_Text("Created new project called " + name + " of type " + type, true); } else { TPMP_Prompt.Instance.Prompt_Text("My apologies, sir, but there already exists project named " + name, true); } }
public void SetGlobalActive(TPMP_Project proj) { this.name = proj.name; this.type = proj.type; this.desc = proj.desc; this.time_spent = proj.time_spent; LoadLastSession(); LoadBasicStatistics(); }
public void LoadProjects() // TO-DO return bool value { List <string> projectList = new List <string>(); StreamReader file = new StreamReader(Config.appDataPath + "projects"); while (!file.EndOfStream) { projectList.Add(file.ReadLine()); } file.Close(); foreach (string value in projectList) { TPMP_Project tmp = new TPMP_Project(); if (tmp.Load(value)) { Globals.listProjects.Add(tmp); } else { MessageBox.Show("There was a problem loading " + value + " project."); } } }