コード例 #1
0
ファイル: Form1.cs プロジェクト: H3ll3m4/blockget-win-gui
 //public Form1(Queue myQ, Filesys filesys)
 public Form1()
 {
     InitializeComponent();
     //string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
     openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
     notifyIconInit();
     //notifyIcon1.ContextMenuStrip = contextMenuStrip1;
     //displayQ = myQ;
     //fs = new Filesys(this);
     fs = new Filesys();
     Globals.UserName = textBoxUserName.Text;
 }
コード例 #2
0
        //See Unit Test
        public static void testEncryptionString()
        {
            //Arrange
            string pathFile = "C:\\Blockget\\test.txt";

            EncryptFile(pathFile);

            //Act
            //We check decryption :
            string decrypted = DecryptFile(pathFile + ".aes");

            //Assert
            if (Filesys.compare2FilesByBlocks(pathFile, decrypted))
            {
                Console.WriteLine("The 2 files are the same");
            }
            else
            {
                Console.WriteLine("Oh oh the file hasn't been decrypted correctly.");
            }
        }
コード例 #3
0
ファイル: Watcher.cs プロジェクト: H3ll3m4/blockget-win-gui
 private static void OnCreated(object source, FileSystemEventArgs e)
 {
     Console.WriteLine($"File: {e.FullPath} {e.ChangeType}");
     Filesys.CreateEvent(e.FullPath);
 }
コード例 #4
0
 internal myWatcher(Filesys filesys)
 {
     fs      = filesys;
     watcher = new FileSystemWatcher();
     initWatcher();
 }
コード例 #5
0
        /// <summary>
        /// Recover the files from the list of string: filename and CIDs: download, merge and decrypt
        /// </summary>
        /// <param name="cidArray"></param>
        public async void RecoverFilesMergeDecrypt(List <string> cidArray)
        {
            //We connect
            var ipfs = new IpfsClient(ipfsServer);

            if (cidArray.Count >= 0)
            {
                // First need to get the right folder. For ease of test, the part of the file are downloaded
                // on a folder filename-extension, i.e. test.txt to blockget/test-txt
                string fileName    = Path.GetFileNameWithoutExtension(cidArray[0]);
                string extensionPt = Path.GetExtension(cidArray[0]);
                //string extension = extensionPt.Skip(1).ToArray();
                string extension = extensionPt.Remove(0, 1);
                //string inputFolder = Globals.BLOCKGET_FILE_FOLDER + fileName + "-" + extension + "\\";
                string   inputFolder        = Globals.OPERATION_FOLDER + fileName + "-" + extension + "\\";
                string[] SplittedFilesArray = new string[Globals.SPLIT_NB];
                string   baseFileName       = Path.GetFileNameWithoutExtension(cidArray[0]);
                int      i = 0;
                //Create input forlder for download and merge
                Directory.CreateDirectory(inputFolder);
                foreach (string s in cidArray.Skip(1)) // We want to skip the first (contre intuitive, not 0)
                {
                    try
                    {
                        //SplittedFilesArray[i] = inputFolder + baseFileName + "." +
                        //        i.ToString().PadLeft(5, Convert.ToChar("0")) + extensionPt + ".tmp";
                        SplittedFilesArray[i] = inputFolder + baseFileName + extensionPt + ".aes." +
                                                i.ToString().PadLeft(5, Convert.ToChar("0")) + ".tmp";
                        //We download bytes => File
                        Stream result = await ipfs.FileSystem.ReadFileAsync(s);

                        //We want to save them in the SaveFolder + cidArray folder
                        //Could also try: Stream result = await ipfs.FileSystem.ReadFileAsync(s).Result;
                        using (FileStream DestinationStream = File.Create(SplittedFilesArray[i])) //TODO ERROR: System.IO.DirectoryNotFoundException: 'Could not find a part of the path 'C:\Blockget\ifmalesuperfherodresedlikewomen-jpg\ifmalesuperfherodresedlikewomen.jpg.aes.00000.tmp'.'
                        {
                            await result.CopyToAsync(DestinationStream);
                        }
                        i++;
                    } //System.Net.Http.HttpRequestException: 'invalid path "": path does not begin with '/''
                    catch (HttpRequestException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("FAIL! Don't forget to run IPFS on your computer");
                        break;
                    }
                }
                // We merge
                string pathEncryptedFile = Split.MergeFile(inputFolder);
                //We decrypt
                //string pathEncryptedFile = inputFolder + fileName + ".aes"; //Globals.BLOCKGET_FILE_FOLDER + "\\" + cidArray[0];
                //string pathEncryptedFile = inputFolder + baseFileName + extensionPt + ".aes";
                string outputPath = Encryption.DecryptFile(pathEncryptedFile);
                // Test if the file downloaded is the same as the one already present
                if (File.Exists(cidArray[0]) && Filesys.compare2FilesByBlocks(outputPath, cidArray[0]))
                {
                    Console.WriteLine("{0} and {1} have been compared bit by bit and are the same", outputPath, cidArray[0]);
                }
                else
                {
                    Console.WriteLine("{0} and {1} have been compared bit by bit and are different, we download and store the file in the Blockget Folder", outputPath, cidArray[0]);
                    // Could use the Path.Combine method to safely append the file name to the path.
                    // Will overwrite if the destination file already exists.
                    File.Copy(outputPath, cidArray[0], true);
                }
                //We delete folder and file downloaded
                File.Delete(outputPath);
                Directory.Delete(inputFolder);
            }
            else
            {
                Console.WriteLine("Problem this entry is empty");
            }
        }
コード例 #6
0
        public IpfsBlkchn(Filesys filesys)
        //public IpfsBlkchn(Filesys filesys, Form1 f)
        {
//            form = f;
            fs = filesys;
        }