(c0e610a99) Ugly temporary workaround to OpenFileDialog crashing on some Linux systems. If instantiating the dialog fails, a message box pops up where the user can enter the path to the file manually.
This commit is contained in:
@@ -965,34 +965,38 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
OnClicked = (btn, userdata) =>
|
OnClicked = (btn, userdata) =>
|
||||||
{
|
{
|
||||||
OpenFileDialog ofd = new OpenFileDialog()
|
try
|
||||||
{
|
{
|
||||||
InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder),
|
OpenFileDialog ofd = new OpenFileDialog()
|
||||||
Filter = TextManager.Get("WorkshopItemPreviewImage")+"|*.png",
|
{
|
||||||
Title = TextManager.Get("WorkshopItemPreviewImageDialogTitle")
|
Multiselect = true,
|
||||||
};
|
InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder),
|
||||||
if (ofd.ShowDialog() == DialogResult.OK)
|
Filter = TextManager.Get("WorkshopItemPreviewImage") + "|*.png",
|
||||||
|
Title = TextManager.Get("WorkshopItemPreviewImageDialogTitle")
|
||||||
|
};
|
||||||
|
if (ofd.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
OnPreviewImageSelected(previewIcon, ofd.FileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
{
|
{
|
||||||
string previewImagePath = Path.GetFullPath(Path.Combine(SteamManager.WorkshopItemStagingFolder, SteamManager.PreviewImageName));
|
//use a custom prompt if OpenFileDialog fails (Linux/Mac)
|
||||||
if (new FileInfo(ofd.FileName).Length > 1024 * 1024)
|
var msgBox = new GUIMessageBox(TextManager.Get("WorkshopItemPreviewImageDialogTitle"), "", relativeSize: new Vector2(0.4f, 0.2f),
|
||||||
{
|
buttons: new string[] { TextManager.Get("Cancel"), TextManager.Get("OK") });
|
||||||
new GUIMessageBox(TextManager.Get("Error"), TextManager.Get("WorkshopItemPreviewImageTooLarge"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ofd.FileName != previewImagePath)
|
var pathBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.5f), msgBox.Content.RectTransform, Anchor.Center) { MinSize = new Point(0,25) });
|
||||||
{
|
|
||||||
File.Copy(ofd.FileName, previewImagePath, overwrite: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (itemPreviewSprites.ContainsKey(previewImagePath))
|
msgBox.Buttons[0].OnClicked += msgBox.Close;
|
||||||
|
msgBox.Buttons[1].OnClicked += msgBox.Close;
|
||||||
|
msgBox.Buttons[1].OnClicked += (btn2, userdata2) =>
|
||||||
{
|
{
|
||||||
itemPreviewSprites[previewImagePath].Remove();
|
if (File.Exists(pathBox.Text))
|
||||||
}
|
{
|
||||||
var newPreviewImage = new Sprite(previewImagePath, sourceRectangle: null);
|
OnPreviewImageSelected(previewIcon, pathBox.Text);
|
||||||
previewIcon.Sprite = newPreviewImage;
|
};
|
||||||
itemPreviewSprites[previewImagePath] = newPreviewImage;
|
return true;
|
||||||
itemEditor.PreviewImage = previewImagePath;
|
};
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1072,40 +1076,40 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
OnClicked = (btn, userdata) =>
|
OnClicked = (btn, userdata) =>
|
||||||
{
|
{
|
||||||
OpenFileDialog ofd = new OpenFileDialog()
|
try
|
||||||
{
|
{
|
||||||
InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder),
|
OpenFileDialog ofd = new OpenFileDialog()
|
||||||
Title = "Select the files you want to add to the Steam Workshop item",
|
|
||||||
};
|
|
||||||
if (ofd.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
foreach (string file in ofd.FileNames)
|
|
||||||
{
|
{
|
||||||
string filePathRelativeToStagingFolder = UpdaterUtil.GetRelativePath(file, Path.Combine(Environment.CurrentDirectory, SteamManager.WorkshopItemStagingFolder));
|
InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder),
|
||||||
string filePathRelativeToBaseFolder = UpdaterUtil.GetRelativePath(file, Environment.CurrentDirectory);
|
Title = TextManager.Get("workshopitemaddfiles"),
|
||||||
//file is not inside the staging folder
|
};
|
||||||
if (filePathRelativeToStagingFolder.StartsWith(".."))
|
if (ofd.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
//submarines can be included in the content package directly
|
OnAddFilesSelected(ofd.FileNames);
|
||||||
string basePath = Path.GetDirectoryName(filePathRelativeToBaseFolder.Replace("..", ""));
|
|
||||||
if (basePath == "Submarines")
|
|
||||||
{
|
|
||||||
string destinationPath = Path.Combine(SteamManager.WorkshopItemStagingFolder, "Submarines", Path.GetFileName(file));
|
|
||||||
File.Copy(file, destinationPath);
|
|
||||||
itemContentPackage.AddFile(filePathRelativeToBaseFolder, ContentType.Submarine);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
itemContentPackage.AddFile(filePathRelativeToBaseFolder, ContentType.None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
itemContentPackage.AddFile(filePathRelativeToStagingFolder, ContentType.None);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
RefreshCreateItemFileList();
|
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
//use a custom prompt if OpenFileDialog fails (Linux/Mac)
|
||||||
|
var msgBox = new GUIMessageBox(TextManager.Get("workshopitemaddfiles"), "", relativeSize: new Vector2(0.4f, 0.2f),
|
||||||
|
buttons: new string[] { TextManager.Get("Cancel"), TextManager.Get("OK") });
|
||||||
|
|
||||||
|
var pathBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.5f), msgBox.Content.RectTransform, Anchor.Center) { MinSize = new Point(0, 25) });
|
||||||
|
|
||||||
|
msgBox.Buttons[0].OnClicked += msgBox.Close;
|
||||||
|
msgBox.Buttons[1].OnClicked += msgBox.Close;
|
||||||
|
msgBox.Buttons[1].OnClicked += (btn2, userdata2) =>
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(pathBox?.Text)) { return true; }
|
||||||
|
string[] filePaths = pathBox.Text.Split(',');
|
||||||
|
if (File.Exists(pathBox.Text))
|
||||||
|
{
|
||||||
|
OnAddFilesSelected(filePaths);
|
||||||
|
};
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1167,7 +1171,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), bottomButtonContainer.RectTransform, Anchor.CenterRight),
|
var publishBtn = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), bottomButtonContainer.RectTransform, Anchor.CenterRight),
|
||||||
TextManager.Get(itemEditor.Id > 0 ? "WorkshopItemUpdate" : "WorkshopItemPublish"), style: "GUIButtonLarge")
|
TextManager.Get(itemEditor.Id > 0 ? "WorkshopItemUpdate" : "WorkshopItemPublish"), style: "GUIButtonLarge")
|
||||||
{
|
{
|
||||||
IgnoreLayoutGroups = true,
|
IgnoreLayoutGroups = true,
|
||||||
@@ -1195,7 +1199,67 @@ namespace Barotrauma
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
publishBtn.TextBlock.AutoScale = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPreviewImageSelected(GUIImage previewImageElement, string filePath)
|
||||||
|
{
|
||||||
|
string previewImagePath = Path.GetFullPath(Path.Combine(SteamManager.WorkshopItemStagingFolder, SteamManager.PreviewImageName));
|
||||||
|
if (new FileInfo(filePath).Length > 1024 * 1024)
|
||||||
|
{
|
||||||
|
new GUIMessageBox(TextManager.Get("Error"), TextManager.Get("WorkshopItemPreviewImageTooLarge"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filePath != previewImagePath)
|
||||||
|
{
|
||||||
|
File.Copy(filePath, previewImagePath, overwrite: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemPreviewSprites.ContainsKey(previewImagePath))
|
||||||
|
{
|
||||||
|
itemPreviewSprites[previewImagePath].Remove();
|
||||||
|
}
|
||||||
|
var newPreviewImage = new Sprite(previewImagePath, sourceRectangle: null);
|
||||||
|
previewImageElement.Sprite = newPreviewImage;
|
||||||
|
itemPreviewSprites[previewImagePath] = newPreviewImage;
|
||||||
|
itemEditor.PreviewImage = previewImagePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAddFilesSelected(string[] fileNames)
|
||||||
|
{
|
||||||
|
if (fileNames == null) { return; }
|
||||||
|
for(int i = 0; i < fileNames.Length; i++)
|
||||||
|
{
|
||||||
|
string file = fileNames[i];
|
||||||
|
if (string.IsNullOrEmpty(file)) { continue; }
|
||||||
|
file = file.Trim();
|
||||||
|
if (!File.Exists(file)) { continue; }
|
||||||
|
|
||||||
|
string filePathRelativeToStagingFolder = UpdaterUtil.GetRelativePath(file, Path.Combine(Environment.CurrentDirectory, SteamManager.WorkshopItemStagingFolder));
|
||||||
|
string filePathRelativeToBaseFolder = UpdaterUtil.GetRelativePath(file, Environment.CurrentDirectory);
|
||||||
|
//file is not inside the staging folder
|
||||||
|
if (filePathRelativeToStagingFolder.StartsWith(".."))
|
||||||
|
{
|
||||||
|
//submarines can be included in the content package directly
|
||||||
|
string basePath = Path.GetDirectoryName(filePathRelativeToBaseFolder.Replace("..", ""));
|
||||||
|
if (basePath == "Submarines")
|
||||||
|
{
|
||||||
|
string destinationPath = Path.Combine(SteamManager.WorkshopItemStagingFolder, "Submarines", Path.GetFileName(file));
|
||||||
|
File.Copy(file, destinationPath);
|
||||||
|
itemContentPackage.AddFile(filePathRelativeToBaseFolder, ContentType.Submarine);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
itemContentPackage.AddFile(filePathRelativeToBaseFolder, ContentType.None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
itemContentPackage.AddFile(filePathRelativeToStagingFolder, ContentType.None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RefreshCreateItemFileList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshCreateItemFileList()
|
private void RefreshCreateItemFileList()
|
||||||
|
|||||||
Reference in New Issue
Block a user