C# 如何使用C读取dconf设置
我正在用MonoDevelop开发一个ubuntu unity应用程序 如何使用C读取dconf设置 我可以使用C访问GSettings吗 我实际需要的是key/org/gnome/desktop/interface/font name的值 更新 我的快速技巧如下:C# 如何使用C读取dconf设置,c#,mono,gtk,gnome,C#,Mono,Gtk,Gnome,我正在用MonoDevelop开发一个ubuntu unity应用程序 如何使用C读取dconf设置 我可以使用C访问GSettings吗 我实际需要的是key/org/gnome/desktop/interface/font name的值 更新 我的快速技巧如下: private string GetFontName() { string font = "Ubuntu 11"; Process p = new Process { StartInfo = new
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[]{'\''});
}
我从不使用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();
}
}
}
好吧,如果dconf文件的格式是文本,这就可以了。这些文件不是简单的文本文件,所以这个答案对OP不起作用。你不应该绑定到GSettings吗?@rene。你是对的。如上所述:大多数应用程序不希望直接与dconf接口,而是希望与GSettings接口。如果有区别,可以使用GLib.Settings类与GSettings API类似,GSettings API是GTK3中gio-sharp.dll的一部分。GTK3为我破坏东西,这就是为什么我会坚持你的黑客。