コード例 #1
0
 public static string ReadEmbededSource(string file)
 {
     try {
         using (var fs = AlternativeDataStream.ReadAlternativeDataStream(file, ADSName))
             using (var sr = new StreamReader(fs, Encoding.UTF8)) {
                 return(sr.ReadToEnd());
             }
     }
     catch (Exception) { }
     try {
         var ext = Path.GetExtension(file).ToLower();
         if (ExtraRead.ContainsKey(ext))
         {
             var s = ExtraRead[ext](file);
             if (s != null)
             {
                 return(s);
             }
         }
     }
     catch (Exception) { }
     try { return(ReadAppleDouble(file)); }
     catch (Exception) { }
     return(null);
 }
コード例 #2
0
        public static void EmbedSource(string file, string text)
        {
            // 拡張子毎の処理(あれば)
            var ext = Path.GetExtension(file);

            if (ExtraEmbed.ContainsKey(ext))
            {
                try { ExtraEmbed[ext](file, text); }
                catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Data); }
            }

            // Alternative Data Streamにソースを書き込む
            try {
                using (var fs = AlternativeDataStream.WriteAlternativeDataStream(file, ADSName))
                    using (var ws = new StreamWriter(fs, new UTF8Encoding(false))) {
                        ws.Write(text);
                    }
            }
            // 例外は無視
            catch (IOException e) { System.Diagnostics.Debug.WriteLine(e.Data); }
            catch (NotImplementedException e) { System.Diagnostics.Debug.WriteLine(e.Data); }
        }