【问题标题】:Notes Plugin: Where are Custom User Settings Stored?Notes 插件:自定义用户设置存储在哪里?
【发布时间】:2011-11-17 19:21:42
【问题描述】:

我们为 Notes 8.5.2 开发了一个自定义插件。它记录了许多自定义用户偏好。这样做的类如下所示:

import java.util.prefs.Preferences;

/**
 * Provides programmatic access to Windows Registry entries for this plug-in.
 */
public class Registry 
{
    Preferences prefs;    

    /**
     * Initializes a new instance of the Registry class.
     */
    public Registry()
    {
        prefs = Preferences.userNodeForPackage(Registry.class) ;    
    } 

    /**
     * Gets the value of a registry key.
     * 
     * @param keyName  The name of the key to return.
     * 
     * @return A string containing the value of the specified registry key. If a key with the specified name cannot be
     *         found, the return value is an empty string.
     */
    public String GetValue(String keyName)
    {
        try
        {
            return prefs.get(keyName, "NA") ;
        }
        catch(Exception err)
        {
            return  "" ;
        }

    }

    /**
     * Sets the value of a registry key.
     * 
     * @param keyName  The name of the registry key.
     * 
     * @param keyValue The new value for the registry key.
     */
    public void SetValue(String keyName, String keyValue)
    {
        try
        {
            prefs.put(keyName, keyValue);
            prefs.flush();
        }
        catch(Exception err)
        {
        }

    }
}

使用它的代码示例如下:

Registry wr = new Registry();
String setting1 = wr.GetValue("CustomSetting1");
wr.SetValue("CustomSetting1", newValue);

现在,我扫描了 Windows 注册表,但这些设置不存在。我已为我的整个硬盘编制索引,但在任何文件中都找不到这些条目。

那么,这些设置到底存储在哪里?

【问题讨论】:

    标签: plugins preferences


    【解决方案1】:

    在 Windows 上,Java Preferences API 使用注册表作为 Preferences 类的后备存储。密钥以HKEY_CURRENT_USER\Software\JavaSoft\Prefs 下的包名称为根。

    您的代码未指定包,因此默认使用以下位置(在 Windows Vista 和 7 上测试):

    HKEY_CURRENT_USER\Software\JavaSoft\Prefs\<unnamed>
    

    在 Sun Developer Network 上,Ray Djajadinataz 有一篇题为 "Sir, What is Your Preference?" 的文章,您可以通过一些显示注册表位置的屏幕截图了解更多有关此 API 的背景知识。

    我想知道您是否正在搜索键名,例如 CustomSetting1,但没有找到它,因为它被保存为 /Custom/Setting1 以注意 C 和 S 是大写的(请参阅 API 文档。)

    【讨论】:

    • 果然,他们就在那儿。他们的名字很奇怪。非常感谢!
    猜你喜欢
    • 2011-05-01
    • 1970-01-01
    • 2010-10-02
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    • 2015-03-21
    • 1970-01-01
    • 2011-01-21
    相关资源
    最近更新 更多