mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-12-15 00:55:49 +08:00
<chore>
This commit is contained in:
@@ -1,16 +1,27 @@
|
||||
#r "nuget: Newtonsoft.Json, 13.0.0"
|
||||
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
var path = Directory.GetFiles(@".idea", "workspace.xml", SearchOption.AllDirectories).First();
|
||||
const string findStr = """
|
||||
"keyToString": {
|
||||
""";
|
||||
const string replaceStr = """
|
||||
"keyToString": {
|
||||
"rider.code.cleanup.on.save": "true",
|
||||
""";
|
||||
var content = File.ReadAllText(path);
|
||||
if(content.Contains("rider.code.cleanup.on.save")){
|
||||
Console.WriteLine("alreay added");
|
||||
return;
|
||||
}
|
||||
content = content.Replace(findStr, replaceStr);
|
||||
Console.WriteLine(content);
|
||||
File.WriteAllText(path, content);
|
||||
XmlDocument xdoc = new XmlDocument();
|
||||
using(var fs = File.Open(path, FileMode.Open)){
|
||||
xdoc.Load(fs);
|
||||
fs.Seek(0, SeekOrigin.Begin);
|
||||
var propertiesComponent = xdoc.SelectSingleNode("""//component[@name="PropertiesComponent"]""");
|
||||
var jsonStr = propertiesComponent.InnerText;
|
||||
var jsonObj = JObject.Parse(jsonStr);
|
||||
var keyToStringObj = jsonObj["keyToString"] as JObject;
|
||||
if (keyToStringObj.ContainsKey("rider.code.cleanup.on.save")) return;
|
||||
|
||||
keyToStringObj.Add(new JProperty("rider.code.cleanup.on.save", "true"));
|
||||
var newNode = xdoc.CreateCDataSection(jsonObj.ToString());
|
||||
propertiesComponent.InnerText=string.Empty;
|
||||
propertiesComponent.AppendChild(newNode);
|
||||
var settings = new XmlWriterSettings { Indent = true };
|
||||
using(var writer = XmlWriter.Create(fs, settings)){
|
||||
xdoc.WriteTo(writer);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user