public static void Main(string[] args)
    {
        if (args.Length == 0)
        {
            Console.WriteLine("Usage:");
            Console.WriteLine("    COMMAND run-tests");
            Console.WriteLine("    COMMAND hash-file <path>");
            return;
        }

        var sub     = args[0];
        var subArgs = new string[args.Length - 1];

        Array.Copy(args, 1, subArgs, 0, subArgs.Length);

        if (sub == "run-tests")
        {
            RunTests.SubMain(subArgs);
        }
        else if (sub == "hash-file")
        {
            HashFile.SubMain(subArgs);
        }
        else
        {
            Console.Error.WriteLine("Unknown sub-command: \"{0}\".", sub);
            Environment.Exit(1); return;
        }
    }
Ejemplo n.º 2
0
        public void CreateFileSha512Hash()
        {
            var file         = Path.Combine(testDirectory, "Aquatic Flowers.jpg");
            var readAllBytes = File.ReadAllBytes(file);
            var hashFile     = new HashFile();
            var sha256Hash   = hashFile.GenerateHash(readAllBytes, HashType.SHA512);

            Assert.That(sha256Hash, Is.EqualTo("7B9B401EFD2575EB1734F39CB93B74273632378B05E37B3C8DC9EE0F75BE901B0BE1EE63EA04476A72163F76B04A18C3136C30D4538D0AA38FCEAA780E3CCB43"));
        }
Ejemplo n.º 3
0
        public void CompressAndWritePassWordHash(string dirPath)
        {
            ICompress zip = CreateZipper(dirPath);

            zip.ZipDirectories();
            HashFile = Factory.CreateHashFile(dirPath);
            HashFile.TransfromBase64StringAndWrite(Password.Salt, Password.Hash);
            Md5 = CreateHasher(Path.GetFullPath(dirPath));
        }
Ejemplo n.º 4
0
        public void CreateFileSha256Hash()
        {
            var file         = Path.Combine(testDirectory, "Aquatic Flowers.jpg");
            var readAllBytes = File.ReadAllBytes(file);
            var hashFile     = new HashFile();
            var sha256Hash   = hashFile.GenerateHash(readAllBytes, HashType.SHA256);

            Assert.That(sha256Hash, Is.EqualTo("34B6919D75D14DE1D8EF71F0ECB288FF47CAA37A475EF9063C0B42A75409A443"));
        }
Ejemplo n.º 5
0
        private void WriteEncryptedBytes(string fileName, byte[] fileBytes)
        {
            Encryptor = Factory.CreateEncryptor(Password);
            byte[] Encrypted = Encryptor.Encrypt(fileBytes);
            File.WriteAllBytes(fileName, Encrypted);
            Md5 = CreateHasher(fileName);
            string hashString = Md5.BeginHashing();

            HashFile.TransformStringAndWrite(fileName, hashString);
        }
Ejemplo n.º 6
0
        public void CreateFileMd5Hash()
        {
            string file         = Path.Combine(testDirectory, "Aquatic Flowers.jpg");
            var    readAllBytes = File.ReadAllBytes(file);

            var hashFile = new HashFile();
            var md5Hash  = hashFile.GenerateHash(readAllBytes);

            Assert.That(md5Hash, Is.EqualTo("35D25CDEB2EB861F6DEC063E62FC78A4"));
        }
Ejemplo n.º 7
0
        public async Task Update()
        {
            await Task.Run(() =>
            {
                using (WebClient web = new WebClient())
                {
                    string hashes       = web.DownloadString(Options.UpdateServer + "hash.txt");
                    var onlineFiles     = HashFile.ParseList(hashes);
                    string[] localFiles = Directory.GetFiles(Environment.CurrentDirectory, "*.*", SearchOption.TopDirectoryOnly);

                    for (int i = 0; i < localFiles.Length; i++)
                    {
                        string filePath = localFiles[i];
                        string file     = Path.GetFileName(filePath);

                        if (file.ToUpperInvariant() == "CONFIG.TXT" || file.ToUpperInvariant() == "DRIVERSOLUTIONS.PATCHER.EXE")
                        {
                            continue;
                        }

                        Progress("Checking: " + file, 0);

                        var check = onlineFiles.Where(f => f.FileName == file).FirstOrDefault();
                        if (check == null)
                        {
                            //delete
                            DeleteFile(filePath);
                        }
                        else
                        {
                            //hash check
                            byte[] data = File.ReadAllBytes(filePath);
                            string hash = Tools.Hash(data);
                            if (check.Hash == hash)
                            {
                                onlineFiles.Remove(check);
                            }
                        }
                    }

                    for (int i = 0; i < onlineFiles.Count; i++)
                    {
                        var file = onlineFiles[i].FileName;
                        Progress("Patching: " + file, i, onlineFiles.Count);

                        DeleteFile(file);
                        byte[] data = web.DownloadData(Options.UpdateServer + file + ".gzip");
                        Tools.Decompress(data, file);
                    }

                    UpdateComplete();
                }
            });
        }
        private bool IsHashValid()
        {
            _sourceFileName  = HashFile.Substring(0, HashFile.Length - (HashType.Length + 1));
            _hashFileContent = File.ReadAllText(HashFile);

            if (!File.Exists(_sourceFileName))
            {
                return(false);
            }

            _sourceFileHash = _calculate.Hash(_sourceFileName, HashType);
            return(_sourceFileHash.Trim().Equals(_hashFileContent.Trim(), StringComparison.InvariantCultureIgnoreCase));
        }
Ejemplo n.º 9
0
        private static List <ManifestRelease> CreateManifestReleaseList(string cuo_path, string version, string name)
        {
            List <ManifestRelease> list = new List <ManifestRelease>();

            DirectoryInfo dir = new DirectoryInfo(cuo_path);

            if (dir.Exists)
            {
                ManifestRelease release = new ManifestRelease()
                {
                    version = version,
                    name    = name
                };

                foreach (var f in _file_list)
                {
                    string path = Path.Combine(cuo_path, f);

                    if (File.Exists(path))
                    {
                        var hash_file = new HashFile()
                        {
                            filename = f,
                            hash     = CalculateMD5(path)
                        };
                        release.files.Add(hash_file);

                        Console.WriteLine(hash_file);
                    }
                }

                //var files = dir.GetFiles("*.*", SearchOption.AllDirectories).Where(s => Path.HasExtension("exe"));


                //foreach (FileInfo file in files)
                //{
                //    var hash_file = new HashFile()
                //    {
                //        filename = file.FullName.Replace(cuo_path, ""),
                //        hash = CalculateMD5(file.FullName)
                //    };
                //    release.files.Add(hash_file);

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

                list.Add(release);
            }

            return(list);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Finds the cached version or populates a new entry.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public string[] GetFile(string fileName)
        {
            int hash = fileName.GetHashCode();

            // Check if cached.
            for (int i = 0; i < this.indexLeft; i++)
            {
                if (this.files[i].hash == hash)
                {
                    return(this.files[i].lines);
                }
            }

            try
            {
                // Populate new file.
                HashFile hashFile = new HashFile(hash);

                hashFile.lines = File.ReadAllLines(fileName);

                InternalNGDebug.Assert(HQ.Settings != null, "NGSettings is null.");

                for (int i = 0; i < hashFile.lines.Length; i++)
                {
                    hashFile.lines[i] = Utility.Color((i + 1).ToString(), HQ.Settings.Get <StackTraceSettings>().previewLineColor) + ConsoleUtility.ColorLine(hashFile.lines[i]);
                }

                // Check array overflow.
                if (this.indexLeft == this.files.Length)
                {
                    Array.Resize(ref this.files, this.files.Length << 1);
                }

                this.files[this.indexLeft] = hashFile;
                ++this.indexLeft;

                //Debug.Log("Cached file:" + fileName);
                return(hashFile.lines);
            }
            catch (Exception ex)
            {
                InternalNGDebug.LogException(ex);
            }

            return(null);
        }
 public Form1()
 {
     InitializeComponent();
     my_file = new HashFile();
 }
Ejemplo n.º 12
0
 public static bool ValidateFileHash(string fileName, HashFile hashFile)
 {
     if (!hashDict.TryGetValue(hashFile, out byte[] validHash))
Ejemplo n.º 13
0
        public override async Task <WorkResult <HashFile> > RunAsync(HashFile workunit, IProgress <IWorkProgress <HashFile> > progress = null, CancellationToken token = default(CancellationToken))
        {
            //TODO WIP, first (database refactor)
            throw new NotImplementedException();

            /*
             * int nshareID = -1;
             * string filePath = string.Empty;
             *
             *
             * Tuple<SVR_ImportFolder, string> tup = VideoLocal_PlaceRepository.GetFromFullPath(workunit.File.FullName);
             * if (tup == null)
             *  return new WorkResult<HashFile>(WorkResultStatus.Error, logger, $"Unable to locate Import Folder for {workunit.File.FullName}");
             * SVR_ImportFolder folder = tup.Item1;
             * filePath = tup.Item2;
             * IFileSystem f = tup.Item1.FileSystem;
             * if (f == null)
             *  return new WorkResult<HashFile>(WorkResultStatus.Error, logger, $"Unable to open filesystem for: {workunit.File.FullName}");
             * long filesize = 0;
             * if (folder.CloudID == null) // Local Access
             * {
             *  if (!File.Exists(workunit.File.FullName))
             *      return new WorkResult<HashFile>(WorkResultStatus.Error, logger, $"File does not exist: {workunit.File.FullName}");
             *  int numAttempts = 0;
             *
             *  // Wait 1 minute seconds before giving up on trying to access the file
             *  while ((filesize = CanAccessFile(workunit.File.FullName)) == 0 && (numAttempts < 10))
             *  {
             *      numAttempts++;
             *      await Task.Delay(6000, token);
             *  }
             *
             *  // if we failed to access the file, get ouuta here
             *  if (numAttempts >= 60)
             *      return new WorkResult<HashFile>(WorkResultStatus.Error, logger, $"Could not access file: {workunit.File.FullName}");
             * }
             *
             * IFile source_file = workunit.File;
             * if (folder.CloudID.HasValue)
             *  filesize = source_file.Size;
             * nshareID = folder.ImportFolderID;
             * // check if we have already processed this file
             *
             *
             * SVR_VideoLocal_Place vlocalplace = Repo.Instace.VideoLocal_Place.GetByFilePathAndShareID(filePath, nshareID);
             * SVR_VideoLocal vlocal = null;
             *
             * if (vlocalplace != null)
             * {
             *  vlocal = vlocalplace.VideoLocal;
             *  logger.Trace("VideoLocal record found in database: {0}", vlocal.VideoLocalID);
             *
             *  if (vlocalplace.FullServerPath == null)
             *  {
             *      if (vlocal.Places.Count == 1)
             *      {
             *          Repo.Instace.VideoLocal.Delete(vlocal);
             *          vlocal = null;
             *      }
             *      Repo.Instace.VideoLocal_Place.Delete(vlocalplace);
             *      vlocalplace = null;
             *  }
             *  if (vlocal != null && workunit.Force)
             *  {
             *      vlocal.FileSize = filesize;
             *      vlocal.DateTimeUpdated = DateTime.Now;
             *  }
             * }
             *
             * if (vlocal == null)
             * {
             *  logger.Trace("VideoLocal, creating temporary record");
             *  vlocal = new SVR_VideoLocal
             *  {
             *      DateTimeUpdated = DateTime.Now,
             *      DateTimeCreated = DateTime.Now,
             *      FileName = Path.GetFileName(filePath),
             *      FileSize = filesize,
             *      Hash = string.Empty,
             *      CRC32 = string.Empty,
             *      MD5 = source_file?.MD5?.ToUpperInvariant() ?? string.Empty,
             *      SHA1 = source_file?.SHA1?.ToUpperInvariant() ?? string.Empty,
             *      IsIgnored = 0,
             *      IsVariation = 0
             *  };
             * }
             *
             * if (vlocalplace == null)
             * {
             *  vlocalplace = new SVR_VideoLocal_Place
             *  {
             *      FilePath = filePath,
             *      ImportFolderID = nshareID,
             *      ImportFolderType = folder.ImportFolderType
             *  };
             *  // Make sure we have an ID
             *  Repo.Instace.VideoLocal_Place.Save(vlocalplace);
             * }
             * // check if we need to get a hash this file
             * if (string.IsNullOrEmpty(vlocal.Hash) || workunit.Force)
             * {
             *  // try getting the hash from the CrossRef
             *  if (!workunit.Force)
             *  {
             *      List<CrossRef_File_Episode> crossRefs =
             *          Repo.Instace.CrossRef_File_Episode.GetByFileNameAndSize(vlocal.FileName, vlocal.FileSize);
             *      if (crossRefs.Count == 1)
             *      {
             *          vlocal.Hash = crossRefs[0].Hash;
             *          vlocal.HashSource = (int)HashSource.DirectHash;
             *      }
             *  }
             *
             *  // try getting the hash from the LOCAL cache
             *  if (!workunit.Force && string.IsNullOrEmpty(vlocal.Hash))
             *  {
             *      List<FileNameHash> fnhashes =
             *          Repo.Instace.FileNameHash.GetByFileNameAndSize(vlocal.FileName, vlocal.FileSize);
             *      if (fnhashes != null && fnhashes.Count > 1)
             *      {
             *          // if we have more than one record it probably means there is some sort of corruption
             *          // lets delete the local records
             *          foreach (FileNameHash fnh in fnhashes)
             *          {
             *              Repo.Instace.FileNameHash.Delete(fnh.FileNameHashID);
             *          }
             *      }
             *      // reinit this to check if we erased them
             *      fnhashes = Repo.Instace.FileNameHash.GetByFileNameAndSize(vlocal.FileName, vlocal.FileSize);
             *
             *      if (fnhashes != null && fnhashes.Count == 1)
             *      {
             *          logger.Trace("Got hash from LOCAL cache: {0} ({1})", workunit.File.FullName, fnhashes[0].Hash);
             *          vlocal.Hash = fnhashes[0].Hash;
             *          vlocal.HashSource = (int)HashSource.WebCacheFileName;
             *      }
             *  }
             *  if (string.IsNullOrEmpty(vlocal.Hash))
             *      FillVideoHashes(vlocal);
             *
             *  //Cloud and no hash, Nothing to do, except maybe Get the mediainfo....
             *  if (string.IsNullOrEmpty(vlocal.Hash) && folder.CloudID.HasValue)
             *  {
             *      logger.Trace("No Hash found for cloud " + vlocal.FileName +
             *                   " putting in videolocal table with empty ED2K");
             *      Repo.Instace.VideoLocal.Save(vlocal, false);
             *      vlocalplace.VideoLocalID = vlocal.VideoLocalID;
             *      Repo.Instace.VideoLocal_Place.Save(vlocalplace);
             *      if (vlocalplace.RefreshMediaInfo())
             *          Repo.Instace.VideoLocal.Save(vlocalplace.VideoLocal, true);
             *      return new WorkResult<HashFile>(workunit);
             *  }
             *
             *  // hash the file
             *  if (string.IsNullOrEmpty(vlocal.Hash) || workunit.Force)
             *  {
             *      logger.Info("Hashing File: {0}", FileName);
             *      ShokoService.CmdProcessorHasher.QueueState = PrettyDescriptionHashing;
             *      DateTime start = DateTime.Now;
             *      logger.Trace("Calculating ED2K hashes for: {0}", FileName);
             *      // update the VideoLocal record with the Hash, since cloud support we calculate everything
             *      var hashes = FileHashHelper.GetHashInfo(FileName.Replace("/", $"{System.IO.Path.DirectorySeparatorChar}"), true, ShokoServer.OnHashProgress,
             *          true, true, true);
             *      TimeSpan ts = DateTime.Now - start;
             *      logger.Trace("Hashed file in {0:#0.0} seconds --- {1} ({2})", ts.TotalSeconds, FileName,
             *          Utils.FormatByteSize(vlocal.FileSize));
             *      vlocal.Hash = hashes.ED2K?.ToUpperInvariant();
             *      vlocal.CRC32 = hashes.CRC32?.ToUpperInvariant();
             *      vlocal.MD5 = hashes.MD5?.ToUpperInvariant();
             *      vlocal.SHA1 = hashes.SHA1?.ToUpperInvariant();
             *      vlocal.HashSource = (int)HashSource.DirectHash;
             *  }
             *  FillMissingHashes(vlocal);
             *  // We should have a hash by now
             *  // before we save it, lets make sure there is not any other record with this hash (possible duplicate file)
             *
             *  SVR_VideoLocal tlocal = Repo.Instace.VideoLocal.GetByHash(vlocal.Hash);
             *  bool duplicate = false;
             *  bool changed = false;
             *
             *  if (tlocal != null)
             *  {
             *      // Aid with hashing cloud. Merge hashes and save, regardless of duplicate file
             *      changed = tlocal.MergeInfoFrom(vlocal);
             *      vlocal = tlocal;
             *
             *      List<SVR_VideoLocal_Place> preps = vlocal.Places.Where(
             *          a => a.ImportFolder.CloudID == folder.CloudID &&
             *               !vlocalplace.FullServerPath.Equals(a.FullServerPath)).ToList();
             *      foreach (var prep in preps)
             *      {
             *          if (prep == null) continue;
             *          // clean up, if there is a 'duplicate file' that is invalid, remove it.
             *          if (prep.FullServerPath == null)
             *          {
             *              Repo.Instace.VideoLocal_Place.Delete(prep);
             *          }
             *          else
             *          {
             *              FileSystemResult dupFileSystemResult =
             *                  prep.ImportFolder?.FileSystem?.Resolve(prep.FullServerPath);
             *              if (dupFileSystemResult == null || !dupFileSystemResult.IsOk)
             *                  Repo.Instace.VideoLocal_Place.Delete(prep);
             *          }
             *      }
             *
             *      var dupPlace = vlocal.Places.FirstOrDefault(
             *          a => a.ImportFolder.CloudID == folder.CloudID &&
             *               !vlocalplace.FullServerPath.Equals(a.FullServerPath));
             *
             *      if (dupPlace != null)
             *      {
             *          // delete the VideoLocal record
             *          logger.Warn("Found Duplicate File");
             *          logger.Warn("---------------------------------------------");
             *          logger.Warn($"New File: {vlocalplace.FullServerPath}");
             *          logger.Warn($"Existing File: {dupPlace.FullServerPath}");
             *          logger.Warn("---------------------------------------------");
             *
             *          // check if we have a record of this in the database, if not create one
             *          List<DuplicateFile> dupFiles = Repo.Instace.DuplicateFile.GetByFilePathsAndImportFolder(
             *              vlocalplace.FilePath,
             *              dupPlace.FilePath,
             *              vlocalplace.ImportFolderID, dupPlace.ImportFolderID);
             *          if (dupFiles.Count == 0)
             *              dupFiles = Repo.Instace.DuplicateFile.GetByFilePathsAndImportFolder(dupPlace.FilePath,
             *                  vlocalplace.FilePath, dupPlace.ImportFolderID, vlocalplace.ImportFolderID);
             *
             *          if (dupFiles.Count == 0)
             *          {
             *              DuplicateFile dup = new DuplicateFile
             *              {
             *                  DateTimeUpdated = DateTime.Now,
             *                  FilePathFile1 = vlocalplace.FilePath,
             *                  FilePathFile2 = dupPlace.FilePath,
             *                  ImportFolderIDFile1 = vlocalplace.ImportFolderID,
             *                  ImportFolderIDFile2 = dupPlace.ImportFolderID,
             *                  Hash = vlocal.Hash
             *              };
             *              Repo.Instace.DuplicateFile.Save(dup);
             *          }
             *          //Notify duplicate, don't delete
             *          duplicate = true;
             *      }
             *  }
             *
             *  if (!duplicate || changed)
             *      Repo.Instace.VideoLocal.Save(vlocal, true);
             *
             *  vlocalplace.VideoLocalID = vlocal.VideoLocalID;
             *  Repo.Instace.VideoLocal_Place.Save(vlocalplace);
             *
             *  if (duplicate)
             *  {
             *      CommandRequest_ProcessFile cr_procfile3 =
             *          new CommandRequest_ProcessFile(vlocal.VideoLocalID, false);
             *      cr_procfile3.Save();
             *      return vlocalplace;
             *  }
             *
             *  // also save the filename to hash record
             *  // replace the existing records just in case it was corrupt
             *  FileNameHash fnhash;
             *  List<FileNameHash> fnhashes2 =
             *      Repo.Instace.FileNameHash.GetByFileNameAndSize(vlocal.FileName, vlocal.FileSize);
             *  if (fnhashes2 != null && fnhashes2.Count > 1)
             *  {
             *      // if we have more than one record it probably means there is some sort of corruption
             *      // lets delete the local records
             *      foreach (FileNameHash fnh in fnhashes2)
             *      {
             *          Repo.Instace.FileNameHash.Delete(fnh.FileNameHashID);
             *      }
             *  }
             *
             *  if (fnhashes2 != null && fnhashes2.Count == 1)
             *      fnhash = fnhashes2[0];
             *  else
             *      fnhash = new FileNameHash();
             *
             *  fnhash.FileName = vlocal.FileName;
             *  fnhash.FileSize = vlocal.FileSize;
             *  fnhash.Hash = vlocal.Hash;
             *  fnhash.DateTimeUpdated = DateTime.Now;
             *  Repo.Instace.FileNameHash.Save(fnhash);
             * }
             * else
             * {
             *  FillMissingHashes(vlocal);
             * }
             *
             *
             * if ((vlocal.Media == null) || vlocal.MediaVersion < SVR_VideoLocal.MEDIA_VERSION || vlocal.Duration == 0)
             * {
             *  if (vlocalplace.RefreshMediaInfo())
             *      Repo.Instace.VideoLocal.Save(vlocalplace.VideoLocal, true);
             * }
             * // now add a command to process the file
             * CommandRequest_ProcessFile cr_procfile = new CommandRequest_ProcessFile(vlocal.VideoLocalID, false);
             * cr_procfile.Save();
             *
             * return vlocalplace;        */
        }
Ejemplo n.º 14
0
        private void ProcessRequest(Options commandLineOptions)
        {
            StreamHasher fileHashMaker;

            switch (commandLineOptions.HashAgorithm.ToUpper())
            {
            case "MD160":
                fileHashMaker = new MD160Hasher();
                break;

            case "SHA1":
                fileHashMaker = new SHA1Hasher();
                break;

            case "SHA256":
                fileHashMaker = new SHA256Hasher();
                break;

            case "SHA384":
                fileHashMaker = new SHA384Hasher();
                break;

            case "SHA512":
                fileHashMaker = new SHA512Hasher();
                break;

            case "MD5":
            default:
                fileHashMaker = new MD5Hasher();
                break;
            }

            fileHashMaker.HashBlockProcessed += fileHashMaker_HashBlockProcessed;

            List <String[]> inputFiles = new List <String[]>();

            if (commandLineOptions.Concatenate)
            {
                // Files will be treated as a single stream -
                // copy all filenames into a string array,
                // then add the array to the List
                String[] files = new String[commandLineOptions.Items.Count];
                for (int loop = 0; loop < commandLineOptions.Items.Count; loop++)
                {
                    files[loop] = commandLineOptions.Items[loop];
                }
                inputFiles.Add(files);
            }
            else
            {
                // Each file treated as a separate entity -
                // copy each filename into a separate string array,
                // then add each array to the List
                foreach (String fileToProcess in commandLineOptions.Items)
                {
                    String[] file = new String[] { fileToProcess };
                    inputFiles.Add(file);
                }
            }
            foreach (String[] fileEntry in inputFiles)
            {
                byte[] fileHash = fileHashMaker.ComputeFileHash(fileEntry, (int)commandLineOptions.BlockSize);
                Console.WriteLine(commandLineOptions.HashAgorithm.ToUpper() + ": " + BitConverter.ToString(fileHash));

                if (!string.IsNullOrWhiteSpace(commandLineOptions.AppendToHashFile))
                {
                    var settings = HashFile.OpenFile(commandLineOptions.AppendToHashFile);
                    settings.Add(fileEntry[0], BitConverter.ToString(fileHash).Replace("-", string.Empty), commandLineOptions.HashAgorithm.ToUpper());
                    settings.Save();
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Chargé en mémoire le fichier Rom spécifier par this._FileName
        /// </summary>
        /// <returns>Return true si le fichier est bien chargé</returns>
        public bool Load()
        {
            if (File.Exists(this._FileName))
            {
                if (SnesRom.isValid(this._FileName))                   //Verifie si le fichier Rom valide
                //Variable de Verification pour determiner de quel type est la rom a charg
                {
                    string CheckLow1     = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81DC", "81DD", this.FileName, true));
                    string CheckLow2     = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81DE", "81DF", this.FileName, true));
                    string CheckLow1b    = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FDC", "7FDD", this.FileName, true));
                    string CheckLow2b    = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FDE", "7FDF", this.FileName, true));
                    string CheckHigh1    = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101DC", "101DD", this.FileName, true));
                    string CheckHigh2    = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101DE", "101DF", this.FileName, true));
                    string CheckHigh1b   = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFDC", "FFDD", this.FileName, true));
                    string CheckHigh2b   = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFDE", "FFDF", this.FileName, true));
                    long   ValCheckLowb  = Convertir.HexaToDecimal(CheckLow1b) + Convertir.HexaToDecimal(CheckLow2b);
                    long   ValCheckHigh  = Convertir.HexaToDecimal(CheckHigh1) + Convertir.HexaToDecimal(CheckHigh2);
                    long   ValCheckHighb = Convertir.HexaToDecimal(CheckHigh1b) + Convertir.HexaToDecimal(CheckHigh2b);
                    long   ValCheckLow   = Convertir.HexaToDecimal(CheckLow1) + Convertir.HexaToDecimal(CheckLow2);

                    //Extraire les informations sur la rom dependant du type de rom
                    if (ValCheckLow == 65535)                     //LowRom 1
                    {
                        this._RomType       = RomType.LowRom_School_1;
                        this._RomName       = ExtractData.AspireString("81C0", "81D4", this.FileName).TrimEnd(new char[] { ' ' });
                        this._PostitionName = (int)Convertir.HexaToDecimal("81C0");
                        this._InfoCart      = (InformationCartouche)
                                              Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("81D6", "81D6", this.FileName, true)));
                        this._RomSizeMB = (ROMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("81D7", "81D7", this.FileName, true)));
                        this._RamSizeKB = (RAMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("81D8", "81D8", this.FileName, true)));
                        this._Country = (Country)
                                        Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("81D9", "81D9", this.FileName, true)));
                        this._Compagnie = (Compagnie)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("81DA", "81DA", this.FileName, true)));
                        this._Version      = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81DB", "81DB", this.FileName, true));
                        this._CompChecksum = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81DC", "81DD", this.FileName, true));
                        this._Checksum     = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81DE", "81DF", this.FileName, true));
                        this._NmiVblVector = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81EA", "81EB", this.FileName, true));
                        this._ResetVector  = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81FC", "81FD", this.FileName, true));
                    }
                    else if (ValCheckLowb == 65535)                      //LowRom 2
                    {
                        this._RomType       = RomType.LowRom_School_2;
                        this._RomName       = ExtractData.AspireString("7FC0", "7FD4", this.FileName).TrimEnd(new char[] { ' ' });
                        this._PostitionName = (int)Convertir.HexaToDecimal("7FC0");
                        this._InfoCart      = (InformationCartouche)
                                              Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("7FD6", "7FD6", this.FileName, true)));
                        this._RomSizeMB = (ROMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("7FD7", "7FD7", this.FileName, true)));
                        this._RamSizeKB = (RAMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("7FD8", "7FD8", this.FileName, true)));
                        this._Country = (Country)
                                        Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("7FD9", "7FD9", this.FileName, true)));
                        this._Compagnie = (Compagnie)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("7FDA", "7FDA", this.FileName, true)));
                        this._Version      = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FDB", "7FDB", this.FileName, true));
                        this._CompChecksum = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FDC", "7FDD", this.FileName, true));
                        this._Checksum     = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FDE", "7FDF", this.FileName, true));
                        this._NmiVblVector = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FEA", "7FEB", this.FileName, true));
                        this._ResetVector  = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FFC", "7FFD", this.FileName, true));
                    }
                    else if (ValCheckHigh == 65535)                      // HighRom
                    {
                        this._RomType       = RomType.HighRom;
                        this._RomName       = ExtractData.AspireString("101C0", "101D4", this.FileName).TrimEnd(new char[] { ' ' });
                        this._PostitionName = (int)Convertir.HexaToDecimal("101C0");
                        this._InfoCart      = (InformationCartouche)
                                              Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("101D6", "101D6", this.FileName, true)));
                        this._RomSizeMB = (ROMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("101D7", "101D7", this.FileName, true)));
                        this._RamSizeKB = (RAMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("101D8", "101D8", this.FileName, true)));
                        this._Country = (Country)
                                        Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("101D9", "101D9", this.FileName, true)));
                        this._Compagnie = (Compagnie)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("101DA", "101DA", this.FileName, true)));
                        this._Version      = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101DB", "101DB", this.FileName, true));
                        this._CompChecksum = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101DC", "101DD", this.FileName, true));
                        this._Checksum     = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101DE", "101DF", this.FileName, true));
                        this._NmiVblVector = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101EA", "101EB", this.FileName, true));
                        this._ResetVector  = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101FC", "101FD", this.FileName, true));
                    }
                    else if (ValCheckHighb == 65535)                      // HighRom
                    {
                        this._RomType       = RomType.HighRom;
                        this._RomName       = ExtractData.AspireString("FFC0", "FFD4", this.FileName).TrimEnd(new char[] { ' ' });
                        this._PostitionName = (int)Convertir.HexaToDecimal("FFC0");
                        this._InfoCart      = (InformationCartouche)
                                              Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("FFD6", "FFD6", this.FileName, true)));
                        this._RomSizeMB = (ROMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("FFD7", "FFD7", this.FileName, true)));
                        this._RamSizeKB = (RAMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("FFD8", "FFD8", this.FileName, true)));
                        this._Country = (Country)
                                        Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("FFD9", "FFD9", this.FileName, true)));
                        this._Compagnie = (Compagnie)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("FFDA", "FFDA", this.FileName, true)));
                        this._Version      = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFDB", "FFDB", this.FileName, true));
                        this._CompChecksum = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFDC", "FFDD", this.FileName, true));
                        this._Checksum     = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFDE", "FFDF", this.FileName, true));
                        this._NmiVblVector = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFEA", "FFEB", this.FileName, true));
                        this._ResetVector  = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFFC", "FFFD", this.FileName, true));
                    }

                    //Format d'affichage
                    if (this._Country.ToString() == "Japon" ||
                        this._Country.ToString() == "USA")
                    {
                        this._FormatAffichage = FormatAffichage.NTSC;
                    }
                    else
                    {
                        this._FormatAffichage = FormatAffichage.PAL;
                    }

                    //MD5 hashing
                    this._MD5 = HashFile.GetMD5Hexa(this._FileName);

                    #region DEBUG INFOS : Informations sur la Rom
//					#if DEBUG //Informations de debuggage
//						Debug.WriteLine("DEBUG INFOS START : VRS.Library.Console.SuperNintendo.SnesRom.Load()");
//						Debug.WriteLine("CheckLow1        :" + CheckLow1);
//						Debug.WriteLine("CheckLow2        :" + CheckLow2);
//						Debug.WriteLine("CheckLow1b       :" + CheckLow1b);
//						Debug.WriteLine("CheckLow2b       :" + CheckLow2b);
//						Debug.WriteLine("CheckHigh1       :" + CheckHigh1);
//						Debug.WriteLine("CheckHigh2       :" + CheckHigh2);
//						Debug.WriteLine("CheckHigh1b      :" + CheckHigh1b);
//						Debug.WriteLine("CheckHigh2b      :" + CheckHigh2b);
//						Debug.WriteLine("ValCheckLowb     :" + ValCheckLowb);
//						Debug.WriteLine("ValCheckHigh     :" + ValCheckHigh);
//						Debug.WriteLine("ValCheckHighb    :" + ValCheckHighb);
//						Debug.WriteLine("ValCheckLow      :" + ValCheckLow);
//						Debug.WriteLine("this._RomName    :" + this._RomName);
//						Debug.WriteLine("this._InfoCart   :" + this._InfoCart.ToString());
//						Debug.WriteLine("this._RomSizeMB  :" + this._RomSizeMB.ToString());
//						Debug.WriteLine("this._RamSizeKB  :" + this._RamSizeKB.ToString());
//						Debug.WriteLine("this._Country    :" + this._Country.ToString());
//						Debug.WriteLine("this._Compagnie  :" + this._Compagnie.ToString());
//						Debug.WriteLine("this._version    : 1." + this._Version);
//						Debug.WriteLine("this._CompChecksum :" + this._CompChecksum);
//						Debug.WriteLine("this._Checksum :" + this._Checksum);
//						Debug.WriteLine("this._ResetVector :" + this._ResetVector);
//						Debug.WriteLine("this._NmiVblVector :" + this._NmiVblVector);
//						Debug.WriteLine("this._FormatAffichage :" + this._FormatAffichage);
//						Debug.WriteLine("this._MD5 :" + this._MD5);
//						Debug.WriteLine("DEBUG INFOS END : VRS.Library.Console.SuperNintendo.SnesRom.Load()");
//					#endif
                    #endregion

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                throw new FileNotFoundException();
            }
        }
Ejemplo n.º 16
0
 private void button8_Click(object sender, System.EventArgs e)
 {
     MessageBox.Show(this, HashFile.GetMD5Hexa(@"d:\cookies.txt"));
 }
Ejemplo n.º 17
0
        static void Main2()
        {
            Console.WriteLine("Columbia State Launcher - Update Service");
            Console.WriteLine("Version 1.0.0.0, (c) Columbia State Team");
            Console.WriteLine("Error report: https://columbia-state.com");
            Console.WriteLine("----------------------------------------");
            Console.WriteLine("Azuriranja launcher-a automatski pocinje\n");

            FilesLibrary lib = new FilesLibrary();

            for (int i = 0; i < lib.Lenght; i++)
            {
                index = i;
                Console.Write(lib.Name(i).Substring(2));
                //for(int j = 0; j < (50 - lib.Name(i).Substring(2).Length); j++)
                //{
                //    Console.Write(" ");
                //}
                pozX = Console.CursorLeft + (50 - lib.Name(i).Substring(2).Length);
                pozY = Console.CursorTop;
                Write("provjera  ");
                if (File.Exists(lib.Name(i)))
                {
                    Write("valdacija ");
                    if (HashFile.GetMD5(lib.Name(i)) == lib.Hash(i))
                    {
                        Write("uredu     \n");
                        continue;
                    }
                    else
                    {
                        Write("brisanje  ");
                        File.Delete(lib.Name(i));

                        Write("skidanje ");

                        using (WebClient client = new WebClient())
                        {
                            var url = new Uri("https://columbia-state.com/launcher/" + lib.Name(i).Substring(2) + ".gz");
                            //client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
                            //client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);

                            //client.DownloadFileAsync(url, path + "\\" + lib.Name(i).Substring(2) + ".gz");
                            client.DownloadFile(url, path + "\\" + lib.Name(i).Substring(2) + ".gz");
                            //while (client.IsBusy) Thread.Sleep(100);
                        }

                        Write("dekompresija        ");
                        if (File.Exists(path + "\\" + lib.Name(i).Substring(2) + ".gz"))
                        {
                            FileInfo fi = new FileInfo(path + "\\" + lib.Name(i).Substring(2) + ".gz");
                            Decompress(fi);
                        }
                        else
                        {
                            error = true;
                            Write("greska u skidanju fajla");
                            break;
                        }
                        File.Delete(path + "\\" + lib.Name(i).Substring(2) + ".gz");

                        Write("provjera            ");
                        if (File.Exists(lib.Name(i)))
                        {
                            Write("valdacija           ");
                            if (HashFile.GetMD5(lib.Name(i)) == lib.Hash(i))
                            {
                                Write("uredu     \n");
                                continue;
                            }
                            else
                            {
                                error = true;
                                Write("greska u valdaciji skinutog fajla");
                                break;
                            }
                        }
                        else
                        {
                            error = true;
                            Write("greska u provjeri skinutog fajla");
                            break;
                        }
                    }
                }
                else
                {
                    Write("skidanje ");
                    using (WebClient client = new WebClient())
                    {
                        var url = new Uri("https://columbia-state.com/launcher/" + lib.Name(i).Substring(2) + ".gz");
                        //client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
                        //client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);

                        //client.DownloadFileAsync(url, path + "\\" + lib.Name(i).Substring(2) + ".gz");
                        client.DownloadFile(url, path + "\\" + lib.Name(i).Substring(2) + ".gz");
                        //while (client.IsBusy) Thread.Sleep(100);
                    }

                    Write("dekompresija");
                    if (File.Exists(path + "\\" + lib.Name(i).Substring(2) + ".gz"))
                    {
                        FileInfo fi = new FileInfo(path + "\\" + lib.Name(i).Substring(2) + ".gz");
                        Decompress(fi);
                    }
                    else
                    {
                        error = true;
                        Write("greska u skidanju fajla");
                        break;
                    }
                    File.Delete(path + "\\" + lib.Name(i).Substring(2) + ".gz");
                    Write("provjera    ");
                    if (File.Exists(lib.Name(i)))
                    {
                        Write("valdacija   ");
                        if (HashFile.GetMD5(lib.Name(i)) == lib.Hash(i))
                        {
                            Write("uredu     \n");
                            continue;
                        }
                        else
                        {
                            error = true;
                            Write("greska u valdaciji skinutog fajla");
                            break;
                        }
                    }
                    else
                    {
                        error = true;
                        Write("greska u provjeri skinutog fajla");
                        break;
                    }
                }
            }

            if (error)
            {
                Console.WriteLine("\nGreska tokom azuriranja, prijavite na https://columbia-state.com");
            }
            else
            {
                Console.WriteLine("\nUspjesno azuriranje, pokrenite aplikaciju");
            }

            Console.ReadKey();
        }