Files
VisualSapfor/src/_VisualDVM/GlobalData/Compiler/UI/CompilerDialog.java

87 lines
4.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package _VisualDVM.GlobalData.Compiler.UI;
import Common.Utils.Utils_;
import Common.Visual.UI;
import Common.Visual.Windows.Dialog.DBObjectDialog;
import _VisualDVM.Global;
import _VisualDVM.GlobalData.Compiler.Compiler;
import _VisualDVM.GlobalData.Compiler.CompilerType;
import _VisualDVM.Utils;
import _VisualDVM.Validators.PathValidator;
public class CompilerDialog extends DBObjectDialog<Compiler, CompilerFields> {
public CompilerDialog() {
super(CompilerFields.class);
}
@Override
public int getDefaultHeight() {
return 300;
}
@Override
public void validateFields() {
//<editor-fold desc="расположение">
String home = fields.tfHome.getText();
if (!home.isEmpty()) {
if (home.startsWith("/")) {
if (Utils_.ContainsCyrillic(home))
Log.Writeln("Расположение компилятора не может содержать кириллицу");
else {
new PathValidator(home, "Расположение компилятора", Log).Validate();
}
} else
Log.Writeln("Расположение компилятора может быть либо пустой строкой, либо путём к файлу");
}
//</editor-fold>
//<editor-fold desc="команда вызова">
String call_command = fields.tfCallCommand.getText();
if (call_command.isEmpty())
Log.Writeln("Команда вызова компилятора не может быть пустой");
else if (Utils_.ContainsCyrillic(call_command))
Log.Writeln("Команда вызова компилятора не может содержать кириллицу");
else {
switch (call_command.charAt(0)) {
case ' ':
Log.Writeln("Команда вызова компилятора не может начинаться с пробела.");
break;
case '/':
if (call_command.endsWith("/"))
Log.Writeln("Каталог не может быть указан в качестве команды.");
else
new PathValidator(call_command, "Команда вызова компилятора", Log).Validate();
break;
default:
//это команда.
//самое опасное место. теоретически тут можно ввести любую команду ОС, в том числе rm -rf
if (call_command.contains(" "))
Log.Writeln("Прямая команда вызова не может содержать пробелы");
if (!call_command.contains("+") && Utils_.ContainsForbiddenName(call_command))
Log.Writeln("Прямая команда вызова содержит запрещённые символы");
else {
if (Utils.isLinuxSystemCommand(call_command))
Log.Writeln(Utils_.DQuotes(call_command) + " является системной командой Linux");
}
break;
}
}
//</editor-fold>
}
@Override
public void fillFields() {
fields.tfDescription.setText(Result.description);
fields.tfCallCommand.setText(Result.call_command);
fields.tfHelpCommand.setText(Result.help_command);
fields.tfVersionCommand.setText(Result.version_command);
fields.tfHome.setText(Result.home_path);
UI.TrySelect(fields.cbCompilerType, Result.type);
fields.events_on = true;
}
@Override
public void ProcessResult() {
Result.machine_id = Global.mainModule.getMachine().id;
Result.description = fields.tfDescription.getText();
Result.call_command = fields.tfCallCommand.getText();
Result.help_command = fields.tfHelpCommand.getText();
Result.version_command = fields.tfVersionCommand.getText();
Result.home_path = fields.tfHome.getText();
Result.type = (CompilerType) fields.cbCompilerType.getSelectedItem();
}
}