no message
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package Common.Utils;
|
||||
import Common.CommonConstants;
|
||||
import Common.Database.VisualiserDatabase;
|
||||
import Common.Passes.PassException;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@@ -396,6 +396,52 @@ public class Utils_ {
|
||||
os.write(bytes);
|
||||
os.close();
|
||||
}
|
||||
public static void CheckDirectory(File dir) {
|
||||
if (!dir.exists()) {
|
||||
try {
|
||||
FileUtils.forceMkdir(dir);
|
||||
} catch (Exception e) {
|
||||
MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void CheckAndCleanDirectory(File dir) {
|
||||
if (dir.exists()) {
|
||||
File[] files = dir.listFiles();
|
||||
if (files != null)
|
||||
for (File f : files) {
|
||||
try {
|
||||
forceDeleteWithCheck(f);
|
||||
} catch (Exception e) {
|
||||
MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
FileUtils.forceMkdir(dir);
|
||||
} catch (Exception e) {
|
||||
MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void forceDeleteWithCheck(File file) throws Exception {
|
||||
int attempts = 0;
|
||||
while (attempts < 10) {
|
||||
if (file.exists()) {
|
||||
try {
|
||||
FileUtils.forceDelete(file);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else return;
|
||||
if (file.exists()) {
|
||||
attempts++;
|
||||
System.out.println("неудачная попытка удаления: файл " + Brackets(file.getAbsolutePath()) + " занят");
|
||||
sleep(2000);
|
||||
} else return;
|
||||
}
|
||||
throw new PassException("Не удалось удалить файл " + Brackets(file.getAbsolutePath()) + " за " + attempts + " попыток");
|
||||
}
|
||||
//Иконки
|
||||
public static ImageIcon getIcon(String path) {
|
||||
URL imageUrl = Utils_.class.getResource(path);
|
||||
|
||||
Reference in New Issue
Block a user