Skip to content

Commit 3f69b5b

Browse files
committed
Minor optimizations in Packager Client
1 parent 27fe459 commit 3f69b5b

File tree

5 files changed

+115
-78
lines changed

5 files changed

+115
-78
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace SmartStore.Packager
5+
{
6+
public class ExtensionInfo : Tuple<string, string>
7+
{
8+
public ExtensionInfo(string path, string name) : base(path, name)
9+
{
10+
}
11+
12+
public string Path { get { return base.Item1; } }
13+
public string Name { get { return base.Item2; } }
14+
}
15+
}

src/Tools/SmartStore.Packager/MainForm.Designer.cs

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Tools/SmartStore.Packager/MainForm.cs

Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private void btnCreatePackages_Click(object sender, EventArgs e)
6868
var outputPath = txtOutputPath.Text;
6969

7070
var erroredIds = new List<string>();
71-
string currentPackage = string.Empty;
71+
ExtensionInfo currentPackage = null;
7272

7373
try
7474
{
@@ -80,22 +80,22 @@ private void btnCreatePackages_Click(object sender, EventArgs e)
8080
// create plugin packages
8181
foreach (var sel in lstPlugins.SelectedItems)
8282
{
83-
currentPackage = (string)sel;
84-
var fi = creator.CreatePluginPackage((string)sel);
85-
if (!LogMessage(fi, (string)sel))
83+
currentPackage = (ExtensionInfo)sel;
84+
var fi = creator.CreatePluginPackage(currentPackage.Path);
85+
if (!LogMessage(fi, currentPackage.Name))
8686
{
87-
erroredIds.Add(currentPackage);
87+
erroredIds.Add(currentPackage.Path);
8888
}
8989
}
9090

9191
// create theme packages
9292
foreach (var sel in lstThemes.SelectedItems)
9393
{
94-
currentPackage = (string)sel;
95-
var fi = creator.CreateThemePackage((string)sel);
96-
if (!LogMessage(fi, (string)sel))
94+
currentPackage = (ExtensionInfo)sel;
95+
var fi = creator.CreateThemePackage(currentPackage.Path);
96+
if (!LogMessage(fi, currentPackage.Name))
9797
{
98-
erroredIds.Add(currentPackage);
98+
erroredIds.Add(currentPackage.Name);
9999
}
100100
}
101101

@@ -151,61 +151,89 @@ private void btnReadDescriptions_Click(object sender, EventArgs e)
151151

152152
btnReadDescriptions.Enabled = false;
153153

154-
ReadPlugins(vpp);
155-
ReadThemes(vpp);
154+
ReadPackages(vpp);
156155

157156
btnReadDescriptions.Enabled = true;
158157
}
159158

160-
private void ReadPlugins(IVirtualPathProvider vpp)
159+
160+
private void ReadPackages(IVirtualPathProvider vpp)
161161
{
162162
if (!ValidatePaths())
163163
return;
164164

165+
lstPlugins.DisplayMember = "Name";
166+
lstPlugins.ValueMember = "Path";
167+
lstThemes.DisplayMember = "Name";
168+
lstThemes.ValueMember = "Path";
169+
165170
lstPlugins.Items.Clear();
166-
foreach (var dir in vpp.ListDirectories("~/Plugins"))
167-
{
168-
var filePath = vpp.Combine(dir, "Description.txt");
169-
if (!vpp.FileExists(filePath))
170-
continue;
171+
lstThemes.Items.Clear();
171172

172-
try
173+
IEnumerable<string> dirs = Enumerable.Empty<string>();
174+
175+
if (vpp.DirectoryExists("~/Plugins") || vpp.DirectoryExists("~/Themes"))
176+
{
177+
if (vpp.DirectoryExists("~/Plugins"))
173178
{
174-
var descriptor = PluginFileParser.ParsePluginDescriptionFile(vpp.MapPath(filePath));
175-
if (descriptor != null)
176-
{
177-
lstPlugins.Items.Add(descriptor.FolderName);
178-
}
179+
dirs = dirs.Concat(vpp.ListDirectories("~/Plugins"));
179180
}
180-
catch
181+
if (vpp.DirectoryExists("~/Themes"))
181182
{
182-
continue;
183+
dirs = dirs.Concat(vpp.ListDirectories("~/Themes"));
183184
}
184185
}
185-
}
186-
187-
private void ReadThemes(IVirtualPathProvider vpp)
188-
{
189-
if (!ValidatePaths())
190-
return;
186+
else
187+
{
188+
dirs = vpp.ListDirectories("~/");
189+
}
191190

192-
lstThemes.Items.Clear();
193-
foreach (var dir in vpp.ListDirectories("~/Themes"))
191+
foreach (var dir in dirs)
194192
{
195-
var filePath = vpp.Combine(dir, "theme.config");
193+
bool isTheme = false;
194+
195+
// is it a plugin?
196+
var filePath = vpp.Combine(dir, "Description.txt");
196197
if (!vpp.FileExists(filePath))
197-
continue;
198+
{
199+
// ...no! is it a theme?
200+
filePath = vpp.Combine(dir, "theme.config");
201+
if (!vpp.FileExists(filePath))
202+
continue;
203+
204+
isTheme = true;
205+
}
198206

199207
try
200208
{
201-
var manifest = ThemeManifest.Create(vpp.MapPath(dir));
202-
lstThemes.Items.Add(manifest.ThemeName);
209+
if (isTheme)
210+
{
211+
var manifest = ThemeManifest.Create(vpp.MapPath(dir));
212+
lstThemes.Items.Add(new ExtensionInfo(dir, manifest.ThemeName));
213+
}
214+
else
215+
{
216+
var descriptor = PluginFileParser.ParsePluginDescriptionFile(vpp.MapPath(filePath));
217+
if (descriptor != null)
218+
{
219+
lstPlugins.Items.Add(new ExtensionInfo(dir, descriptor.FolderName));
220+
}
221+
}
203222
}
204223
catch
205224
{
206225
continue;
207226
}
208227
}
228+
229+
if (lstPlugins.Items.Count > 0)
230+
{
231+
tabMain.SelectedIndex = 0;
232+
}
233+
else if (lstThemes.Items.Count > 0)
234+
{
235+
tabMain.SelectedIndex = 1;
236+
}
209237
}
210238

211239
private bool ValidatePaths()
@@ -217,13 +245,6 @@ private bool ValidatePaths()
217245
return false;
218246
}
219247

220-
//if (!Directory.Exists(txtOutputPath.Text))
221-
//{
222-
// MessageBox.Show("Output path does not exist! Please specify an existing path", "Path error", MessageBoxButtons.OK, MessageBoxIcon.Error);
223-
// txtOutputPath.Focus();
224-
// return false;
225-
//}
226-
227248
return true;
228249
}
229250

src/Tools/SmartStore.Packager/PackageCreator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public PackageCreator(string rootPath, string outputPath)
3030
_packageBuilder = new PackageBuilder(wsf, _vpp);
3131
}
3232

33-
public FileInfo CreatePluginPackage(string folderName)
33+
public FileInfo CreatePluginPackage(string path)
3434
{
35-
string virtualPath = "~/Plugins/{0}/Description.txt".FormatInvariant(folderName);
35+
string virtualPath = _vpp.Combine(path, "Description.txt");
3636

3737
if (!_vpp.FileExists(virtualPath))
3838
{
@@ -62,9 +62,9 @@ public FileInfo CreatePluginPackage(PluginDescriptor descriptor)
6262
return SavePackageFile(result);
6363
}
6464

65-
public FileInfo CreateThemePackage(string themeName)
65+
public FileInfo CreateThemePackage(string virtualPath)
6666
{
67-
string virtualPath = "~/Themes/{0}".FormatInvariant(themeName);
67+
//string virtualPath = "~/Themes/{0}".FormatInvariant(themeName);
6868

6969
var manifest = ThemeManifest.Create(_vpp.MapPath(virtualPath));
7070

src/Tools/SmartStore.Packager/SmartStore.Packager.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Compile Include="..\..\AssemblyVersionInfo.cs">
6161
<Link>Properties\AssemblyVersionInfo.cs</Link>
6262
</Compile>
63+
<Compile Include="ExtensionInfo.cs" />
6364
<Compile Include="MainForm.cs">
6465
<SubType>Form</SubType>
6566
</Compile>

0 commit comments

Comments
 (0)