Ejemplo n.º 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 FoundersCloudCoin loadOneCloudCoinFromJsonFile(String loadFilePath)
    {
        FoundersCloudCoin returnCC = new FoundersCloudCoin();

        //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 <FoundersCloudCoin>(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
Ejemplo n.º 2
0
        public static void export()
        {
            Console.Out.WriteLine("");
            Banker bank = new Banker(FS);

            int[] bankTotals    = bank.countCoins(FS.BankFolder);
            int[] frackedTotals = bank.countCoins(FS.FrackedFolder);
            Console.Out.WriteLine("  Your Bank Inventory:");
            //int grandTotal = (bankTotals[0] + frackedTotals[0]);
            showCoins();
            // state how many 1, 5, 25, 100 and 250
            int exp_1   = 0;
            int exp_5   = 0;
            int exp_25  = 0;
            int exp_100 = 0;
            int exp_250 = 0;

            //Warn if too many coins
            Console.WriteLine(bankTotals[1] + frackedTotals[1] + bankTotals[2] + frackedTotals[2] + bankTotals[3] + frackedTotals[3] + bankTotals[4] + frackedTotals[4] + bankTotals[5] + frackedTotals[5]);
            if (((bankTotals[1] + frackedTotals[1]) + (bankTotals[2] + frackedTotals[2]) + (bankTotals[3] + frackedTotals[3]) + (bankTotals[4] + frackedTotals[4]) + (bankTotals[5] + frackedTotals[5])) > 1000)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Out.WriteLine("Warning: You have more than 1000 Notes in your bank. Stack files should not have more than 1000 Notes in them.");
                Console.Out.WriteLine("Do not export stack files with more than 1000 notes. .");
                Console.ForegroundColor = ConsoleColor.White;
            }//end if they have more than 1000 coins

            Console.Out.WriteLine("  Do you want to export your CloudCoin to (1)jpgs , (2) stack (JSON) , (3) QR Code (4) 2D Bar code file?");
            int file_type = reader.readInt(1, 4);

            // 1 jpg 2 stack
            if (onesTotalCount > 0)
            {
                Console.Out.WriteLine("  How many 1s do you want to export?");
                exp_1 = reader.readInt(0, (onesTotalCount));
            }

            // if 1s not zero
            if (fivesTotalCount > 0)
            {
                Console.Out.WriteLine("  How many 5s do you want to export?");
                exp_5 = reader.readInt(0, (fivesTotalCount));
            }

            // if 1s not zero
            if ((qtrTotalCount > 0))
            {
                Console.Out.WriteLine("  How many 25s do you want to export?");
                exp_25 = reader.readInt(0, (qtrTotalCount));
            }

            // if 1s not zero
            if (hundredsTotalCount > 0)
            {
                Console.Out.WriteLine("  How many 100s do you want to export?");
                exp_100 = reader.readInt(0, (hundredsTotalCount));
            }

            // if 1s not zero
            if (twoFiftiesTotalCount > 0)
            {
                Console.Out.WriteLine("  How many 250s do you want to export?");
                exp_250 = reader.readInt(0, (twoFiftiesTotalCount));
            }

            // if 1s not zero
            // move to export
            Exporter exporter = new Exporter(FS);

            if (file_type == 1)
            {
                Console.Out.WriteLine("  Tag your jpegs with 'random' to give them a random number.");
            }
            Console.Out.WriteLine("  What tag will you add to the file name?");
            String tag = reader.readString();

            //Console.Out.WriteLine(("Exporting to:" + exportFolder));
            if (file_type == 1)
            {
                exporter.writeJPEGFiles(exp_1, exp_5, exp_25, exp_100, exp_250, tag);
                // stringToFile( json, "test.txt");
            }
            else if (file_type == 2)
            {
                exporter.writeJSONFile(exp_1, exp_5, exp_25, exp_100, exp_250, tag);
            }
            else if (file_type == 3)
            {
                exporter.writeQRCodeFiles(exp_1, exp_5, exp_25, exp_100, exp_250, tag);
                // stringToFile( json, "test.txt");
            }
            else if (file_type == 4)
            {
                exporter.writeBarCode417CodeFiles(exp_1, exp_5, exp_25, exp_100, exp_250, tag);
                // stringToFile( json, "test.txt");
            }


            // end if type jpge or stack
            Console.Out.WriteLine("  Exporting CloudCoins Completed.");
        }// end export One