Skip to content

Commit 69b24b2

Browse files
committed
Added Import from themepack
1 parent 903df3f commit 69b24b2

5 files changed

Lines changed: 79 additions & 67 deletions

File tree

ThemePacker/MainForm.cs

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void ThemePacker_Load(object sender, EventArgs e)
6464
picturesLsv.LargeImageList = _imageList;
6565
picturesLsv.View = View.LargeIcon;
6666

67-
CreateDirectory("temp");//crée un dossier temporaire
67+
CreateDirectory("temp\\themepack");//crée un dossier temporaire
6868
}
6969

7070
private void ClearPictures()
@@ -128,10 +128,15 @@ private void ListShuffle()
128128
_pictures = _pictures.OrderBy(x => rng.Next()).ToDictionary(item => item.Key, item => item.Value);
129129
}
130130

131-
private bool SelectPic()
131+
private bool SelectPic(string path = null)
132132
{
133-
List<string> imagesList = Directory.GetFiles(_path, "*.jpg", SearchOption.TopDirectoryOnly).ToList();
134-
imagesList.AddRange(Directory.GetFiles(_path, "*.png", SearchOption.TopDirectoryOnly));
133+
if(path == null)
134+
{
135+
path = _path;
136+
}
137+
138+
List<string> imagesList = Directory.GetFiles(path, "*.jpg", SearchOption.TopDirectoryOnly).ToList();
139+
imagesList.AddRange(Directory.GetFiles(path, "*.png", SearchOption.TopDirectoryOnly));
135140
if (imagesList.Count < 1)
136141
{
137142
MessageBox.Show("Votre dossier ne contient pas d'image ou pas le bon type d'image. (png et jpg only)");
@@ -158,7 +163,6 @@ private void BtnPrevious_Click(object sender, EventArgs e)
158163
{
159164
MessageBox.Show("DIS IS ZE BEGINING (joy face)");
160165
}
161-
//Hide();
162166
}
163167

164168
private void UpdatePic()
@@ -240,32 +244,23 @@ public void Generate()
240244
theme["Slideshow"]["Interval"] = "60000";
241245

242246
tfs.JSON = theme;
243-
tfs.JsonSerialize();
244-
245-
//read and replace
246-
string text = File.ReadAllText("temp\\super.theme");
247-
File.WriteAllText("temp\\super.theme", text);
247+
tfs.JsonSerialize($"temp\\themepack\\{fileName}.theme");
248248

249249
CabInfo cab = new CabInfo(saveFileDialog.FileName);
250-
cab.Pack("temp", true, Microsoft.Deployment.Compression.CompressionLevel.Normal, null);
251-
252-
Environment.Exit(7);
253-
}
250+
cab.Pack("temp\\themepack", true, Microsoft.Deployment.Compression.CompressionLevel.Normal, null);
254251

255-
private void SetThemeFileSerializerProperty(dynamic theme, string category, string property, string value)
256-
{
257-
((theme as IDictionary<string, object>)[category] as IDictionary<string, object>)[property] = value;
252+
this.Close();
258253
}
259254

260255
private void CopyQuick()
261256
{
262257
foreach (string path in _likeds)
263258
{
264-
File.Copy(path, "temp\\DesktopBackground\\" + new FileInfo(path).Name);
259+
File.Copy(path, "temp\\themepack\\DesktopBackground\\" + new FileInfo(path).Name);
265260
}
266261

267262
File.Copy("Resources\\super.theme", "temp\\super.theme", true);
268-
File.Copy("Resources\\icon.png", "temp\\icon.png", true);
263+
File.Copy("Resources\\icon.png", "temp\\themepack\\icon.png", true);
269264
}
270265

271266
private void CreateDirectory(string path)
@@ -327,6 +322,8 @@ private async void BtnNext_Click_API(object sender, EventArgs e)
327322

328323
private async Task GetImageFromInspirobot()
329324
{
325+
Directory.CreateDirectory(@"temp\images");
326+
330327
using (var client = new HttpClient())
331328
{
332329
client.BaseAddress = new Uri("http://inspirobot.me/");
@@ -342,7 +339,7 @@ private async Task GetImageFromInspirobot()
342339
{
343340
string[] urlBits = url.Split("/".ToArray(), StringSplitOptions.RemoveEmptyEntries);
344341
string fileName = urlBits[urlBits.Length - 1];
345-
string imagePath = $"temp\\{fileName}";
342+
string imagePath = $"temp\\images\\{fileName}";
346343

347344
Debug.WriteLine($"Starting {fileName} download");
348345
webClient.DownloadFile(new Uri(url), imagePath);
@@ -366,7 +363,29 @@ private void ThemePacker_FormClosed(object sender, FormClosedEventArgs e)
366363

367364
private void ImportThemepackToolStripMenuItem_Click(object sender, EventArgs e)
368365
{
366+
OpenFileDialog openFileDialog = new OpenFileDialog();
367+
openFileDialog.Filter = "Themepack | *.themepack";
368+
openFileDialog.Title = "Ouvrir";
369+
370+
if(openFileDialog.ShowDialog() == DialogResult.OK && openFileDialog.FileName.EndsWith(".themepack"))
371+
{
369372

373+
string filename = $"temp\\{openFileDialog.FileName.Split('\\').Last()}";
374+
File.Copy(openFileDialog.FileName, filename);
375+
File.Move(filename, filename = filename.Replace(".themepack", ".cab"));
376+
377+
CabInfo cab = new CabInfo(filename);
378+
_path = filename.Split('.')[0];
379+
cab.Unpack(_path);
380+
381+
if (SelectPic(_path + "\\DesktopBackground"))
382+
{
383+
btnLike.Enabled = true;
384+
btnNext.Enabled = true;
385+
btnPrevious.Enabled = true;
386+
UpdatePic();
387+
}
388+
}
370389
}
371390

372391
private void AsImageFolderToolStripMenuItem_Click(object sender, EventArgs e)

ThemePacker/Properties/Resources.Designer.cs

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

ThemePacker/Properties/Settings.Designer.cs

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

ThemePacker/ThemeFileSerializer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,13 @@ public void JsonSerialize(string path = null)
104104
if (path == null)
105105
path = _path;
106106

107+
string dir = path.Split('\\').Where(d => !d.Contains(".")).Aggregate((i,j) => i + "\\" + j);
108+
109+
Directory.CreateDirectory(dir);
110+
107111
var themeDic = JSON.ToObject<Dictionary<string, Dictionary<string, string>>>();
108112

109-
using (StreamWriter sw = new StreamWriter(path))
113+
using (StreamWriter sw = new StreamWriter(path, false))
110114
{
111115
foreach (var category in themeDic)
112116
{

ThemePacker/ThemePacker.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
77
<ProjectGuid>{3CA13A26-7504-49A3-8E0E-0B0700472625}</ProjectGuid>
88
<OutputType>WinExe</OutputType>
9-
<RootNamespace>TheFullFacebook</RootNamespace>
10-
<AssemblyName>TheFullFacebook</AssemblyName>
9+
<RootNamespace>ThemePacker</RootNamespace>
10+
<AssemblyName>ThemePacker</AssemblyName>
1111
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
@@ -87,6 +87,7 @@
8787
<Compile Include="Properties\Resources.Designer.cs">
8888
<AutoGen>True</AutoGen>
8989
<DependentUpon>Resources.resx</DependentUpon>
90+
<DesignTime>True</DesignTime>
9091
</Compile>
9192
<None Include="packages.config" />
9293
<None Include="Properties\Settings.settings">

0 commit comments

Comments
 (0)