简体   繁体   English

.NET 标准 2.0 - Windows 注册表 - 适用于 Mac OS X - Unity

[英].NET Standard 2.0 - Windows Registry - works on Mac OS X - Unity

I have my project (originally developed on Unity - Windows) on API Compatibility Level set to .NET Standard 2.0, and in my project I have an external.dll class library compiled also as .NET Standard 2.0 in which is used Microsoft.Win32. I have my project (originally developed on Unity - Windows) on API Compatibility Level set to .NET Standard 2.0, and in my project I have an external.dll class library compiled also as .NET Standard 2.0 in which is used Microsoft.Win32. I am saving some data to the Windows Registry.我正在将一些数据保存到 Windows 注册表中。

Now I am adapting the project to work on Mac too, and I found that my external.dll with the Registry thing is working with no error on my Mac also.现在我也在调整项目以在 Mac 上工作,我发现我的 external.dll 与注册表的东西在我的 Mac 上也没有错误。

I've been trying to find where could that data be stored, as Mac's OS X doesn't have a Windows like Registry?我一直在试图找到这些数据可以存储在哪里,因为 Mac 的 OS X 没有像 Registry 这样的 Windows?

Why and how is this working?为什么以及如何工作?

The code is used as a.dll plugin in Unity.该代码在 Unity 中用作 a.dll 插件。

using Microsoft.Win32;

... ...

    private RegistryKey key;

    public StorageImpl()
    {
        key = Registry.CurrentUser.OpenSubKey(RegistryKeyPath, true);

        if (key == null)
        {
            key = Registry.CurrentUser.CreateSubKey(RegistryKeyPath);
        }
    }

    public DateTime? StartDate
    {
        get
        {
            object value = key.GetValue(RegistryStartDate);
            return value != null ? DateTime.FromBinary((long)value) : (DateTime?)null;
        }

        set
        {
            if (value != null)
            {
                key.SetValue(RegistryStartDate, value.Value.ToBinary(), RegistryValueKind.QWord);
            }
            else
            {
                key.DeleteValue(RegistryStartDate);
            }

            key.Flush();
        }
    }

I found where the data is being saved: /Users/user/.mono/registry/CurrentUser/software/nameOfSoftware/values.xml我找到了数据的保存位置: /Users/user/.mono/registry/CurrentUser/software/nameOfSoftware/values.xml

I had to search manually listing all folder content using terminal: ls -a我不得不使用终端手动搜索列出所有文件夹内容: ls -a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM