Exemple #1
0
        public override bool WriteCoinToJpeg(CloudCoin cloudCoin, string TemplateFile, string OutputFile, string tag)
        {
            OutputFile = OutputFile.Replace("\\\\", "\\");
            bool fileSavedSuccessfully = true;

            /* BUILD THE CLOUDCOIN STRING */
            String cloudCoinStr = "01C34A46494600010101006000601D05"; //THUMBNAIL HEADER BYTES

            for (int i = 0; (i < 25); i++)
            {
                cloudCoinStr = cloudCoinStr + cloudCoin.an[i];
            } // end for each an

            //cloudCoinStr += "204f42455920474f4420262044454645415420545952414e545320";// Hex for " OBEY GOD & DEFEAT TYRANTS "
            //cloudCoinStr += "20466f756e6465727320372d352d3137";// Founders 7-5-17
            cloudCoinStr += "4c6976652046726565204f7220446965"; // Live Free or Die
            cloudCoinStr += "00000000000000000000000000";       //Set to unknown so program does not export user data
                                                                // for (int i =0; i < 25; i++) {
                                                                //     switch () { }//end switch pown char
                                                                // }//end for each pown
            cloudCoinStr += "00";                               // HC: Has comments. 00 = No
            cloudCoin.CalcExpirationDate();
            cloudCoinStr += cloudCoin.edHex;                    // 01;//Expiration date Sep 2016 (one month after zero month)
            cloudCoinStr += "01";                               //  cc.nn;//network number
            String hexSN     = cloudCoin.sn.ToString("X6");
            String fullHexSN = "";

            switch (hexSN.Length)
            {
            case 1: fullHexSN = ("00000" + hexSN); break;

            case 2: fullHexSN = ("0000" + hexSN); break;

            case 3: fullHexSN = ("000" + hexSN); break;

            case 4: fullHexSN = ("00" + hexSN); break;

            case 5: fullHexSN = ("0" + hexSN); break;

            case 6: fullHexSN = hexSN; break;
            }
            cloudCoinStr = (cloudCoinStr + fullHexSN);
            /* BYTES THAT WILL GO FROM 04 to 454 (Inclusive)*/
            byte[] ccArray = this.hexStringToByteArray(cloudCoinStr);


            /* READ JPEG TEMPLATE*/
            byte[] jpegBytes = null;
            switch (cloudCoin.getDenomination())
            {
            case 1: jpegBytes = readAllBytes(this.TemplateFolder + "jpeg1.jpg"); break;

            case 5: jpegBytes = readAllBytes(this.TemplateFolder + "jpeg5.jpg"); break;

            case 25: jpegBytes = readAllBytes(this.TemplateFolder + "jpeg25.jpg"); break;

            case 100: jpegBytes = readAllBytes(this.TemplateFolder + "jpeg100.jpg"); break;

            case 250: jpegBytes = readAllBytes(this.TemplateFolder + "jpeg250.jpg"); break;
            }// end switch


            /* WRITE THE SERIAL NUMBER ON THE JPEG */

            //Bitmap bitmapimage;
            SKBitmap bitmapimage;
            //using (var ms = new MemoryStream(jpegBytes))
            {
                //bitmapimage = new Bitmap(ms);
                bitmapimage = SKBitmap.Decode(jpegBytes);
            }
            SKCanvas canvas = new SKCanvas(bitmapimage);
            //Graphics graphics = Graphics.FromImage(bitmapimage);
            //graphics.SmoothingMode = SmoothingMode.AntiAlias;
            //graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            SKPaint textPaint = new SKPaint()
            {
                IsAntialias = true,
                Color       = SKColors.White,
                TextSize    = 14,
                Typeface    = SKTypeface.FromFamilyName("Arial")
            };

            //PointF drawPointAddress = new PointF(30.0F, 25.0F);

            canvas.DrawText(String.Format("{0:N0}", cloudCoin.sn) + " of 16,777,216 on Network: 1", 30, 40, textPaint);
            //graphics.DrawString(String.Format("{0:N0}", cc.sn) + " of 16,777,216 on Network: 1", new Font("Arial", 10), Brushes.White, drawPointAddress);

            //ImageConverter converter = new ImageConverter();
            //byte[] snBytes = (byte[])converter.ConvertTo(bitmapimage, typeof(byte[]));
            SKImage image = SKImage.FromBitmap(bitmapimage);
            SKData  data  = image.Encode(SKEncodedImageFormat.Jpeg, 100);

            byte[] snBytes = data.ToArray();

            List <byte> b1 = new List <byte>(snBytes);
            List <byte> b2 = new List <byte>(ccArray);

            b1.InsertRange(4, b2);

            if (tag == "random")
            {
                Random r    = new Random();
                int    rInt = r.Next(100000, 1000000); //for ints
                tag = rInt.ToString();
            }

            string fileName = ExportFolder + cloudCoin.FileName + tag + ".jpg";

            File.WriteAllBytes(fileName, b1.ToArray());
            Console.Out.WriteLine("Writing to " + fileName);
            //CoreLogger.Log("Writing to " + fileName);
            return(fileSavedSuccessfully);
        }
Exemple #2
0
    }    //end write json to file

    public bool writeJSONFile(int m1, int m5, int m25, int m100, int m250, string tag, int mode = 0, string backupDir = "")
    {
        bool jsonExported = true;
        int  totalSaved   = m1 + (m5 * 5) + (m25 * 25) + (m100 * 100) + (m250 * 250);
        // Track the total coins
        int coinCount = m1 + m5 + m25 + m100 + m250;

        String[] coinsToDelete    = new String[coinCount];
        String[] bankedFileNames  = new DirectoryInfo(this.fileSystem.BankFolder).GetFiles().Select(o => o.Name).ToArray();   //Get all names in bank folder
        String[] frackedFileNames = new DirectoryInfo(this.fileSystem.FrackedFolder).GetFiles().Select(o => o.Name).ToArray();;
        String[] partialFileNames = new DirectoryInfo(this.fileSystem.PartialFolder).GetFiles().Select(o => o.Name).ToArray();
        // Add the two arrays together
        var list = new List <String>();

        list.AddRange(bankedFileNames);
        list.AddRange(frackedFileNames);
        list.AddRange(partialFileNames);

        // Program will spend fracked files like perfect files
        bankedFileNames = list.ToArray();


        // Check to see the denomination by looking at the file start
        int c = 0;
        // c= counter
        String json = "{" + Environment.NewLine;

        json = json + "\t\"cloudcoin\": " + Environment.NewLine;
        json = json + "\t[" + Environment.NewLine;
        String bankFileName;
        String frackedFileName;
        String partialFileName;
        string denomination;

        // Put all the JSON together and add header and footer
        for (int i = 0; (i < bankedFileNames.Length); i++)
        {
            denomination    = bankedFileNames[i].Split('.')[0];
            bankFileName    = this.fileSystem.BankFolder + bankedFileNames[i];    //File name in bank folder
            frackedFileName = this.fileSystem.FrackedFolder + bankedFileNames[i]; //File name in fracked folder
            partialFileName = this.fileSystem.PartialFolder + bankedFileNames[i];
            if (denomination == "1" && m1 > 0)
            {
                if (c != 0)    //This is the json seperator between each coin. It is not needed on the first coin
                {
                    json += ",\n";
                }

                if (File.Exists(bankFileName))     // Is it a bank file
                {
                    CloudCoin coinNote = fileSystem.loadOneCloudCoinFromJsonFile(bankFileName);
                    coinNote.aoid    = null; //Clear all owner data
                    json             = json + fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = bankFileName;
                    c++;
                }
                else if (File.Exists(partialFileName))     // Is it a partial file
                {
                    CloudCoin coinNote = fileSystem.loadOneCloudCoinFromJsonFile(partialFileName);
                    coinNote.aoid    = null; //Clear all owner data
                    json             = json + fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = partialFileName;
                    c++;
                }
                else
                {
                    CloudCoin coinNote = this.fileSystem.loadOneCloudCoinFromJsonFile(frackedFileName);
                    coinNote.aoid    = null;
                    json             = json + this.fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = frackedFileName;
                    c++;
                }

                m1--;
                // Get the clean JSON of the coin
            }    // end if coin is a 1

            if (denomination == "5" && m5 > 0)
            {
                if ((c != 0))
                {
                    json += ",\n";
                }

                if (File.Exists(bankFileName))
                {
                    CloudCoin coinNote = this.fileSystem.loadOneCloudCoinFromJsonFile(bankFileName);
                    coinNote.aoid    = null; //Clear all owner data
                    json             = json + this.fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = bankFileName;
                    c++;
                }
                else if (File.Exists(partialFileName))     // Is it a partial file
                {
                    CloudCoin coinNote = fileSystem.loadOneCloudCoinFromJsonFile(partialFileName);
                    coinNote.aoid    = null; //Clear all owner data
                    json             = json + fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = partialFileName;
                    c++;
                }
                else
                {
                    CloudCoin coinNote = this.fileSystem.loadOneCloudCoinFromJsonFile(frackedFileName);
                    coinNote.aoid    = null;
                    json             = json + this.fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = frackedFileName;
                    c++;
                }

                m5--;
            }     // end if coin is a 5

            if (denomination == "25" && m25 > 0)
            {
                if ((c != 0))
                {
                    json += ",\n";
                }

                if (File.Exists(bankFileName))
                {
                    CloudCoin coinNote = this.fileSystem.loadOneCloudCoinFromJsonFile(bankFileName);
                    coinNote.aoid    = null; //Clear all owner data
                    json             = json + this.fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = bankFileName;
                    c++;
                }
                else if (File.Exists(partialFileName))     // Is it a partial file
                {
                    CloudCoin coinNote = fileSystem.loadOneCloudCoinFromJsonFile(partialFileName);
                    coinNote.aoid    = null; //Clear all owner data
                    json             = json + fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = partialFileName;
                    c++;
                }
                else
                {
                    CloudCoin coinNote = this.fileSystem.loadOneCloudCoinFromJsonFile(frackedFileName);
                    coinNote.aoid    = null;
                    json             = json + this.fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = frackedFileName;
                    c++;
                }

                m25--;
            }    // end if coin is a 25

            if (denomination == "100" && m100 > 0)
            {
                if ((c != 0))
                {
                    json += ",\n";
                }

                if (File.Exists(bankFileName))
                {
                    CloudCoin coinNote = this.fileSystem.loadOneCloudCoinFromJsonFile(bankFileName);
                    coinNote.aoid    = null; //Clear all owner data
                    json             = json + this.fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = bankFileName;
                    c++;
                }
                else if (File.Exists(partialFileName))     // Is it a partial file
                {
                    CloudCoin coinNote = fileSystem.loadOneCloudCoinFromJsonFile(partialFileName);
                    coinNote.aoid    = null; //Clear all owner data
                    json             = json + fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = partialFileName;
                    c++;
                }
                else
                {
                    CloudCoin coinNote = this.fileSystem.loadOneCloudCoinFromJsonFile(frackedFileName);
                    coinNote.aoid    = null;
                    json             = json + this.fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = frackedFileName;
                    c++;
                }

                m100--;
            }     // end if coin is a 100

            if (denomination == "250" && m250 > 0)
            {
                if ((c != 0))
                {
                    json += ",\n";
                }

                if (File.Exists(bankFileName))
                {
                    CloudCoin coinNote = this.fileSystem.loadOneCloudCoinFromJsonFile(bankFileName);
                    coinNote.aoid    = null; //Clear all owner data
                    json             = json + this.fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = bankFileName;
                    c++;
                }
                else if (File.Exists(partialFileName))     // Is it a partial file
                {
                    CloudCoin coinNote = fileSystem.loadOneCloudCoinFromJsonFile(partialFileName);
                    coinNote.aoid    = null; //Clear all owner data
                    json             = json + fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = partialFileName;
                    c++;
                }
                else
                {
                    CloudCoin coinNote = this.fileSystem.loadOneCloudCoinFromJsonFile(frackedFileName);
                    coinNote.aoid    = null;
                    json             = json + this.fileSystem.setJSON(coinNote);
                    coinsToDelete[c] = frackedFileName;
                    c++;
                }

                m250--;
            }    // end if coin is a 250

            if (m1 == 0 && m5 == 0 && m25 == 0 && m100 == 0 && m250 == 0)
            {
                break;
            }     // Break if all the coins have been called for.
            string status           = String.Format("exported %d of %d coin.", i, bankedFileNames.Length);
            int    percentCompleted = (i + 1) * 100 / bankedFileNames.Length;
        }    // end for each coin needed

        /*WRITE JSON TO FILE*/
        json  = json + "\t] " + Environment.NewLine;
        json += "}";
        String filename = (this.fileSystem.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + ".stack");

        if (mode == 1)
        {
            filename = (backupDir + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + ".stack");
        }
        if (File.Exists(filename))
        {
            // tack on a random number if a file already exists with the same tag
            Random rnd     = new Random();
            int    tagrand = rnd.Next(999);
            filename = (this.fileSystem.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + tagrand + ".stack");
        }    //end if file exists

        File.WriteAllText(filename, json);
        Console.Out.WriteLine("Writing to : ");
        //CoreLogger.Log("Writing to : " + filename);
        Console.Out.WriteLine(filename);
        /*DELETE FILES THAT HAVE BEEN EXPORTED*/
        if (mode == 0)
        {
            for (int cc = 0; cc < coinsToDelete.Length; cc++)
            {
                // Console.Out.WriteLine("Deleting " + coinsToDelete[cc]);
                if (coinsToDelete[cc] != null)
                {
                    File.Delete(coinsToDelete[cc]);
                }
            }    //end for all coins to delete
        }
        // end if write was good
        return(jsonExported);
    }    //end write json to file
 public override bool WriteCoinToQRCode(CloudCoin cloudCoin, string OutputFile, string tag)
 {
     throw new NotImplementedException();
 }
Exemple #4
0
 public void SetProgress(CloudCoin coin)
 {
     lblTitle.Text = coin.sn + "  " + GetDenominations(coin.denomination)
                     + "\t" + coin.StatusText;
     //lblProgress.Text = progress.ToString();
 }
 public Stack(CloudCoin coin)
 {
     cc    = new CloudCoin[1];
     cc[0] = coin;
 }
Exemple #6
0
    // end get JSON

    /* Writes a JPEG To the Export Folder */
    public bool writeJpeg(CloudCoin cc, string tag)
    {
        return(true);
    }    //end write JPEG
Exemple #7
0
 public override bool WriteCoinToBARCode(CloudCoin cloudCoin, string OutputFile, string tag)
 {
     return(true);
 }
Exemple #8
0
 public override bool WriteCoinToJpeg(CloudCoin cloudCoin, string TemplateFile, string OutputFile, string tag)
 {
     return(true);
 }