readconfigcommon.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. function SaveConfigToServer(_domainname){
  2. // leere Zeilen am Ende löschen
  3. var zw = config_split.length - 1;
  4. while (config_split[zw] == "") {
  5. config_split.pop();
  6. }
  7. var config_gesamt = "";
  8. for (var i = 0; i < config_split.length; ++i)
  9. {
  10. config_gesamt = config_gesamt + config_split[i] + "\n";
  11. }
  12. FileDeleteOnServer("/config/config.ini", _domainname);
  13. FileSendContent(config_gesamt, "/config/config.ini", _domainname);
  14. }
  15. function UpdateConfig(zw, _index, _enhance, _domainname){
  16. var namezw = zw["name"];
  17. FileCopyOnServer("/img_tmp/ref_zw.jpg", namezw, _domainname);
  18. var namezw = zw["name"].replace(".jpg", "_org.jpg");
  19. FileCopyOnServer("/img_tmp/ref_zw_org.jpg", namezw, _domainname);
  20. }
  21. function createReader(file) {
  22. var image = new Image();
  23. reader.onload = function(evt) {
  24. var image = new Image();
  25. image.onload = function(evt) {
  26. var width = this.width;
  27. var height = this.height;
  28. };
  29. image.src = evt.target.result;
  30. };
  31. reader.readAsDataURL(file);
  32. }
  33. function ZerlegeZeile(input, delimiter = " =\t\r") {
  34. var Output = Array(0);
  35. // delimiter = " =,\t";
  36. /* The input can have multiple formats:
  37. * - key = value
  38. * - key = value1 value2 value3 ...
  39. * - key value1 value2 value3 ...
  40. *
  41. * Examples:
  42. * - ImageSize = VGA
  43. * - IO0 = input disabled 10 false false
  44. * - main.dig1 28 144 55 100 false
  45. *
  46. * This causes issues eg. if a password key has a whitespace or equal sign in its value.
  47. * As a workaround and to not break any legacy usage, we enforce to only use the
  48. * equal sign, if the key is "password"
  49. */
  50. if (input.includes("password") || input.includes("Token")) { // Line contains a password, use the equal sign as the only delimiter and only split on first occurrence
  51. var pos = input.indexOf("=");
  52. delimiter = " \t\r"
  53. Output.push(trim(input.substr(0, pos), delimiter));
  54. Output.push(trim(input.substr(pos +1, input.length), delimiter));
  55. }
  56. else { // Legacy Mode
  57. input = trim(input, delimiter);
  58. var pos = findDelimiterPos(input, delimiter);
  59. var token;
  60. while (pos > -1) {
  61. token = input.substr(0, pos);
  62. token = trim(token, delimiter);
  63. Output.push(token);
  64. input = input.substr(pos+1, input.length);
  65. input = trim(input, delimiter);
  66. pos = findDelimiterPos(input, delimiter);
  67. }
  68. Output.push(input);
  69. }
  70. return Output;
  71. }
  72. function findDelimiterPos(input, delimiter) {
  73. var pos = -1;
  74. var zw;
  75. var akt_del;
  76. for (var anz = 0; anz < delimiter.length; ++anz) {
  77. akt_del = delimiter[anz];
  78. zw = input.indexOf(akt_del);
  79. if (zw > -1) {
  80. if (pos > -1) {
  81. if (zw < pos) {
  82. pos = zw;
  83. }
  84. }
  85. else {
  86. pos = zw;
  87. }
  88. }
  89. }
  90. return pos;
  91. }
  92. function trim(istring, adddelimiter) {
  93. while ((istring.length > 0) && (adddelimiter.indexOf(istring[0]) >= 0)) {
  94. istring = istring.substr(1, istring.length-1);
  95. }
  96. while ((istring.length > 0) && (adddelimiter.indexOf(istring[istring.length-1]) >= 0)) {
  97. istring = istring.substr(0, istring.length-1);
  98. }
  99. return istring;
  100. }
  101. function getConfig() {
  102. return config_gesamt;
  103. }
  104. function loadConfig(_domainname) {
  105. var xhttp = new XMLHttpRequest();
  106. try {
  107. url = _domainname + '/fileserver/config/config.ini';
  108. xhttp.open("GET", url, false);
  109. xhttp.send();
  110. config_gesamt = xhttp.responseText;
  111. config_gesamt = config_gesamt.replace("InitalRotate", "InitialRotate"); // Korrigiere Schreibfehler in config.ini !!!!!
  112. } catch (error) {}
  113. return true;
  114. }
  115. function dataURLtoBlob(dataurl) {
  116. var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
  117. bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
  118. while(n--){
  119. u8arr[n] = bstr.charCodeAt(n);
  120. }
  121. return new Blob([u8arr], {type:mime});
  122. }
  123. function FileCopyOnServer(_source, _target, _domainname = "") {
  124. url = _domainname + "/editflow?task=copy&in=" + _source + "&out=" + _target;
  125. var xhttp = new XMLHttpRequest();
  126. try {
  127. xhttp.open("GET", url, false);
  128. xhttp.send();
  129. } catch (error) {}
  130. }
  131. function FileDeleteOnServer(_filename, _domainname = "") {
  132. var xhttp = new XMLHttpRequest();
  133. var okay = false;
  134. xhttp.onreadystatechange = function() {
  135. if (xhttp.readyState == 4) {
  136. if (xhttp.status == 200) {
  137. okay = true;
  138. }
  139. else if (xhttp.status == 0) {
  140. // firework.launch('Server closed the connection abruptly!', 'danger', 30000);
  141. // location.reload()
  142. }
  143. else {
  144. // firework.launch('An error occured: ' + xhttp.responseText, 'danger', 30000);
  145. // location.reload()
  146. }
  147. }
  148. };
  149. try {
  150. var url = _domainname + "/delete" + _filename;
  151. xhttp.open("POST", url, false);
  152. xhttp.send();
  153. } catch (error) {}
  154. return okay;
  155. }
  156. function FileSendContent(_content, _filename, _domainname = "") {
  157. var xhttp = new XMLHttpRequest();
  158. var okay = false;
  159. xhttp.onreadystatechange = function() {
  160. if (xhttp.readyState == 4) {
  161. if (xhttp.status == 200) {
  162. okay = true;
  163. }
  164. else if (xhttp.status == 0) {
  165. firework.launch('Server closed the connection abruptly!', 'danger', 30000);
  166. }
  167. else {
  168. firework.launch('An error occured: ' + xhttp.responseText, 'danger', 30000);
  169. }
  170. }
  171. };
  172. try {
  173. upload_path = _domainname + "/upload" + _filename;
  174. xhttp.open("POST", upload_path, false);
  175. xhttp.send(_content);
  176. } catch (error) {}
  177. return okay;
  178. }
  179. function MakeRefImageZW(zw, _enhance, _domainname){
  180. var _filename = zw["name"].replace("/config/", "/img_tmp/");
  181. var url = _domainname + "/editflow?task=cutref&in=/config/reference.jpg&out=" + _filename + "&x=" + zw["x"] + "&y=" + zw["y"] + "&dx=" + zw["dx"] + "&dy=" + zw["dy"];
  182. if (_enhance == true){
  183. url = url + "&enhance=true";
  184. }
  185. var xhttp = new XMLHttpRequest();
  186. try {
  187. xhttp.open("GET", url, false);
  188. xhttp.send();
  189. } catch (error){}
  190. if (xhttp.responseText == "CutImage Done") {
  191. if (_enhance == true) {
  192. firework.launch('Image Contrast got enhanced', 'success', 5000);
  193. }
  194. else {
  195. firework.launch('Alignment Marker have been updated', 'success', 5000);
  196. }
  197. return true;
  198. }
  199. else {
  200. return false;
  201. }
  202. }