如何使生成的设计的.Net应用程序设置便携式应用程序、Net

2023-09-02 02:01:14 作者:暖风撩人醉

我一直在寻找改变的多普勒播客聚合源与目标能够直接从我的MP3播放器上运行的程序。

I've been looking at modifying the source of the Doppler podcast aggregator with the goal of being able to run the program directly from my mp3 player.

多普勒存储应用程序设置的设置类,默认序列化用户设置用户的主目录。我想改变这种做法,所有的设置将存储在同一目录下的EXE。

Doppler stores application settings using a Visual Studio designer generated Settings class, which by default serializes user settings to the user's home directory. I'd like to change this so that all settings would be stored in the same directory as the exe.

看来,这将有可能通过创建继承的 SettingsProvider 类。有没有人创造了这样一个供应商,并想与大家分享code?

It seems that this would be possible by creating a custom provider class which inherits the SettingsProvider class. Has anyone created such a provider and would like to share code?

更新:我是能够得到一个自定义设置提供的近的使用此的 MSDN样本,即用简单的继承。我最初是困惑,Windows窗体设计器停止工作,直到我在做的 $ C $的CProject :

Update: I was able to get a custom settings provider nearly working by using this MSDN sample, i.e. with simple inheritance. I was initially confused as Windows Forms designer stopped working until I did this trick suggested at Codeproject:

internal sealed partial class Settings
{
    private MySettingsProvider settingsprovider = new MySettingsProvider();

    public Settings()
    {
        foreach (SettingsProperty property in this.Properties)
        {
            property.Provider = settingsprovider;
        }
    ...

程序还是​​始于窗口大小为0。0虽然

The program still starts with window size 0;0 though.

任何人只要有任何见解呢?

Anyone with any insight to this?

为什么需要assing在运行时的提供者---而不是使用的建议由MSDN属性? 为什么改变了默认设置被传递到使用默认设置提供对自定义一个应用程序?

推荐答案

为什么不使用$ C $的CProject PortableSettingsProvider解决方案是(有一些小的变化)? 我已经在我的项目(​​ StreamRecorder.NET )成功这样做。

Why not use the CodeProject PortableSettingsProvider solution as is (with a few minor changes) ? I have done so in my project (StreamRecorder.NET) with success.

该项目的页面上的一些意见是有用的:

Some comments on the project's page were useful:

http://www.$c$cproject.com/Messages/2934144/Fixed-csharp-version.aspx http://www.$c$cproject.com/Messages/3285411/Re-Win-Form-Designer-breaking-with-custom-Settings.aspx http://www.codeproject.com/Messages/2934144/Fixed-csharp-version.aspx http://www.codeproject.com/Messages/3285411/Re-Win-Form-Designer-breaking-with-custom-Settings.aspx

而code我结束了:

    static void Main(string[] args)
    {
        if (args.Contains("-p") || args.Contains("--portable"))
        {
            MakePortable(Properties.Settings.Default);
            MakePortable(Properties.LastUsedSettings.Default);
            MakePortable(Properties.DefaultSettings.Default);
        }
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new MainForm(args));
    }

    private static void MakePortable(ApplicationSettingsBase settings)
    {
        var portableSettingsProvider = 
            new PortableSettingsProvider(settings.GetType().Name + ".settings");
        settings.Providers.Add(portableSettingsProvider);
        foreach (System.Configuration.SettingsProperty prop in settings.Properties)
            prop.Provider = portableSettingsProvider;
        settings.Reload();
    }

最后我做了这些改变对CP项目:

Lastly I made these changes to the CP project:

string _fileName;
public PortableSettingsProvider(string fileName)
{
    _fileName = fileName;
}

public virtual string GetAppSettingsFilename()
{
    //Used to determine the filename to store the settings
    //return ApplicationName + ".settings";
    return _fileName;
}