コード例 #1
0
            private static void DoCheckFileProperties(FileInfo fileInfo)
            {
                if (fileInfo == null || !fileInfo.Exists)
                {
                    return;
                }

                lock (FileCheckingLock)
                {
                    var checksum = Sha1.GetInstance().GenerateInHex(fileInfo);
                    var version  = GetVersionFrom(checksum);
                    if (!UnknownVersion.Equals(version))
                    {
                        Logger.GetInstance(typeof(DefaultOpenVRManager)).Debug($"{fileInfo.FullName}, sha1: {checksum}, version: {version}");
                        return;
                    }
                    Logger.GetInstance(typeof(DefaultOpenVRManager)).Warn($"{fileInfo.FullName}, sha1: {checksum}, version: {version}");

                    var sourceFileName = fileInfo.FullName;
                    var destFileName   = $"{sourceFileName}_{Convert.ToTimestampInMilli(DateTime.UtcNow)}.bak";
                    try
                    {
                        File.Move(sourceFileName, destFileName);
                    }
                    catch (Exception e)
                    {
                        Logger.GetInstance(typeof(DefaultOpenVRManager)).Error($"Can not move unknown \"{sourceFileName}\" to \"{destFileName}\". {e}");
                    }
                }
            }
コード例 #2
0
            private static string PrepareBinary(string resourceName, string platformName, string binaryName)
            {
                if (string.IsNullOrWhiteSpace(binaryName))
                {
                    return(null);
                }

                var binaryPath = GetBinaryFilePath(platformName, binaryName);

                if (string.IsNullOrWhiteSpace(binaryPath))
                {
                    Logger.GetInstance(typeof(DefaultOpenVRManager)).Error("Can not find binary path to load");
                    return(null);
                }

                lock (FileExtractingLock)
                {
                    if (File.Exists(binaryPath))
                    {
                        CheckFileProperties(new FileInfo(binaryPath));
                        return(binaryPath);
                    }

                    var tempBinaryPath = $"{binaryPath}.{Convert.ToTimestampInMilli(DateTime.UtcNow)}";

                    Extract.FromAssemblyToFileByResourceName(
                        resourceName,
                        new FileInfo(tempBinaryPath),
                        Extract.CompressionType.Gzip
                        );

                    if (!File.Exists(binaryPath) && File.Exists(tempBinaryPath))
                    {
                        try
                        {
                            File.Move(tempBinaryPath, binaryPath);
                        }
                        catch (Exception e)
                        {
                            Logger.GetInstance(typeof(DefaultOpenVRManager)).Error($"Can not move file from \"{tempBinaryPath}\". {e}");
                        }
                    }

                    if (File.Exists(binaryPath))
                    {
                        CheckFileProperties(new FileInfo(binaryPath));
                        return(binaryPath);
                    }
                }

                return(null);
            }