2014-03-01 30 views
1

我正在使用MonoDevelop開發ubuntu統一應用程序。如何使用C#讀取dconf設置

我如何讀取dconf使用C#設置?

我可以使用C#訪問GSettings嗎?

我真正需要的是關鍵/org/gnome/desktop/interface/font-name的價值。

更新

我的快速破解如下:

private string GetFontName() 
{ 
    string font = "Ubuntu 11"; 

    Process p = new Process { 
     StartInfo = new ProcessStartInfo { 
      FileName = "gsettings", 
      Arguments = "get org.gnome.desktop.interface font-name", 
      UseShellExecute = false, 
      RedirectStandardOutput = true, 
      CreateNoWindow = true 
     } 
    }; 

    p.Start(); 

    while (!p.StandardOutput.EndOfStream) 
     font = p.StandardOutput.ReadLine(); 

    p.WaitForExit(); 

    return font.Trim(new char[]{'\''}); 
} 
+0

你不應該綁定到GSettings呢? – rene

+0

@rene。你是對的。正如[此處](https://wiki.gnome.org/Projects/dconf)所述:「**大多數應用程序不會直接與dconf連接,而是與GSettings。**」 – sergej

+1

如果它有所作爲,您可以使用GTK#3中'gio-sharp.dll'的一部分'GLib.Settings'類(類似於GSettings API)。 GTK#3爲我打破了東西,這就是爲什麼我會堅持你的破解。 – EvilTak

回答

-4

我從來沒有與Ubuntu和Mono工作。 我想下面的頌歌可能會幫助你。

using System; 
using System.IO; 

namespace FileAccess 
{ 
    class MainClass 
    { 
     public static void Main (string[] args) 
     { 
      string FileName="TestFile.txt"; 

      // Open the file into a StreamReader 
      StreamReader file = File.OpenText(FileName); 
      // Read the file into a string 
      string s = file.ReadToEnd(); 
      // Close the file so it can be accessed again. 
      file.Close(); 

      // Add a line to the text 
      s += "A new line.\n"; 

      // Hook a write to the text file. 
      StreamWriter writer = new StreamWriter(FileName); 
      // Rewrite the entire value of s to the file 
      writer.Write(s); 

      // Add a single line 
      writer.WriteLine("Add a single line."); 

      // Close the writer 
      writer.Close(); 
     } 
    } 
} 
+0

那麼,如果一個dconf文件的格式是文本,這可以工作。這些文件不是簡單的文本文件,所以這個答案不適用於OP。 – rene