Пример #1
0
        }  // End constructor

        /* PUBLIC METHODS */

        // This loads a JSON file (.stack) from the hard drive that contains only one CloudCoin and turns it into an object.
        //   This uses Newton soft but causes a enrror System.IO.FileNotFoundException. Could not load file 'Newtonsoft.Json'
        public CloudCoin loadOneCloudCoinFromJsonFile(String loadFilePath)
        {
            CloudCoin returnCC = new CloudCoin();

            //Load file as JSON
            String incomeJson = this.importJSON(loadFilePath);
            //STRIP UNESSARY test
            int secondCurlyBracket     = ordinalIndexOf(incomeJson, "{", 2) - 1;
            int firstCloseCurlyBracket = ordinalIndexOf(incomeJson, "}", 0) - secondCurlyBracket;

            // incomeJson = incomeJson.Substring(secondCurlyBracket, firstCloseCurlyBracket);
            incomeJson = incomeJson.Substring(secondCurlyBracket, firstCloseCurlyBracket + 1);
            // Console.Out.WriteLine(incomeJson);
            //Deserial JSON

            try
            {
                returnCC = JsonConvert.DeserializeObject <CloudCoin>(incomeJson);
            }
            catch (JsonReaderException)
            {
                Console.WriteLine("There was an error reading files in your bank.");
                CoreLogger.Log("There was an error reading files in your bank.");
                Console.WriteLine("You may have the aoid memo bug that uses too many double quote marks.");
                Console.WriteLine("Your bank files are stored using and older version that did not use properly formed JSON.");
                Console.WriteLine("Would you like to upgrade these files to the newer standard?");
                Console.WriteLine("Your files will be edited.");
                Console.WriteLine("1 for yes, 2 for no.");
                KeyboardReader reader = new KeyboardReader();
                int            answer = reader.readInt(1, 2);
                if (answer == 1)
                {
                    //Get rid of ed and aoid
                    //Get file names in bank folder
                    String[] fileNames = new DirectoryInfo(bankFolder).GetFiles().Select(o => o.Name).ToArray();
                    for (int i = 0; i < fileNames.Length; i++)
                    {
                        Console.WriteLine("Fixing " + bankFolder + "\\" + fileNames[i]);
                        CoreLogger.Log("Fixing " + bankFolder + "\\" + fileNames[i]);
                        string text = File.ReadAllText(bankFolder + "\\" + fileNames[i]);
                        text = text.Replace("\"aoid\": [\"memo\"=\"\"]", "");
                        File.WriteAllText(bankFolder + "\\" + fileNames[i], text);
                    }//End for all files in bank
                    CoreLogger.Log("Done Fixing. The program will now exit. Please restart. Press any key.");
                    Console.WriteLine("Done Fixing. The program will now exit. Please restart. Press any key.");
                    Console.Read();
                    Environment.Exit(0);
                }
                else
                {
                    CoreLogger.Log("Leaving files as is. You maybe able to fix the manually by editing the files.");
                    Console.WriteLine("Leaving files as is. You maybe able to fix the manually by editing the files.");
                    Console.WriteLine("Done Fixing. The program will now exit. Please restart. Press any key.");
                    Console.Read();
                    Environment.Exit(0);
                }
            }

            return(returnCC);
        }//end load one CloudCoin from JSON