Beispiel #1
0
        /*
         *      この辺が1:1なのなんとかしたい。AtoBに一般化すればいいか。
         *      まあGUIから叩くようにしよう。このメソッドが生き残ることは多分ない。
         */
        static void FileSearch(Dictionary <string, FileDatas> dict, string baseDirPath, string ignoreBasePath)
        {
            foreach (string filePath in Directory.GetFiles(baseDirPath))
            {
                if (filePath.EndsWith(".meta"))
                {
                    continue;
                }

                var fileName = Path.GetFileName(filePath);
                if (fileName.StartsWith("."))
                {
                    continue;
                }

                // ignore base path
                var basePathIgnoredFilePath = filePath.Replace(ignoreBasePath, string.Empty);

                // ignore file extension. e.g. A.client.cs -> A.cs, B.server.cs -> B.cs
                var extentionIgnoredFilePath = basePathIgnoredFilePath.Replace(".client.", ".").Replace(".server.", ".");

                using (var md5 = MD5.Create())
                    using (var sr = new StreamReader(filePath)) {
                        var codes = sr.ReadToEnd();
                        var bytes = Encoding.UTF8.GetBytes(codes);
                        var hash  = md5.ComputeHash(bytes);

                        dict[extentionIgnoredFilePath] = new FileDatas(string.Join("-", hash.Select(b => b.ToString()).ToArray()), File.GetLastWriteTime(filePath));
                    }
            }
        }
Beispiel #2
0
        //ハッシュ値の取得
        private void GetFileHashValues(FileDatas data, string filePath)
        {
            IDictionary <string, HashAlgorithm> HashProviders = new Dictionary <string, HashAlgorithm>();                       //ハッシュアルゴリズム格納用

            //ハッシュアルゴリズムの登録
            HashProviders.Add("MD5", new MD5CryptoServiceProvider());
            HashProviders.Add("SHA256", new SHA256CryptoServiceProvider());
            HashProviders.Add("SHA384", new SHA384CryptoServiceProvider());
            HashProviders.Add("SHA512", new SHA512CryptoServiceProvider());

            //登録したすべてのアルゴリズムを利用して取得
            foreach (var key in HashProviders.Keys)
            {
                try
                {
                    using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                    {
                        byte[] hash = HashProviders[key].ComputeHash(stream);
                        data.HashButtons[key].Content = GetHashString(hash);
                    }
                }
                catch (Exception e)
                {
                    data.HashButtons[key].Content = "エラー";
                    MessageBox.Show(this, e.Message, "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Beispiel #3
0
 //ファイル読み込み
 private void FileLoad(FileDatas data, string path)
 {
     data.FilePath = path;                                                               //パスを設定
     data.InitHashList();                                                                //ハッシュリストを初期化
     data.ViewFileNameFlag = false;                                                      //ファイル名の表示を切替
     data.SetFileNameLabel();                                                            //ファイル名の表示を更新
     data.SetStatus(FileDatas.FileLoadStatus.Selected);                                  //状態を選択済みに変更
     GetFileHashValues(data, path);                                                      //ハッシュ値の取得
 }
Beispiel #4
0
 /// <summary>
 /// 仅仅添加外部b64数据
 /// </summary>
 /// <param name="item"></param>
 /// <param name="b64data"></param>
 public void AddPlain(string item, string b64data)
 {
     if (FileNames.Contains(item) == false)
     {
         Count++;
         FileNames.Add(item);
         FileDatas.Add(item, null);
     }
     if (FileStringDatas.ContainsKey(item) == false)
     {
         FileStringDatas.Add(item, b64data);
     }
     else
     {
         FileStringDatas[item] = (b64data);
     }
 }
Beispiel #5
0
        /// <summary>
        ///     Returns the FileInfo
        /// </summary>
        /// <returns></returns>
        public SqlStoreFileInfo GetFileInfo()
        {
            FileData lastdata;

            if (FileDatas == null)
            {
                using (var context = new OnlineFilesEntities())
                    lastdata = context.FileDatas.OrderByDescending(d => d.Revision).FirstOrDefault();
            }
            else
            {
                lastdata = FileDatas.OrderByDescending(d => d.Revision).FirstOrDefault();
            }

            var fileinfo = new SqlStoreFileInfo
            {
                Parent            = null,
                Path              = null,
                Exists            = true,
                CreationTime      = CreateDt,
                LastAccessTime    = CreateDt,
                LastWriteTime     = lastdata?.CreateDt ?? CreateDt,
                Directory         = false,
                Archive           = GetWin32Attribute(FileAttributes.Archive),
                Compressed        = GetWin32Attribute(FileAttributes.Compressed),
                Device            = GetWin32Attribute(FileAttributes.Device),
                Encrypted         = GetWin32Attribute(FileAttributes.Encrypted),
                NotContentIndexed = GetWin32Attribute(FileAttributes.NotContentIndexed),
                Offline           = GetWin32Attribute(FileAttributes.Offline),
                System            = GetWin32Attribute(FileAttributes.System),
                Hidden            = GetWin32Attribute(FileAttributes.Hidden),
                IntegrityStream   = GetWin32Attribute(FileAttributes.IntegrityStream),
                NoScrubData       = GetWin32Attribute(FileAttributes.NoScrubData),
                Normal            = GetWin32Attribute(FileAttributes.Normal),
                ReadOnly          = GetWin32Attribute(FileAttributes.ReadOnly),
                ReparsePoint      = GetWin32Attribute(FileAttributes.ReparsePoint),
                SparseFile        = GetWin32Attribute(FileAttributes.SparseFile),
                Temporary         = GetWin32Attribute(FileAttributes.Temporary),
                ObjectGuid        = pk_FileId
            };

            return(fileinfo);
        }