Beispiel #1
0
        private static async Task Calibrate(DataSetInfo info)
        {
            using var app     = MaxImDlApp.Acquire() ?? throw new InvalidOperationException("Failed to create app.");
            using var doc     = app.CreateDocument();
            app.CalMedianBias = true;
            app.CalMedianDark = true;

            app.CalClear();

            foreach (var item in info.Bias)
            {
                app.CalAddBias(item.FullName);
            }
            foreach (var item in info.Dark)
            {
                app.CalAddDark(item.FullName);
            }

            app.CalSet();

            using var progressBar = new ShellProgressBar.ProgressBar(
                      info.Files.Count,
                      "Calibrating files...",
                      new ShellProgressBar.ProgressBarOptions()
            {
                DisplayTimeInRealTime = true,
                EnableTaskBarProgress = true
            }
                      );
            foreach (var item in info.EnumeratePaths())
            {
                var task = Task.Run(() =>
                {
                    // ReSharper disable AccessToDisposedClosure
                    doc.OpenFile(item.Source);
                    doc.Calibrate();
                    if (info.Bin != BinType.NoBin)
                    {
                        doc.Bin(info.Bin);
                    }
                    // ReSharper restore AccessToDisposedClosure
                });
                var targetDir = Path.GetDirectoryName(item.Target);
                if (!Directory.Exists(targetDir))
                {
                    Directory.CreateDirectory(targetDir);
                }

                var   fileName = Path.GetFileNameWithoutExtension(item.Source);
                await task;
                doc.SaveFile(item.Target);
                progressBar.Tick(fileName);
            }
        }
Beispiel #2
0
        public IEnumerable <uint> Sort(string fileName)
        {
            _fileSplitter.SplitUIntsIntoBinaryFiles(File.OpenText(fileName));

            using (var pbar = new ShellProgressBar.ProgressBar(_fileSplitter.NumberOfChunks, "Generating chunks", ConsoleColor.Cyan))
                for (int i = 0; i < _fileSplitter.NumberOfChunks; i++)
                {
                    pbar.Tick("Sorting chunk " + i);
                    using (Stream stream = _fileSystem.OpenFileForWriting(i))
                    {
                        _binaryStreamSorter.SortBinaryFileInMemory(stream);
                    }
                }
            return(_filePartMerger.MergeSortParts(_fileSplitter.NumberOfChunks));
        }
    private static async Task PublishModAsync(PublishModOptions options)
    {
        using var progressBar = new ShellProgressBar.ProgressBar(10000, "Building Release");
        var configPath = Path.Combine(options.ModFolder, ModConfig.ConfigFileName);
        var config     = await IConfig <ModConfig> .FromPathAsync(configPath);

        await Mod.Loader.Update.Packaging.Publisher.PublishAsync(new Mod.Loader.Update.Packaging.Publisher.PublishArgs()
        {
            ModTuple            = new PathTuple <ModConfig>(configPath, config),
            OutputFolder        = options.OutputFolder,
            IncludeRegexes      = options.IncludeRegexes.ToList(),
            IgnoreRegexes       = options.IgnoreRegexes.ToList(),
            OlderVersionFolders = options.OlderVersionFolders.ToList(),
            AutomaticDelta      = options.AutomaticDelta,
            CompressionLevel    = options.CompressionLevel,
            CompressionMethod   = options.CompressionMethod,
            Progress            = progressBar.AsProgress <double>(),
            PackageName         = options.PackageName,
            PublishTarget       = options.PublishTarget,
            ChangelogPath       = options.ChangelogPath,
            ReadmePath          = options.ReadmePath,
            MetadataFileName    = config.ReleaseMetadataFileName
        });
    }
Beispiel #4
0
        private SimulationState[] GetMarketMaximum(Dictionary <DateTime, bool> buyDates, ShellProgressBar.ProgressBar progressBar)
        {
            var history = Array.Empty <SimulationState>();
            var worth   = GetMarketAverageWorth().Last();

            foreach (var(date, _) in buyDates.Reverse())
            {
                buyDates[date] = false;
                var newHistory = SimulateBuyDates(buyDates);
                var newWorth   = newHistory?.LastOrDefault()?.Worth ?? 0m;

                if (newWorth < worth)
                {
                    buyDates[date] = true;
                }
                else
                {
                    worth   = newWorth;
                    history = newHistory;
                }
                progressBar?.Tick($"Initialising...");
            }

            return(history);
        }
Beispiel #5
0
 public void Start(string message, int ticks)
 {
     _progressBar = new ShellProgressBar.ProgressBar(ticks, message, ConsoleColor.Cyan);
 }
Beispiel #6
0
        //decodes an steg image
        static public void Decode(string InputImage, string outputTxt, bool encrypted = false)
        {
            //formating
            Console.WriteLine("\n\n");

            //decalare as null so we can check later for cleanup
            Bitmap     image  = null;
            FileStream output = null;

            ShellProgressBar.ProgressBar bar = null;
            string password = null;
            int    count    = 0;

            //get the password before we start to read the data
            if (encrypted)
            {
                //Some Console.WroteLine() for formating
                Console.WriteLine();
                Console.Write("Please enter the password: "******"\n");
            }

            try
            {
                //Open file streams and read all neccessary data like the image and get the progress bar
                output = new FileStream(outputTxt, FileMode.Create);

                bar = Progress.GetProgressBar(100, InputImage, outputTxt, "decode");

                bar.Tick("Reading Image...");

                image = new Bitmap(InputImage);

                bar.Tick("Decoding image");

                //update the MaxTicks after reading the image
                bar.MaxTicks = image.Height / 2;

                List <byte> buffer = new List <byte>();

                //loop through the image pixels
                for (int y = 0; y < image.Height; y++)
                {
                    bar.Tick(y);

                    for (int x = 0; x < image.Width; x++)
                    {
                        Color imagePixel = image.GetPixel(x, y);

                        for (int channel = 0; channel < 3; channel++)
                        {
                            LSB.bitCount++;

                            switch (channel)
                            {
                            case 0:
                                getLSB(imagePixel.R);
                                break;

                            case 1:
                                getLSB(imagePixel.G);
                                break;

                            case 2:
                                getLSB(imagePixel.B);
                                break;
                            }

                            //if we are done with the byte
                            if (AtEndOfByte())
                            {
                                LSB.byteCount++;
                                buffer.Add(currentByte);

                                //if the byte is all 0's aka null byte
                                if (LSB.currentByte == '\0')
                                {
                                    //if we are at the end of the image with a count of 5
                                    count++;
                                    if (count == 5)
                                    {
                                        //mark that we reached the end and fufull exit conditions for the loop
                                        LSB.atEnd = true;
                                        x         = image.Width - 1;
                                        y         = image.Height - 1;
                                        break;
                                    }
                                }
                                else
                                {
                                    //if the byte is not null we write it to the output
                                    count = 0;
                                    output.Write(buffer.ToArray(), 0, buffer.ToArray().Length);
                                    buffer.Clear();
                                }

                                //reset bit count and current byte
                                LSB.bitCount    = 0;
                                LSB.currentByte = 0;
                            }
                        }
                    }
                }

                //if we never find the end points of the encoded data
                if (LSB.atEnd == false)
                {
                    Exception ex = new Exception("The image does not seem to be encoded or the image was altered after encoding");
                    throw ex;
                }

                //if the data was encrypted then we need to decrypt the data inorder to revert to original form
                if (encrypted)
                {
                    output.Close();

                    bar.Tick("Decypting the file...");

                    outputTxt = Encypt.GetDecryptedFile(outputTxt, password);
                }

                bar.Tick("Got " + LSB.byteCount + " bytes from " + InputImage + " and extracted to " + outputTxt);
                bar.Tick(bar.MaxTicks);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while decoding image: " + ex.Message);
            }
            finally
            {
                //cleanup
                if (image != null)
                {
                    image.Dispose();
                }
                if (output != null)
                {
                    output.Dispose();
                }
                if (bar != null)
                {
                    bar.Dispose();
                }
            }
        }
Beispiel #7
0
        //encodes and image with the given txt file
        static public void Encode(string InputImage, string InputTxt, string OutputImage, bool encrypted = false)
        {
            //formating
            Console.WriteLine("\n\n\n");

            Bitmap     image = null;
            FileStream input = null;

            ShellProgressBar.ProgressBar bar = null;
            int count = 0;

            //if the file is to be encrypted we encrypt the file and get the new encrypted one before moving on
            if (encrypted)
            {
                //gets the new encrypted file
                InputTxt = Encypt.GetEncryptedFile(InputTxt);

                //formating
                Console.WriteLine();
                Console.WriteLine();
            }

            try
            {
                //gets the file that is to be places in the image
                input = new FileStream(InputTxt, FileMode.Open);

                //get the progress bar
                bar = Progress.GetProgressBar((int)input.Length, InputTxt, InputImage, "encode");

                //update the progress bar
                bar.Tick("Reading image...");

                //read the image
                image = new Bitmap(InputImage);

                //update progress bar
                bar.Tick("Encoding image..");

                //get the first byte from the file
                int temp = input.ReadByte();
                LSB.currentByte = (byte)temp;

                //check if the file is empty
                if (temp == -1)
                {
                    Exception ex = new Exception("The file seems to be empty");
                    throw ex;
                }

                //loop through the whole image
                for (int y = 0; y < image.Height; y++)
                {
                    //update progress bar with the byte count
                    //one of the parameters in creating the progress bar is the size of the file
                    //so the bar knows the complete size and can calculate percent based on current count
                    bar.Tick(LSB.byteCount);

                    for (int x = 0; x < image.Width; x++)
                    {
                        //current pixel
                        Color imagePixel = image.GetPixel(x, y);

                        byte red   = 0;
                        byte green = 0;
                        byte blue  = 0;

                        //loop through the color channels RGB
                        for (int i = 0; i < 3; i++)
                        {
                            //check which channel we are on and encode based on that
                            //calls the setLSB methos which encodes the pixel channel to match that of the byte from the file
                            switch (i)
                            {
                            case 0:
                                red = setLSB(imagePixel.R);
                                break;

                            case 1:
                                green = setLSB(imagePixel.G);
                                break;

                            case 2:
                                blue = setLSB(imagePixel.B);
                                break;
                            }

                            //update our bit count so we know when we completed a whole byte
                            LSB.bitCount++;

                            //if we have complete a whole byte we need to get the next byte from the file
                            if (AtEndOfByte())
                            {
                                //update byte count
                                LSB.byteCount++;

                                //read the byte
                                temp = input.ReadByte();

                                //set current byte
                                LSB.currentByte = (byte)temp;

                                //if there was nothing left in the file
                                if (temp == -1)
                                {
                                    //update count
                                    count++;

                                    //if we have put 6 null bytes at the end of the encoding
                                    //this means we have completly encoded the txt file within the image
                                    if (count == 6)
                                    {
                                        //break out and close the file and set the end bool to true as we have finished
                                        if (input != null)
                                        {
                                            input.Close();
                                        }
                                        LSB.atEnd = true;
                                        break;
                                    }

                                    //set current byte to a null byte so that we can encode it within the image
                                    //6 null bytes are placed in the image to signify the end of the encoded message
                                    //this is so when we decode we know that we have finshed reading the encoded data
                                    LSB.currentByte = (byte)'\0';
                                }

                                //reset bit count as we got a new byte
                                LSB.bitCount = 0;
                            }
                        }

                        //once we have finished encoding one pixel we replace the old one with the new encoded one
                        image.SetPixel(x, y, Color.FromArgb(red, green, blue));

                        //if we are dont encoding exit the loops
                        if (LSB.atEnd && LSB.bitCount == 8)
                        {
                            x = image.Width - 1;
                            y = image.Height - 1;
                        }
                    }
                }

                //if we have finished looping through the image but did not finish encoding that means the txt file was too large for this image
                if (LSB.bitCount != 8 || LSB.atEnd == false)
                {
                    Exception ex = new Exception("The file you are trying to hide is too big try with a larger image or smaller message");
                    throw ex;
                }

                try
                {
                    //save the new enocded image
                    bar.Tick("Saving Image...");
                    image.Save(OutputImage, System.Drawing.Imaging.ImageFormat.Png);
                    bar.Tick(bar.MaxTicks);
                }
                catch (Exception e)
                {
                    //if we get an error while saving the image
                    Exception ex = new Exception("The image failed to save make sure the file does not already exist");
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while encoding the image: " + ex.Message);
            }
            finally
            {
                //cleanup
                if (image != null)
                {
                    image.Dispose();
                }
                if (input != null)
                {
                    input.Dispose();
                }
                if (bar != null)
                {
                    bar.Dispose();
                }
            }
        }