public static bool UpdateXmlResource(string res, string filename, Dictionary <string, string> acwMap, IEnumerable <string> additionalDirectories = null, Action <TraceLevel, string> logMessage = null, Action <string, string> registerCustomView = null) { // use a temporary file so we only update the real file if things actually changed string tmpfile = filename + ".bk"; try { XDocument doc = XDocument.Load(filename, LoadOptions.SetLineInfo); UpdateXmlResource(res, doc.Root, acwMap, additionalDirectories, logMessage, (e) => { registerCustomView?.Invoke(e, filename); }); using (var stream = File.OpenWrite(tmpfile)) using (var xw = new LinePreservedXmlWriter(new StreamWriter(stream))) xw.WriteNode(doc.CreateNavigator(), false); return(Xamarin.Android.Tasks.MonoAndroidHelper.CopyIfChanged(tmpfile, filename)); } catch (Exception e) { logMessage?.Invoke(TraceLevel.Warning, $"AndroidResgen: Warning while updating Resource XML '{filename}': {e.Message}"); return(false); } finally { if (File.Exists(tmpfile)) { File.Delete(tmpfile); } } }
public static void UpdateXmlResource(string filename, Dictionary <string, string> acwMap, IEnumerable <string> additionalDirectories = null) { // use a temporary file so we only update the real file if things actually changed string tmpfile = filename + ".bk"; try { XDocument doc = XDocument.Load(filename, LoadOptions.SetLineInfo); // The assumption here is that the file we're fixing up is in a directory below the // obj/${Configuration}/res/ directory and so appending ../gives us the actual path to // 'res/' UpdateXmlResource(Path.Combine(Path.GetDirectoryName(filename), ".."), doc.Root, acwMap, additionalDirectories); using (var stream = File.OpenWrite(tmpfile)) using (var xw = new LinePreservedXmlWriter(new StreamWriter(stream))) xw.WriteNode(doc.CreateNavigator(), false); Xamarin.Android.Tasks.MonoAndroidHelper.CopyIfChanged(tmpfile, filename); File.Delete(tmpfile); } catch (Exception e) { if (File.Exists(tmpfile)) { File.Delete(tmpfile); } Console.Error.WriteLine("AndroidResgen: Warning while updating Resource XML '{0}': {1}", filename, e.Message); return; } }
public static bool UpdateXmlResource(string res, string filename, Dictionary <string, string> acwMap, IEnumerable <string> additionalDirectories = null, Action <TraceLevel, string> logMessage = null, Action <string, string> registerCustomView = null) { try { XDocument doc = XDocument.Load(filename, LoadOptions.SetLineInfo); UpdateXmlResource(res, doc.Root, acwMap, additionalDirectories, (e) => { registerCustomView?.Invoke(e, filename); }); using (var sw = MemoryStreamPool.Shared.CreateStreamWriter()) using (var xw = new LinePreservedXmlWriter(sw)) { xw.WriteNode(doc.CreateNavigator(), false); xw.Flush(); sw.Flush(); return(MonoAndroidHelper.CopyIfStreamChanged(sw.BaseStream, filename)); } } catch (Exception e) { logMessage?.Invoke(TraceLevel.Warning, string.Format(Xamarin.Android.Tasks.Properties.Resources.XA1001, filename, e.Message)); return(false); } }
public static void UpdateXmlResource(string res, string filename, Dictionary <string, string> acwMap, IEnumerable <string> additionalDirectories = null) { // use a temporary file so we only update the real file if things actually changed string tmpfile = filename + ".bk"; try { XDocument doc = XDocument.Load(filename, LoadOptions.SetLineInfo); UpdateXmlResource(res, doc.Root, acwMap, additionalDirectories); using (var stream = File.OpenWrite(tmpfile)) using (var xw = new LinePreservedXmlWriter(new StreamWriter(stream))) xw.WriteNode(doc.CreateNavigator(), false); Xamarin.Android.Tasks.MonoAndroidHelper.CopyIfChanged(tmpfile, filename); File.Delete(tmpfile); } catch (Exception e) { if (File.Exists(tmpfile)) { File.Delete(tmpfile); } Console.Error.WriteLine("AndroidResgen: Warning while updating Resource XML '{0}': {1}", filename, e.Message); return; } }