no message
This commit is contained in:
@@ -17,9 +17,6 @@ import javafx.util.Pair;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
@@ -29,8 +26,6 @@ import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.*;
|
||||
import java.security.MessageDigest;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Semaphore;
|
||||
@@ -44,27 +39,6 @@ public class Utils {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static boolean ContainsForbiddenName(String string) {
|
||||
char[] chars = string.toCharArray();
|
||||
for (char c : chars)
|
||||
if (isForbidden(c)) return true;
|
||||
return false;
|
||||
}
|
||||
public static boolean isForbidden(char c) {
|
||||
for (char f : Constants.forbidden_file_name_characters)
|
||||
if (c == f) return true;
|
||||
return false;
|
||||
}
|
||||
public static String ReplaceForbiddenSymbols(String name) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (char c : name.toCharArray())
|
||||
res.append(isForbidden(c) ? '_' : c);
|
||||
return res.toString();
|
||||
}
|
||||
public static void init() {
|
||||
for (char f : Constants.forbidden_file_name_characters)
|
||||
Constants.all_forbidden_characters_string += f + " ";
|
||||
}
|
||||
public static String MFVar(Object o) {
|
||||
return "$(" + o.toString() + ")";
|
||||
}
|
||||
@@ -73,7 +47,7 @@ public class Utils {
|
||||
try {
|
||||
FileUtils.forceMkdir(dir);
|
||||
} catch (Exception e) {
|
||||
Global.Log.PrintException(e);
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,14 +59,14 @@ public class Utils {
|
||||
try {
|
||||
forceDeleteWithCheck(f);
|
||||
} catch (Exception e) {
|
||||
Global.Log.PrintException(e);
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
FileUtils.forceMkdir(dir);
|
||||
} catch (Exception e) {
|
||||
Global.Log.PrintException(e);
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,7 +77,7 @@ public class Utils {
|
||||
try {
|
||||
return new String(Files.readAllBytes(file.toPath()));
|
||||
} catch (Exception e) {
|
||||
Global.Log.PrintException(e);
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -115,7 +89,7 @@ public class Utils {
|
||||
try {
|
||||
forceDeleteWithCheck(f);
|
||||
} catch (Exception e) {
|
||||
Global.Log.PrintException(e);
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,11 +142,6 @@ public class Utils {
|
||||
getFilesCountR(dir, res);
|
||||
return res.getValue();
|
||||
}
|
||||
public static String print_date(Date date) {
|
||||
String pattern = "dd.MM.yyyy HH:mm:ss";
|
||||
DateFormat df = new SimpleDateFormat(pattern);
|
||||
return df.format(date);
|
||||
}
|
||||
public static File CreateTempResourceFile(String res_name) throws Exception {
|
||||
URL u = (Utils.class.getResource("/files/" + res_name));
|
||||
InputStream i = u.openStream();
|
||||
@@ -203,7 +172,7 @@ public class Utils {
|
||||
return getTempFileName(name, "");
|
||||
}
|
||||
public static boolean isAnchestor(File child, File anchestor) {
|
||||
return child.getAbsolutePath().startsWith(anchestor.getAbsolutePath() + (Global.isWindows ? "\\" : "/"));
|
||||
return child.getAbsolutePath().startsWith(anchestor.getAbsolutePath() + (CommonUtils.isWindows ? "\\" : "/"));
|
||||
}
|
||||
//при условии что это точно его предок
|
||||
public static String getRelativeAddress(File file, File anchestor) {
|
||||
@@ -220,8 +189,8 @@ public class Utils {
|
||||
Log.Writeln_("Имя файла не может содержать кириллицу");
|
||||
res = false;
|
||||
}
|
||||
if (ContainsForbiddenName(name)) {
|
||||
Log.Writeln_("Имя файла не может содержать запрещённых символов\n" + Constants.all_forbidden_characters_string);
|
||||
if (CommonUtils.ContainsForbiddenName(name)) {
|
||||
Log.Writeln_("Имя файла не может содержать запрещённых символов\n" + CommonUtils.printAllForbiddenCharacters());
|
||||
res = false;
|
||||
}
|
||||
return res;
|
||||
@@ -230,7 +199,7 @@ public class Utils {
|
||||
//идет по всем уровням файлов
|
||||
public static boolean validateProjectFile(File file, TextLog Log) {
|
||||
String name = file.getName();
|
||||
if (CommonUtils.ContainsCyrillic(name) || ContainsForbiddenName(name)) {
|
||||
if (CommonUtils.ContainsCyrillic(name) || CommonUtils.ContainsForbiddenName(name)) {
|
||||
Log.Writeln_(file.getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
@@ -253,29 +222,11 @@ public class Utils {
|
||||
validateProjectFolder_r(dir, files_list);
|
||||
if (!files_list.isEmpty())
|
||||
Log.Writeln_("Имена " + filesLines.length + " файлов/подпапок содержат запрещённые символы " +
|
||||
Constants.all_forbidden_characters_string +
|
||||
CommonUtils.printAllForbiddenCharacters() +
|
||||
"или кириллицу");
|
||||
//нужно проверить корень на наличие хоть одной программы.
|
||||
return Log.isEmpty();
|
||||
}
|
||||
public static void CopyToClipboard(String text) {
|
||||
Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard()
|
||||
.setContents(
|
||||
new StringSelection(text),
|
||||
null
|
||||
);
|
||||
}
|
||||
public static String getFromClipboard() {
|
||||
String res = "";
|
||||
try {
|
||||
res = (String) Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard().getData(DataFlavor.stringFlavor);
|
||||
} catch (Exception ex) {
|
||||
Global.Log.PrintException(ex);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public static void delete_with_check(File file) throws Exception {
|
||||
int attempts = 0;
|
||||
while (attempts < 10) {
|
||||
@@ -315,7 +266,7 @@ public class Utils {
|
||||
} catch (Exception e) {
|
||||
// тут можно обработать ошибку
|
||||
// возникает она если в передаваемый алгоритм в getInstance(,,,) не существует
|
||||
Global.Log.PrintException(e);
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
BigInteger bigInt = new BigInteger(1, digest);
|
||||
String md5Hex = bigInt.toString(16);
|
||||
@@ -346,21 +297,12 @@ public class Utils {
|
||||
} else return;
|
||||
if (file.exists()) {
|
||||
attempts++;
|
||||
Global.Log.Print("неудачная попытка удаления: файл " + CommonUtils.Brackets(file.getAbsolutePath()) + " занят");
|
||||
CommonUtils.MainLog.Print("неудачная попытка удаления: файл " + CommonUtils.Brackets(file.getAbsolutePath()) + " занят");
|
||||
Thread.sleep(2000);
|
||||
} else return;
|
||||
}
|
||||
throw new PassException("Не удалось удалить файл " + CommonUtils.Brackets(file.getAbsolutePath()) + " за " + attempts + " попыток");
|
||||
}
|
||||
public static byte[] packFile(File src) throws Exception {
|
||||
byte[] dst = Files.readAllBytes(src.toPath());
|
||||
return dst;
|
||||
}
|
||||
public static void unpackFile(byte[] bytes, File dst) throws Exception {
|
||||
FileOutputStream os = new FileOutputStream(dst);
|
||||
os.write(bytes);
|
||||
os.close();
|
||||
}
|
||||
public static Socket createClientSocket(InetAddress address, int port, int timeout) throws Exception {
|
||||
Socket socket = new Socket();
|
||||
socket.setSoTimeout(timeout);
|
||||
@@ -372,19 +314,6 @@ public class Utils {
|
||||
InputStream i = u.openStream();
|
||||
Files.copy(i, dst.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
public static boolean validateEmail(String address, TextLog log) {
|
||||
Matcher matcher = Constants.VALID_EMAIL_ADDRESS_REGEX.matcher(address);
|
||||
if (!matcher.find()) {
|
||||
log.Writeln_("введённый адрес электронной почты некорректен.");
|
||||
return false;
|
||||
}
|
||||
String match = address.substring(matcher.start(), matcher.end());
|
||||
if (!match.equals(address)) {
|
||||
log.Writeln_("введённый адрес электронной почты некорректен.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static void getFilesByExtensions_r(File dir, Vector<File> res, String... extensions) {
|
||||
File[] files = dir.listFiles();
|
||||
if (files != null) {
|
||||
@@ -430,7 +359,7 @@ public class Utils {
|
||||
}
|
||||
public static File createScript(File scriptDirectory, File targetDirectory, String name, String scriptText) throws Exception {
|
||||
//->
|
||||
File scriptFile = Paths.get(scriptDirectory.getAbsolutePath(), name + (Global.isWindows ? ".bat" : "")).toFile();
|
||||
File scriptFile = Paths.get(scriptDirectory.getAbsolutePath(), name + (CommonUtils.isWindows ? ".bat" : "")).toFile();
|
||||
FileUtils.write(scriptFile, "cd " + CommonUtils.DQuotes(targetDirectory.getAbsolutePath()) + "\n" + scriptText);
|
||||
if (!scriptFile.setExecutable(true)) throw new PassException("Не удалось создать исполняемый файл для скрипта");
|
||||
return scriptFile;
|
||||
@@ -594,23 +523,6 @@ public class Utils {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public static String strikeThrough(String s) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (char c : s.toCharArray()) {
|
||||
res.append(c);
|
||||
if (c != Constants.toStrike)
|
||||
res.append(Constants.toStrike);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
public static String noStrikeThrough(String s) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (char c : s.toCharArray()) {
|
||||
if (c != (Constants.toStrike))
|
||||
res.append(c);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
public static void addEmptyLines(Vector<String> lines, int num) {
|
||||
IntStream.range(0, num).mapToObj(i -> "").forEach(lines::add);
|
||||
}
|
||||
@@ -657,8 +569,8 @@ public class Utils {
|
||||
public static void Kill(String PID, boolean force) {
|
||||
if (!PID.isEmpty()) {
|
||||
String killCommand =
|
||||
force ? Global.isWindows ? "taskkill /PID " + CommonUtils.DQuotes(PID) + " /F /T" : "kill -9 " + CommonUtils.DQuotes(PID) :
|
||||
Global.isWindows ? "taskkill /PID " + CommonUtils.DQuotes(PID) : "kill -2 " + CommonUtils.DQuotes(PID);
|
||||
force ? CommonUtils.isWindows ? "taskkill /PID " + CommonUtils.DQuotes(PID) + " /F /T" : "kill -9 " + CommonUtils.DQuotes(PID) :
|
||||
CommonUtils.isWindows ? "taskkill /PID " + CommonUtils.DQuotes(PID) : "kill -2 " + CommonUtils.DQuotes(PID);
|
||||
System.out.println(killCommand);
|
||||
try {
|
||||
Process killer = Utils.startScript(Global.TempDirectory, Global.TempDirectory, "killer", killCommand);
|
||||
@@ -782,7 +694,7 @@ public class Utils {
|
||||
try {
|
||||
if (p != null) res = Double.parseDouble(p);
|
||||
} catch (Exception ex) {
|
||||
Global.Log.PrintException(ex);
|
||||
CommonUtils.MainLog.PrintException(ex);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user