Skip to content

Commit

Permalink
Accept . in package name and dsmappname
Browse files Browse the repository at this point in the history
Support now Linker Worker
Improve support for Privilege and Port Config
  • Loading branch information
vletroye committed Jan 30, 2021
1 parent fe799b4 commit e3ec67d
Show file tree
Hide file tree
Showing 12 changed files with 961 additions and 105 deletions.
1 change: 1 addition & 0 deletions Mods/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 90 additions & 39 deletions Mods/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2697,12 +2697,15 @@ private void textBoxPackage_Validated(object sender, EventArgs e)
{
var focused = Helper.FindFocusedControl(this);

var copy = new Package();
foreach (var item in list.items)
if (list != null)
{
copy.items.Add(item.Key.Replace(oldName, newName), item.Value);
var copy = new Package();
foreach (var item in list.items)
{
copy.items.Add(item.Key.Replace(oldName, newName), item.Value);
}
list = copy;
}
list = copy;
if (!string.IsNullOrEmpty(textBoxDsmAppName.Text))
textBoxDsmAppName.Text = textBoxDsmAppName.Text.Replace(oldName, newName);

Expand All @@ -2715,14 +2718,17 @@ private void textBoxPackage_Validated(object sender, EventArgs e)
oldName = string.Format("/webman/3rdparty/{0}/", oldName);
newName = string.Format("/webman/3rdparty/{0}/", newName);

foreach (var item in list.items)
if (list != null)
{
if (item.Value.url.StartsWith(oldName))
foreach (var item in list.items)
{
item.Value.url = item.Value.url.Replace(oldName, newName);
if (item.Value.url.StartsWith(oldName))
{
item.Value.url = item.Value.url.Replace(oldName, newName);
}
}
BindData(list, null);
}
BindData(list, null);
DisplayItem();
focused.Focus();

Expand Down Expand Up @@ -2842,9 +2848,9 @@ private void textBoxDsmAppName_Validating(object sender, CancelEventArgs e)
{
if (string.IsNullOrEmpty(textBoxDsmAppName.Text) && !string.IsNullOrEmpty(textBoxPackage.Text))
{
textBoxDsmAppName.Text = string.Format("SYNO.SDS._ThirdParty.App.{0}", Helper.CleanUpText(textBoxPackage.Text));
textBoxDsmAppName.Text = string.Format("SYNO.SDS.ThirdParty.App.{0}", Helper.CleanUpText(textBoxPackage.Text));
}
var name = textBoxDsmAppName.Text.Replace(".", "_").Replace("__", "_");
var name = textBoxDsmAppName.Text; //.Replace(".", "_").Replace("__", "_");
var cleaned = Helper.CleanUpText(textBoxDsmAppName.Text);
if (name != cleaned)
{
Expand Down Expand Up @@ -3112,7 +3118,7 @@ private DialogResult SavePackage(string path, bool force = false)
}
}
}
catch { saved = DialogResult.Abort; }
catch (Exception ex) { saved = DialogResult.Abort; }
}
return saved;
}
Expand Down Expand Up @@ -3515,15 +3521,26 @@ private void ShowIconOnScriptMenu(ToolStripItem menu)
{
switch (file)
{
case "!usr-local-linker":
var item = resource == null ? null : resource.SelectToken(file.Substring(1));
if (item != null && !string.IsNullOrEmpty(CurrentPackageFolder))
file = Path.Combine(CurrentPackageFolder, "INFO");
else
file = null;
break;
case "!port-config":
file = null;
var portConfig = resource == null ? null : resource.SelectToken("port-config");
if (portConfig != null)
if (portConfig != null && !string.IsNullOrEmpty(CurrentPackageFolder))
{
var protocolFile = portConfig.SelectToken("protocol-file").ToString();
if (protocolFile != null && !string.IsNullOrEmpty(CurrentPackageFolder))
var protocolFile = portConfig.SelectToken("protocol-file");
if (protocolFile == null) // Maybe the old style ?
{
file = Path.Combine(CurrentPackageFolder, portConfig.ToString().Replace("/", "\\"));
}
else
{
file = Path.Combine(CurrentPackageFolder, "package", protocolFile.Replace("/", "\\"));
file = Path.Combine(CurrentPackageFolder, "package", protocolFile.ToString().Replace("/", "\\"));
}
}
break;
Expand All @@ -3538,7 +3555,8 @@ private void ShowIconOnScriptMenu(ToolStripItem menu)
}
else
{
file = Path.Combine(CurrentPackageFolder, string.Format(file, info["dsmuidir"]));
var uidir = info.Keys.Contains("dsmuidir") ? info["dsmuidir"] : "";
file = Path.Combine(CurrentPackageFolder, string.Format(file, uidir));
}
}
break;
Expand Down Expand Up @@ -5360,25 +5378,29 @@ private void portConfigToolStripMenuItem_Click(object sender, EventArgs e)
var portConfig = resource == null ? null : resource.SelectToken("port-config");
if (portConfig != null)
{
var protocolFile = portConfig.SelectToken("protocol-file").ToString();
if (protocolFile != null)
var protocolFile = portConfig.SelectToken("protocol-file");
if (protocolFile == null) // Maybe the old style ?
{
portConfigFile = Path.Combine(CurrentPackageFolder, portConfig.ToString().Replace("/", "\\"));
}
else
{
portConfigFile = Path.Combine(CurrentPackageFolder, "package", protocolFile.ToString().Replace("/", "\\"));
}
if (File.Exists(portConfigFile))
{
portConfigFile = Path.Combine(CurrentPackageFolder, "package", protocolFile.Replace("/", "\\"));
if (File.Exists(portConfigFile))
//Read the INI protocol file (remove space before and after the '=')
IniParserConfiguration config = new IniParserConfiguration();
config.AssigmentSpacer = "";
var parser = new IniDataParser(config);
var fileParser = new FileIniDataParser(parser);
try
{
//Read the INI protocol file (remove space before and after the '=')
IniParserConfiguration config = new IniParserConfiguration();
config.AssigmentSpacer = "";
var parser = new IniDataParser(config);
var fileParser = new FileIniDataParser(parser);
try
{
portConfigData = fileParser.ReadFile(portConfigFile);
}
catch
{
MessageBoxEx.Show(this, string.Format("Service Configuration file {0} can't be parsed.", protocolFile), "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
}
portConfigData = fileParser.ReadFile(portConfigFile);
}
catch
{
MessageBoxEx.Show(this, string.Format("Service Configuration file {0} can't be parsed.", protocolFile.ToString()), "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
}
}
}
Expand All @@ -5391,11 +5413,18 @@ private void portConfigToolStripMenuItem_Click(object sender, EventArgs e)

if (portConfig != null)
{
var protocolFile = portConfig.SelectToken("protocol-file").ToString();
if (protocolFile != null)
var protocolFile = portConfig.SelectToken("protocol-file");
if (protocolFile == null) // Maybe the old style ?
{
protocolFile = Path.Combine(CurrentPackageFolder, "package", protocolFile.Replace("/", "\\"));
Directory.CreateDirectory(Path.GetDirectoryName(protocolFile));
portConfigFile = Path.Combine(CurrentPackageFolder, portConfig.ToString().Replace("/", "\\"));
}
else
{
portConfigFile = Path.Combine(CurrentPackageFolder, "package", protocolFile.ToString().Replace("/", "\\"));
}
if (portConfigFile != null && portConfigFile.EndsWith(".sc"))
{
Directory.CreateDirectory(Path.GetDirectoryName(portConfigFile));

//Read the INI protocol string and remove space before and after the '='
IniParserConfiguration config = new IniParserConfiguration();
Expand All @@ -5411,7 +5440,7 @@ private void portConfigToolStripMenuItem_Click(object sender, EventArgs e)
}

//Save the INI protocol file
Helper.WriteAnsiFile(protocolFile, portConfigData.ToString());
Helper.WriteAnsiFile(portConfigFile, portConfigData.ToString());
//var fileParser = new FileIniDataParser(parser);
//fileParser.WriteFile(protocolFile, portConfigData, Encoding.GetEncoding(1252));

Expand Down Expand Up @@ -5535,7 +5564,29 @@ private void linkerToolStripMenuItem_Click(object sender, EventArgs e)
}
else
{
MessageBoxEx.Show(this, "This Worker is not yet implemented.", "Notification", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
var linkerConfig = resource == null ? null : resource.SelectToken("usr-local-linker");

var ui = info.ContainsKey("dsmuidir") ? info["dsmuidir"] : "";
var worker = new Linker(linkerConfig, Path.Combine(CurrentPackageFolder, "package"), ui);
if (worker.ShowDialog(this) == DialogResult.OK && worker.PendingChanges())
{
linkerConfig = worker.Specification;

if (linkerConfig != null && linkerConfig.HasValues)
{
//Update the Resource file
if (resource == null) resource = JsonConvert.DeserializeObject<JObject>("{}");
resource["usr-local-linker"] = linkerConfig;
}
else
{
if (resource != null)
resource.Remove("usr-local-linker");
}

//Save the Resource file
SaveResourceConfig(CurrentPackageFolder);
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions Mods/Helpers/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static class Helper
public static Regex getPort = new Regex(@"^:(\d*)/.*$", RegexOptions.Compiled);
public static Regex getOldFirmwareVersion = new Regex(@"^\d+.\d+\.\d+$", RegexOptions.Compiled);
public static Regex getShortFirmwareVersion = new Regex(@"^\d+\.\d+$", RegexOptions.Compiled);
public static Regex getFirmwareVersion = new Regex(@"^(\d+)\.(\d+)(\.[^-]*){0,1}-(\d+)(.*)$", RegexOptions.Compiled); //new Regex(@"^(\d+\.)*\d-\d+$", RegexOptions.Compiled);
public static Regex getFirmwareVersion = new Regex(@"^(\d+)\.(\d+)(\.[^-]*){0,1}(-(\d+)(.*)){0,1}$", RegexOptions.Compiled); //new Regex(@"^(\d+\.)*\d-\d+$", RegexOptions.Compiled);

public static Regex getOldVersion = new Regex(@"^((\d+\.)*\d+)\.(\d+)$", RegexOptions.Compiled);
public static Regex getVersion = new Regex(@"^(\d+\.)*\d+-\d+$", RegexOptions.Compiled);
Expand All @@ -42,7 +42,7 @@ internal enum SymLinkFlag
Directory = 1
}

static Regex cleanChar = new Regex(@"[^a-zA-Z0-9\-]", RegexOptions.Compiled);
static Regex cleanChar = new Regex(@"[^a-zA-Z0-9\-\.]", RegexOptions.Compiled);
static string resourcesDirectory = null;

public static bool CompareImages(Bitmap b1, Bitmap b2)
Expand Down Expand Up @@ -802,7 +802,7 @@ public static void EncryptAndSign(string sourcePath, string targetPath, string p
encrypter.EncryptAndSign(outputStream, new FileInfo(sourcePath));
}
}

public static string JsonPrettify(string json)
{
using (var stringReader = new StringReader(json))
Expand Down Expand Up @@ -1032,7 +1032,7 @@ public static void LoadDSMReleases(TextBox box)
if (getFirmwareVersion.IsMatch(ver))
{
var match = getFirmwareVersion.Match(ver);
var firmware = String.Format("{0}.{1}-{2}", match.Groups[1].Value, match.Groups[2].Value, match.Groups[4].Value);
var firmware = String.Format("{0}.{1}-{2}", match.Groups[1].Value, match.Groups[2].Value, match.Groups[5].Value);
if (!box.AutoCompleteCustomSource.Contains(firmware))
box.AutoCompleteCustomSource.Add(firmware);
}
Expand Down Expand Up @@ -1072,7 +1072,7 @@ private static void GetFirmwareMajorMinor(SortedDictionary<string, string> info,

major = int.Parse(match.Groups[1].Value);
minor = int.Parse(match.Groups[2].Value);
build = int.Parse(match.Groups[4].Value);
int.TryParse(match.Groups[5].Value, out build);
}

public static bool CheckDSMVersionMax(SortedDictionary<string, string> info, int maxMajor, int maxMinor, int maxBuild)
Expand Down
9 changes: 9 additions & 0 deletions Mods/Mods.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@
<Compile Include="Forms\FindReplace.Designer.cs">
<DependentUpon>FindReplace.cs</DependentUpon>
</Compile>
<Compile Include="Workers\Linker.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Workers\Linker.Designer.cs">
<DependentUpon>Linker.cs</DependentUpon>
</Compile>
<Compile Include="Workers\Privilege.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -239,6 +245,9 @@
<Compile Include="Forms\SearchAndReplace.Designer.cs">
<DependentUpon>SearchAndReplace.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="Workers\Linker.resx">
<DependentUpon>Linker.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Workers\Privilege.resx">
<DependentUpon>Privilege.cs</DependentUpon>
</EmbeddedResource>
Expand Down
Loading

0 comments on commit e3ec67d

Please sign in to comment.