Changeset - 2e8a10efff43
[Not reviewed]
default
0 1 0
Jason Maltzen (jmaltzen) - 9 years ago 2015-12-31 05:53:03
jason.maltzen@unsanctioned.net
Move the check for template directory before creating profile folder.
1 file changed with 6 insertions and 6 deletions:
0 comments (0 inline, 0 general)
PlayerProfile.cs
Show inline comments
...
 
@@ -69,108 +69,108 @@ namespace DesertPaintLab
 
            }
 
		}
 

 
        public string Directory
 
        {
 
            get {
 
                return this.directory;
 
            }
 
        }
 

 
        public ReactionSet Reactions
 
        {
 
            get {
 
                return this.reactions;
 
            }
 
        }
 

 
        public string ReagentFile
 
        {
 
            get {
 
                return this.reagentFile;
 
            }
 
        }
 

 
        public SortedDictionary<string, PaintRecipe> Recipes
 
        {
 
            get {
 
                return this.recipes;
 
            }
 
        }
 

 
        public int RecipeCount
 
        {
 
            get {
 
                int count = 0;
 
                foreach (PaintRecipe recipe in this.recipes.Values)
 
                {
 
                    if (recipe.IsValid)
 
                    {
 
                        ++count;
 
                    }
 
                }
 
                return count;
 
            }
 
        }
 
		
 
		public bool Initialize()
 
		{
 
			// Create new directory.
 
			System.IO.Directory.CreateDirectory(directory);
 
				
 
			// Copy template files into new directory.
 
			string templatePath = FileUtils.FindApplicationResourceDirectory("template");
 
			
 
            // Copy template files into new directory.
 
            string templatePath = FileUtils.FindApplicationResourceDirectory("template");
 
            
 
            if (!System.IO.Directory.Exists(templatePath))
 
            {
 
                LastError = "Failed to find profile template folder.";
 
                return false;
 
            }
 

 
			// Create new directory.
 
			System.IO.Directory.CreateDirectory(directory);
 
		    
 
			DirectoryInfo di = new DirectoryInfo(templatePath);
 
			FileInfo[] templateFiles = di.GetFiles();
 

 
			foreach (FileInfo file in templateFiles)
 
			{
 
                string destFile = System.IO.Path.Combine(directory, file.Name);
 
				System.IO.File.Copy(file.FullName, destFile, true);
 
                if (!File.Exists(destFile))
 
                {
 
                    LastError = "Failed to copy template file " + file.Name + ".";
 
                    return false;
 
                }					
 
			}
 
            return true;
 
		}
 
		
 
		public void ConvertFromPP(string ppFile, string dpFile)
 
		{
 
			string line;
 
			using (StreamReader reader = new StreamReader(ppFile))
 
			{
 
				using (StreamWriter writer = new StreamWriter(dpFile))
 
				{
 
					while ((line = reader.ReadLine()) != null) 
 
                	{
 
						string[] tokens = line.Split(null);
 
						if ((tokens.Length > 0) && (tokens[0] != "//"))
 
						{							
 
							// Write reaction.
 
							writer.Write(tokens[0] + " " + tokens[2] + " ");
 
							switch (tokens[4])
 
							{
 
							case "W":
 
								writer.WriteLine(tokens[6] + " " + tokens[6] + " " + tokens[6]);
 
								break;
 
							case "R":
 
								writer.WriteLine(tokens[6] + " 0 0");
 
								break;
 
							case "G":
 
								writer.WriteLine("0 " + tokens[6] + " 0");
 
								break;
 
							case "B":
 
								writer.WriteLine("0 0 " + tokens[6]);
 
								break;	
 
							}
 
							
 
							// Write reverse reaction.
 
							writer.Write(tokens[2] + " " + tokens[0] + " ");
0 comments (0 inline, 0 general)