예제 #1
0
        private static ROOT _Read(StringReader textReader, ReadSettings settings)
        {
            Guard.NotNull(textReader, nameof(textReader));
            Guard.NotNull(settings, nameof(settings));

            using (var reader = new JsonTextReader(textReader))
            {
                var root = new ROOT();
                root.DeserializeObject(reader);

                var ex = root.Validate().FirstOrDefault();
                if (ex != null)
                {
                    throw ex;
                }

                foreach (var buffer in root._buffers)
                {
                    buffer._ResolveUri(settings.FileReader);
                }

                foreach (var image in root._images)
                {
                    image._ResolveUri(settings.FileReader);
                }

                return(root);
            }
        }
예제 #2
0
        /// <summary>
        /// 获取根句柄
        /// </summary>
        /// <returns></returns>
        private static RegistryKey GetRootKey(ROOT aRoot, string sSubKey)
        {
            RegistryKey aRootKey = Registry.CurrentUser;

            switch (aRoot)
            {
            case ROOT.CLASSES_ROOT:     aRootKey = Registry.ClassesRoot;        break;

            case ROOT.CURRENT_CONFIG:   aRootKey = Registry.CurrentConfig;      break;

            case ROOT.CURRENT_USER:     aRootKey = Registry.CurrentUser;        break;

            case ROOT.DYN_DATA:         aRootKey = Registry.PerformanceData;    break;

            case ROOT.LOCAL_MACHINE:    aRootKey = Registry.LocalMachine;       break;

            case ROOT.USERS:            aRootKey = Registry.Users;              break;
            }

            if (String.IsNullOrWhiteSpace(sSubKey))
            {
                return(aRootKey);
            }

            sSubKey = sSubKey.Replace('/', '\\');
            return(aRootKey.OpenSubKey(sSubKey));
        }
        internal Memory.MemoryAccessor _GetMemoryAccessor(ROOT root, int count, Accessor baseAccessor)
        {
            var view = root.LogicalBufferViews[this._bufferView];
            var info = new Memory.MemoryAccessInfo(null, this._byteOffset ?? 0, count, view.ByteStride, baseAccessor.Dimensions, baseAccessor.Encoding, baseAccessor.Normalized);

            return(new Memory.MemoryAccessor(view.Content, info));
        }
예제 #4
0
        public Func <int, T> GetDecoder <T>(ROOT root, ElementType et, ComponentType ct, bool normalized)
            where T : struct
        {
            var srcBuffer = root.LogicalBufferViews[this._bufferView];

            var decoder = srcBuffer.CreateValueDecoder(et, ct, normalized, this._byteOffset ?? 0);

            return(idx => (T)decoder(idx));
        }
예제 #5
0
        /// <summary>
        /// Writes a <see cref="ROOT"/> instance into a <see cref="BinaryWriter"/>.
        /// </summary>
        /// <param name="binaryWriter">The destination <see cref="BinaryWriter"/> stream.</param>
        /// <param name="model">The source <see cref="ROOT"/> instance.</param>
        public static void WriteBinaryModel(this BinaryWriter binaryWriter, ROOT model)
        {
            var ex = IsBinaryCompatible(model); if (ex != null)
            {
                throw ex;
            }

            var jsonText    = model.GetJSON(Newtonsoft.Json.Formatting.None);
            var jsonChunk   = Encoding.UTF8.GetBytes(jsonText);
            var jsonPadding = jsonChunk.Length & 3; if (jsonPadding != 0)
            {
                jsonPadding = 4 - jsonPadding;
            }

            var buffer = model.LogicalBuffers.Count > 0 ? model.LogicalBuffers[0].Content : null;

            if (buffer != null && buffer.Length == 0)
            {
                buffer = null;
            }

            var binPadding = buffer == null ? 0 : buffer.Length & 3; if (binPadding != 0)
            {
                binPadding = 4 - binPadding;
            }

            int fullLength = 4 + 4 + 4;

            fullLength += 8 + jsonChunk.Length + jsonPadding;
            if (buffer != null)
            {
                fullLength += 8 + buffer.Length + binPadding;
            }

            binaryWriter.Write(GLTFHEADER);
            binaryWriter.Write(GLTFVERSION2);
            binaryWriter.Write(fullLength);

            binaryWriter.Write(jsonChunk.Length + jsonPadding);
            binaryWriter.Write(CHUNKJSON);
            binaryWriter.Write(jsonChunk);
            for (int i = 0; i < jsonPadding; ++i)
            {
                binaryWriter.Write((Byte)0x20);
            }

            if (buffer != null)
            {
                binaryWriter.Write(buffer.Length + binPadding);
                binaryWriter.Write(CHUNKBIN);
                binaryWriter.Write(buffer);
                for (int i = 0; i < binPadding; ++i)
                {
                    binaryWriter.Write((Byte)0);
                }
            }
        }
예제 #6
0
        private static void AddComputerSystem(Computer computer, ROOT.CIMV2.Win32.ComputerSystem wmiComputerSystem)
        {
            // Set computer name
            computer.Name = wmiComputerSystem.Name;

            computer.System.LoggedOnUser = wmiComputerSystem.UserName;
            computer.System.Manufacturer = wmiComputerSystem.Manufacturer;
            computer.System.Model = wmiComputerSystem.Model;
            computer.System.Domain = wmiComputerSystem.Domain;
            computer.System.TotalMemory = wmiComputerSystem.TotalPhysicalMemory;
        }
예제 #7
0
        public Action <int, IList <Byte>, int, int> CopyTo(ROOT root, ElementType et, ComponentType ct)
        {
            var srcBuffer = root.LogicalBufferViews[this._bufferView];

            var itemLen   = et.Length() * ct.ByteLength();
            var srcStride = Math.Max(srcBuffer.ByteStride, itemLen);

            return((srcIdx, dstBuff, dstStride, dstIdx) =>
            {
                srcBuffer.Data.CopyTo(srcStride * srcIdx, dstBuff, dstStride * dstIdx, itemLen);
            });
        }
예제 #8
0
        public IReadOnlyList <int> GetIndices(ROOT root, int count)
        {
            var srcDecoder = GetDecoder(root);

            var indices = new int[count];

            for (int i = 0; i < indices.Length; ++i)
            {
                indices[i] = srcDecoder(i);
            }

            return(indices);
        }
예제 #9
0
        private static void AddLogicalDisk(Computer computer, ROOT.CIMV2.Win32.LogicalDisk wmiLogicalDisk)
        {
            LogicalDisk logicalDisk = new LogicalDisk();

            logicalDisk.Description = wmiLogicalDisk.Description;
            logicalDisk.Name = wmiLogicalDisk.Name;
            logicalDisk.ShareName = wmiLogicalDisk.ProviderName;
            logicalDisk.Type = wmiLogicalDisk.DriveType.ToString();
            logicalDisk.FileSystem = wmiLogicalDisk.FileSystem;
            logicalDisk.FreeSpace = wmiLogicalDisk.FreeSpace;
            logicalDisk.Size = wmiLogicalDisk.Size;

            computer.LogicalDisks.Add(logicalDisk);
        }
예제 #10
0
        /// <summary>
        /// 获取句柄
        /// </summary>
        /// <param name="sKeyPath">参数配置地址(相对路径,如“TMT\\Global”)</param>
        private static RegistryKey GetKeyByPath(string sKeyPath, ROOT aRoot, string sSubKey)
        {
            if (String.IsNullOrWhiteSpace(sKeyPath))
            {
                return(null);
            }

            sSubKey  = sSubKey.Replace('/', '\\');
            sKeyPath = sKeyPath.Replace('/', '\\');

            RegistryKey aRootKey     = GetRootKey(aRoot, sSubKey);
            RegistryKey aSoftwareKey = aRootKey.OpenSubKey(sKeyPath);

            return(aSoftwareKey);
        }
예제 #11
0
        /// <summary>
        /// Tells if a given model can be stored as Binary format.
        /// </summary>
        /// <param name="model">the model to test</param>
        /// <returns>null if it can be stored as binary, or an exception object if it can't</returns>
        /// <remarks>
        /// Due to the limitations of Binary Format, not all models can be saved as Binary.
        /// </remarks>
        public static Exception IsBinaryCompatible(ROOT model)
        {
            try
            {
                Guard.NotNull(model, nameof(model));
                Guard.IsTrue(model.LogicalBuffers.Count <= 1, nameof(model), $"{nameof(model)} GLB only supports one binary buffer, {model.LogicalBuffers.Count} found.");
            }
            catch (Exception ex)
            {
                return(ex);
            }

            // todo: buffer[0].Uri must be null

            return(null);
        }
예제 #12
0
        /// <summary>
        /// Tells if a given model can be stored as Binary format.
        /// </summary>
        /// <param name="model">the model to test</param>
        /// <returns>null if it can be stored as binary, or an exception object if it can't</returns>
        /// <remarks>
        /// Due to the limitations of Binary Format, not all models can be saved as Binary.
        /// </remarks>
        public static Exception IsBinaryCompatible(ROOT model)
        {
            try
            {
                Guard.NotNull(model, nameof(model));
                Guard.IsTrue(model.LogicalBuffers.Count <= 1, nameof(model), $"GLB format only supports one binary buffer, {model.LogicalBuffers.Count} found. It can be solved by calling {nameof(ModelRoot.MergeImages)} and {nameof(ModelRoot.MergeBuffers)}");
            }
            catch (ArgumentException ex)
            {
                return(ex);
            }

            // todo: buffer[0].Uri must be null

            return(null);
        }
예제 #13
0
        void BuildTree()
        {
            List <Node> nodes = new List <Node>();

            ROOT.BuildTree(nodes);
            Trace.Assert(nodes[0] == ROOT);
            nodes.RemoveAt(0);
            foreach (var o in nodes)
            {
                o.green.data.children.Add(o);
                //Debug.WriteLine($"{o.id} -> {o.green.id}" +
                //    $", children: {string.Join(",",o.data.children.Select(v=>v.id.ToString()))}" +
                //    $", edge: {string.Join(",",o.edge.Select(v=>v.Item1.ToString()))}");
                if (o.was_last != -1)
                {
                    o.data.count = 1;
                }
            }
        }
예제 #14
0
        /// <summary>
        /// 新建键值
        /// </summary>
        /// <param name="sKeyPath">参数配置地址(相对路径,如“TMT\\Global”)</param>
        /// <returns></returns>
        private static RegistryKey CreatKey(string sKeyPath, string sSubKey = "software\\Microsoft", ROOT aRoot = ROOT.CURRENT_USER)
        {
            if (String.IsNullOrWhiteSpace(sKeyPath))
            {
                return(null);
            }

            RegistryKey aSoftwareKey = GetKeyByPath(sKeyPath, aRoot, sSubKey);

            if (aSoftwareKey == null)
            {
                RegistryKey aKey = GetRootKey(aRoot, sSubKey);
                return(aKey.CreateSubKey(sKeyPath));
            }

            return(aSoftwareKey);
        }
예제 #15
0
        private static void AddProcessor(Computer computer, ROOT.CIMV2.Win32.Processor wmiProcessor)
        {
            Processor processor = new Processor();

            processor.Name = wmiProcessor.Name.Trim();
            processor.Speed = wmiProcessor.MaxClockSpeed;
            processor.L2CacheSize = wmiProcessor.L2CacheSize;
            processor.UpgradeMethod = wmiProcessor.UpgradeMethod.ToString();
            processor.Version = wmiProcessor.Version;

            computer.Processors.Add(processor);
        }
예제 #16
0
        /// <summary>
        /// 获取全部参数
        /// </summary>
        /// <param name="sKeyPath">参数配置地址(相对路径,如“TMT\\Global”)</param>
        public static string[] GetParaNames(string sKeyPath, string sSubKey = "software\\Microsoft", ROOT aRoot = ROOT.CURRENT_USER)
        {
            RegistryKey aSoftwareKey = GetKeyByPath(sKeyPath, aRoot, sSubKey);

            if (aSoftwareKey == null)
            {
                return(null);
            }

            return(aSoftwareKey.GetValueNames());
        }
예제 #17
0
        internal Memory.IntegerArray _GetIndicesArray(ROOT root, int count)
        {
            var srcBuffer = root.LogicalBufferViews[this._bufferView];

            return(new Memory.IntegerArray(srcBuffer.Content, this._byteOffset ?? 0, count, this._componentType));
        }
예제 #18
0
        /// <summary>
        /// 是否存在参数
        /// </summary>
        /// <param name="sKeyPath">参数配置地址(相对路径,如“TMT\\Global”)</param>
        /// <param name="sParaName">参数名</param>
        public static bool ExistPara(string sKeyPath, string sParaName, string sSubKey = "software\\Microsoft", ROOT aRoot = ROOT.CURRENT_USER)
        {
            RegistryKey aSoftwareKey = GetKeyByPath(sKeyPath, aRoot, sSubKey);

            if (aSoftwareKey == null)
            {
                return(false);
            }

            string[] pList = GetParaNames(sKeyPath);
            foreach (string sPara in pList)
            {
                if (sParaName == sPara)
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #19
0
        /// <summary>
        /// 删除全部参数
        /// </summary>
        /// <param name="sKeyPath">参数配置地址(相对路径,如“TMT\\Global”)</param>
        public static void ClearParas(string sKeyPath, string sSubKey = "software\\Microsoft", ROOT aRoot = ROOT.CURRENT_USER)
        {
            RegistryKey aSoftwareKey = GetKeyByPath(sKeyPath, aRoot, sSubKey);

            if (aSoftwareKey == null)
            {
                return;
            }

            string[] pList = GetParaNames(sKeyPath);
            foreach (string sPara in pList)
            {
                aSoftwareKey.DeleteValue(sPara);
            }

            aSoftwareKey.Close();
        }
예제 #20
0
        public Func <int, int> GetDecoder(ROOT root)
        {
            var srcBuffer = root.LogicalBufferViews[this._bufferView];

            return(srcBuffer.CreateIndexDecoder(this._componentType, this._byteOffset ?? 0));
        }
예제 #21
0
        /// <summary>
        /// 获取参数值(STRING)
        /// </summary>
        /// <param name="sKeyPath">参数配置地址(相对路径,如“TMT\\Global”)</param>
        /// <param name="sParaName">参数名</param>
        public static string GetValue(string sKeyPath, string sParaName, string sSubKey = "software\\Microsoft", ROOT aRoot = ROOT.CURRENT_USER)
        {
            RegistryKey aSoftwareKey = GetKeyByPath(sKeyPath, aRoot, sSubKey);

            if (aSoftwareKey == null)
            {
                return("");
            }

            return(aSoftwareKey.GetValue(sParaName, "").ToString());
        }
예제 #22
0
        private static void AddNetworkAdapter(Computer computer, ROOT.CIMV2.Win32.NetworkAdapterConfiguration wmiNetworkAdapter)
        {
            NetworkAdapter networkAdapter = new NetworkAdapter();
            networkAdapter.Model = wmiNetworkAdapter.Description;
            networkAdapter.DnsDomain = wmiNetworkAdapter.DNSDomain;
            networkAdapter.DnsHostName = wmiNetworkAdapter.DNSHostName;
            networkAdapter.MacAddress = wmiNetworkAdapter.MACAddress;
            networkAdapter.DhcpEnabled = wmiNetworkAdapter.DHCPEnabled;
            networkAdapter.DhcpLeaseExpirationDate = wmiNetworkAdapter.DHCPLeaseExpires;
            networkAdapter.DhcpLeaseObtainedDate = wmiNetworkAdapter.DHCPLeaseObtained;
            networkAdapter.DhcpServer = wmiNetworkAdapter.DHCPServer;
            networkAdapter.DatabasePath = wmiNetworkAdapter.DatabasePath;
            networkAdapter.WinsLMHostLookupEnabled = wmiNetworkAdapter.WINSEnableLMHostsLookup;
            networkAdapter.WinsHostLookupFile = wmiNetworkAdapter.WINSHostLookupFile;
            networkAdapter.WinsPrimaryServer = wmiNetworkAdapter.WINSPrimaryServer;
            networkAdapter.WinsSecondaryServer = wmiNetworkAdapter.WINSSecondaryServer;
            networkAdapter.Model = wmiNetworkAdapter.Description;

            networkAdapter.IPEnabled = wmiNetworkAdapter.IPEnabled;
            networkAdapter.IPAddresses = wmiNetworkAdapter.IPAddress;
            networkAdapter.DnsServers = wmiNetworkAdapter.DNSServerSearchOrder;
            networkAdapter.Gateways = wmiNetworkAdapter.DefaultIPGateway;
            networkAdapter.IPSubnets = wmiNetworkAdapter.IPSubnet;

            computer.NetworkAdapters.Add(networkAdapter);
        }
예제 #23
0
 private static void AddOperatingSystem(Computer computer, ROOT.CIMV2.Win32.OperatingSystem0 wmiOS)
 {
     computer.OperatingSystem.FreePhysicalMemory = wmiOS.FreePhysicalMemory;
     computer.OperatingSystem.FreeVirtualMemory = wmiOS.FreeVirtualMemory;
     computer.OperatingSystem.InstallDate = wmiOS.InstallDate;
     computer.OperatingSystem.LastBootUpTime = wmiOS.LastBootUpTime;
     computer.OperatingSystem.LocalDateTime = wmiOS.LocalDateTime;
     computer.OperatingSystem.Name = wmiOS.Caption;
     computer.OperatingSystem.SerialNumber = wmiOS.SerialNumber;
     computer.OperatingSystem.ServicePack = wmiOS.CSDVersion;
     computer.OperatingSystem.Version = wmiOS.Version;
     computer.OperatingSystem.WindowsDirectory = wmiOS.WindowsDirectory;
 }
예제 #24
0
        private static void AddPrinter(Computer computer, ROOT.CIMV2.Win32.Printer wmiPrinter)
        {
            Printer printer = new Printer();
            printer.Name = wmiPrinter.Name;
            printer.ShareName = wmiPrinter.ShareName;
            printer.ServerName = wmiPrinter.ServerName;
            printer.State = wmiPrinter.PrinterState.ToString();
            printer.Status = wmiPrinter.PrinterStatus.ToString();
            printer.DataType = wmiPrinter.PrintJobDataType;
            printer.HorizontalResolution = wmiPrinter.HorizontalResolution;
            printer.VerticalResolution = wmiPrinter.VerticalResolution;

            computer.Printers.Add(printer);
        }
예제 #25
0
        /// <summary>
        /// 获取参数值(FLOAT)
        /// </summary>
        /// <param name="sKeyPath">参数配置地址(相对路径,如“TMT\\Global”)</param>
        /// <param name="sParaName">参数名</param>
        public static float GetValue(string sKeyPath, string sParaName, float fDefault = 0, string sSubKey = "software\\Microsoft", ROOT aRoot = ROOT.CURRENT_USER)
        {
            string sValue = GetValue(sKeyPath, sParaName, sSubKey, aRoot);

            if (!String.IsNullOrWhiteSpace(sValue))
            {
                float fRet;
                if (float.TryParse(sValue, out fRet))
                {
                    return(fRet);
                }
            }
            return(fDefault);
        }
예제 #26
0
        private static void AddProcess(Computer computer, ROOT.CIMV2.Win32.Process wmiProcess)
        {
            Process process = new Process();
            process.Name = wmiProcess.Name;
            process.Path = wmiProcess.ExecutablePath;

            computer.Processes.Add(process);
        }
예제 #27
0
        private static void AddShare(Computer computer, ROOT.CIMV2.Win32.Share wmiShare)
        {
            Share share = new Share();
            share.Name = wmiShare.Name;
            share.Description = wmiShare.Description;
            share.Path = wmiShare.Path0;
            share.Type = wmiShare.Type.ToString();

            computer.Shares.Add(share);
        }
예제 #28
0
        /// <summary>
        /// 获取参数值(BOOL)
        /// </summary>
        /// <param name="sKeyPath">参数配置地址(相对路径,如“TMT\\Global”)</param>
        /// <param name="sParaName">参数名</param>
        public static bool GetValue(string sKeyPath, string sParaName, bool bDefault = false, string sSubKey = "software\\Microsoft", ROOT aRoot = ROOT.CURRENT_USER)
        {
            string sValue = GetValue(sKeyPath, sParaName, sSubKey, aRoot);

            if (!String.IsNullOrWhiteSpace(sValue))
            {
                bool bRet;
                if (bool.TryParse(sValue, out bRet))
                {
                    return(bRet);
                }
            }
            return(bDefault);
        }