// // Program.cs // // Author: // Michael Becker // // Copyright (c) 2019 // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . using System; using System.Text; using UniversalEditor.ObjectModels.Text.Formatted.Items; namespace UniversalEditor.ConsoleApplication { class MainClass { public static void Main(string[] args) { if (args.Length > 0) { if (args[0] == "--generate-associations") { string assocs = null; if (args.Length > 1) { if (args[1] == "--reg") { assocs = GenerateAssociationsREG(); } } if (assocs == null) assocs = GenerateAssociations(); Console.WriteLine(assocs); } else if (args[0] == "--update-associations") { if (System.Environment.OSVersion.Platform == PlatformID.Unix) { string filename = "/usr/share/mime/packages/universal-editor.xml"; string assocs = GenerateAssociations(); try { System.IO.File.WriteAllText(filename, assocs); System.Diagnostics.Process.Start("update-mime-database", "/usr/share/mime"); System.Environment.Exit(0); } catch (UnauthorizedAccessException ex) { Console.WriteLine("ue: {0}: Permission denied", filename); System.Environment.Exit(1); } } else if (System.Environment.OSVersion.Platform == PlatformID.Win32NT) { } } else if (args[0] == "--list-associations") { // wake up the UE DataFormatReference[] dfrs = UniversalEditor.Common.Reflection.GetAvailableDataFormats(); Association[] assocs = Association.GetAllAssociations(); foreach (Association assoc in assocs) { Console.WriteLine(assoc.ToString()); } return; } else if (args[0] == "--list-dataformats") { DataFormatReference[] dfrs = UniversalEditor.Common.Reflection.GetAvailableDataFormats(); foreach (DataFormatReference dfr in dfrs) { Console.WriteLine(dfr.ToString()); } return; } else if (args[0] == "--find-checksum") { if (args.Length > 0) { Console.WriteLine("looking for {0}", args[1]); Checksum.Modules.Adler32.Adler32 adlr = new Checksum.Modules.Adler32.Adler32(); string[] files = new string[args.Length - 2]; for (int i = 2; i "); sb.AppendLine(""); DataFormatReference[] dfrs = UniversalEditor.Common.Reflection.GetAvailableDataFormats(); Association[] assocs = Association.GetAllAssociations(); for (int i = 0; i < assocs.Length; i++) { for (int j = 0; j < assocs[i].Filters.Count; j++) { string mimetype = String.Format("application/x-universaleditor-a{0}f{1}", i, j); if (assocs[i].Filters[j].ContentType != null) { mimetype = assocs[i].Filters[j].ContentType; } sb.AppendLine(String.Format("\t", mimetype)); sb.AppendLine(String.Format("\t\t{0}", assocs[i].Filters[j].Title)); // Console.Write("registering '{0}' extensions... ", assocs[i].Filters[j].Title); for (int k = 0; k < assocs[i].Filters[j].FileNameFilters.Count; k++) { sb.AppendLine(String.Format("\t\t", assocs[i].Filters[j].FileNameFilters[k])); } sb.AppendLine("\t"); } } sb.Append(""); return sb.ToString(); } private static string GenerateAssociationsREG() { StringBuilder sb = new StringBuilder(); sb.AppendLine("Windows Registry Editor Version 5.00"); DataFormatReference[] dfrs = UniversalEditor.Common.Reflection.GetAvailableDataFormats(); Association[] assocs = Association.GetAllAssociations(); for (int i = 0; i < assocs.Length; i++) { for (int j = 0; j < assocs[i].Filters.Count; j++) { for (int k = 0; k < assocs[i].Filters[j].FileNameFilters.Count; k++) { string ext = assocs[i].Filters[j].FileNameFilters[k]; if (ext.StartsWith("*.")) { ext = ext.Substring(1); } sb.AppendLine(String.Format("[HKEY_CLASSES_ROOT\\{0}{1}]", "UniversalEditor", ext)); sb.AppendLine(String.Format("[HKEY_CLASSES_ROOT\\{0}{1}\\DefaultIcon]", "UniversalEditor", ext)); sb.AppendLine("@=\"universal-editor.ico\""); sb.AppendLine(String.Format("[HKEY_CLASSES_ROOT\\{0}{1}\\Shell\\Open\\command]", "UniversalEditor", ext)); sb.AppendLine("@=UniversalEditor.exe \"%1\""); sb.AppendLine(String.Format("[HKEY_CLASSES_ROOT\\{0}]", ext)); sb.AppendLine(String.Format("@=\"{0}{1}\"", "UniversalEditor", ext)); } } } return sb.ToString(); } } }