1 //this file is part of notepad++ 2 //Copyright (C)2003 Don HO <donho@altern.org> 3 // 4 //This program is free software; you can redistribute it and/or 5 //modify it under the terms of the GNU General Public License 6 //as published by the Free Software Foundation; either 7 //version 2 of the License, or (at your option) any later version. 8 // 9 //This program is distributed in the hope that it will be useful, 10 //but WITHOUT ANY WARRANTY; without even the implied warranty of 11 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 //GNU General Public License for more details. 13 // 14 //You should have received a copy of the GNU General Public License 15 //along with this program; if not, write to the Free Software 16 //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 /** 18 * 19 * 20 * See_Also: 21 * https://github.com/notepad-plus-plus/nppPluginList 22 * 23 * Author: dokutoku, https://twitter.com/dokutoku3 24 * License: GPL-2.0 or later 25 */ 26 module npp_api.pluginfunc.export_info; 27 28 29 version (Not_betterC): 30 31 private static import std.array; 32 private static import std.ascii; 33 private static import std.digest; 34 private static import std.digest.sha; 35 private static import std.file; 36 private static import std.json; 37 38 private enum string[] key_names = 39 [ 40 `folder-name`, 41 `display-name`, 42 `version`, 43 `id`, 44 `repository`, 45 `description`, 46 `author`, 47 `homepage`, 48 ]; 49 50 /** 51 * 52 */ 53 struct npp_plugin_info_item 54 { 55 /** 56 * plugin folder name 57 */ 58 string folder_name; 59 60 /** 61 * plugin display name 62 */ 63 string display_name; 64 65 /** 66 * plugin veresion 67 */ 68 string version_; 69 70 /** 71 * SHA-256 zip file hash 72 */ 73 string id; 74 75 /** 76 * plugin zip file uri 77 */ 78 string repository; 79 80 /** 81 * plugin description 82 */ 83 string description; 84 85 /** 86 * plugin author 87 */ 88 string author; 89 90 /** 91 * plugin project page URI 92 */ 93 string homepage; 94 95 void update_id(string input_file) 96 97 do 98 { 99 if (!std.file.exists(input_file) || !std.file.isFile(input_file)) { 100 throw new Exception(`Unknown input file.`); 101 } 102 103 this.id = std.digest.toHexString!(std.ascii.LetterCase.lower)(std.digest.sha.sha256Of(std.file.read(input_file))).idup; 104 } 105 106 @disable 107 void update_json(std.json.JSONValue input) 108 109 do 110 { 111 /+ 112 foreach (item_value; this.tupleof) { 113 } 114 +/ 115 } 116 117 string export_json() 118 119 in 120 { 121 static assert(key_names.length == this.tupleof.length); 122 } 123 124 do 125 { 126 auto output = std.array.appender!(string); 127 128 output.put("\t\t"); 129 output.put(`{`); 130 output.put("\n"); 131 132 size_t i = 0; 133 134 foreach (item_value; this.tupleof) { 135 std.json.JSONValue json_value = item_value; 136 output.put("\t\t\t"); 137 output.put(`"`); 138 output.put(key_names[i]); 139 output.put(`": `); 140 output.put(std.json.toJSON(json_value, false, std.json.JSONOptions.escapeNonAsciiChars | std.json.JSONOptions.doNotEscapeSlashes)); 141 output.put((i != (this.tupleof.length - 1)) ? (",\n") : ("\n")); 142 i++; 143 } 144 145 output.put("\t\t"); 146 output.put(`}`); 147 output.put(`,`); 148 output.put("\n"); 149 150 return output.data().idup; 151 } 152 } 153 154 155 string create_plugin_list_json(A...)(A a) 156 157 in 158 { 159 foreach (item; a) { 160 static assert(is(typeof(item) : string)); 161 } 162 } 163 164 do 165 { 166 auto output = std.array.appender!(string); 167 168 output.put(`{`); 169 output.put("\n"); 170 171 output.put("\t"); 172 output.put(`"npp-plugins": [`); 173 output.put("\n"); 174 175 foreach (item; a) { 176 output.put(item); 177 } 178 179 180 output.put("\t"); 181 output.put(`]`); 182 output.put("\n"); 183 184 output.put(`}`); 185 output.put("\n"); 186 187 188 return output.data().idup; 189 }