Skip to content

Commit 026a97f

Browse files
authored
Merge pull request #32 from Dragon-0609/dev
Fix errors caused by old/new theme 2
2 parents 6eda8a5 + 05406d5 commit 026a97f

File tree

7 files changed

+31
-20
lines changed

7 files changed

+31
-20
lines changed

Yuki Theme.Core/CLI.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public static void load_schemes (Func <string> ifZero = null)
9191
/// <returns></returns>
9292
public static bool add (string copyFrom, string name)
9393
{
94+
if (name.Length < 2)
95+
{
96+
if (CLI_Actions.showError != null) CLI_Actions.showError ("The name is too short. At least it must be 2", "Too short");
97+
return true;
98+
}
9499
string sto = Helper.ConvertNameToPath (name);
95100
string patsh = Path.Combine (currentPath,
96101
$"Themes/{sto}" + (oldThemeList [copyFrom] ? Helper.FILE_EXTENSTION_OLD : Helper.FILE_EXTENSTION_NEW));
@@ -325,6 +330,10 @@ public static void import (string path, Func <string, string, bool> exist)
325330
/// <param name="to">To</param>
326331
public static void rename (string from, string to)
327332
{
333+
if (to.Length < 2)
334+
{
335+
if (CLI_Actions.showError != null) CLI_Actions.showError ("The name is too short. At least it must be 2", "Too short");
336+
}
328337
if (!isDefaultTheme [from])
329338
{
330339
string frm = Helper.ConvertNameToPath (from);
@@ -772,7 +781,7 @@ private static void ReGenerateFromOld (string path, string oldPath, string name,
772781
File.WriteAllText (path, json);
773782
else
774783
{
775-
Helper.UpdateZip (path, json, null, true, null, true);
784+
Helper.UpdateZip (path, json, null, true, null, true, "", false);
776785
}
777786
}
778787

Yuki Theme.Core/Forms/ThemeManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public void onRename (string from, string to)
7575
ListViewItem res = scheme.Items.Find (from, true) [0];
7676
ReItem reit = (ReItem)res;
7777
reit.SetName (to);
78+
form.schemes.Items [form.schemes.Items.IndexOf (from)] = to;
79+
scheme.Invalidate();
7880
form.schemes.Invalidate();
7981
}
8082

Yuki Theme.Core/Helper.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,16 @@ private static bool IsZip (ZipArchive zipFile, string themefile)
272272
}
273273

274274
public static void UpdateZip (string path, string content, Image img, bool wantToKeepImage = false, Image sticker = null,
275-
bool wantToKeepSticker = false, string themeName = "")
275+
bool wantToKeepSticker = false, string themeName = "", bool asOld = true)
276276
{
277277
if (!wantToKeepImage && !wantToKeepSticker && img == null && sticker == null)
278278
{
279-
SaveToFile (path, content);
279+
SaveToFile (path, content, asOld);
280280
} else
281281
{
282282
using (var archive = ZipFile.Open (path, ZipArchiveMode.Update))
283283
{
284-
if (themeName.Length == 0) themeName = GetThemeSaveName ();
284+
if (themeName.Length == 0) themeName = GetThemeSaveName (asOld);
285285
ZipArchiveEntry entry = archive.GetEntry (themeName);
286286

287287
entry?.Delete ();
@@ -316,10 +316,10 @@ public static void UpdateZip (string path, string content, Image img, bool wantT
316316
}
317317
}
318318

319-
private static void SaveToFile (string path, string content)
319+
private static void SaveToFile (string path, string content, bool asOld)
320320
{
321321
if (File.Exists (path)) File.Delete (path);
322-
if (Settings.saveAsOld)
322+
if (asOld)
323323
SaveToFileOld (path, content);
324324
else
325325
SaveToFileNew (path, content);
@@ -376,18 +376,18 @@ private static void ExtractFile (ZipArchive archive, string filename, string des
376376
}
377377
}
378378

379-
public static void Zip (string path, string content, Image img, Image sticker = null, string themeName = "")
379+
public static void Zip (string path, string content, Image img, Image sticker = null, string themeName = "", bool asOld = true)
380380
{
381381
if (img == null && sticker == null)
382382
{
383-
SaveToFile (path, content);
383+
SaveToFile (path, content, asOld);
384384
} else
385385
{
386386
using (var fileStream = new FileStream (path, FileMode.Create))
387387
{
388388
using (var archive = new ZipArchive (fileStream, ZipArchiveMode.Create))
389389
{
390-
if (themeName.Length == 0) themeName = GetThemeSaveName ();
390+
if (themeName.Length == 0) themeName = GetThemeSaveName (asOld);
391391
ZipArchiveEntry entry = archive.CreateEntry (themeName, CompressionLevel.Optimal);
392392

393393

@@ -443,14 +443,14 @@ public static Color ChangeColorBrightness (Color color, float correctionFactor)
443443
return Color.FromArgb (color.A, (int) red, (int) green, (int) blue);
444444
}
445445

446-
public static string GetThemeSaveName ()
446+
public static string GetThemeSaveName (bool asOld)
447447
{
448-
return "theme." + GetSaveFormat ();
448+
return "theme." + GetSaveFormat (asOld);
449449
}
450450

451-
public static string GetSaveFormat ()
451+
public static string GetSaveFormat (bool asOld)
452452
{
453-
return Settings.saveAsOld ? "xshd" : "json";
453+
return asOld ? "xshd" : "json";
454454
}
455455

456456
public static bool IsDark (Color clr)

Yuki Theme.Core/NewThemeFormat.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public static void saveList (Image img2 = null, Image img3 = null, bool wantToKe
4545
{
4646
if (iszip)
4747
{
48-
Helper.UpdateZip (CLI.currentTheme.fullPath, json, img2, wantToKeep, img3, wantToKeep);
48+
Helper.UpdateZip (CLI.currentTheme.fullPath, json, img2, wantToKeep, img3, wantToKeep, "", false);
4949
} else
5050
{
51-
Helper.Zip (CLI.currentTheme.fullPath, json, img2, img3);
51+
Helper.Zip (CLI.currentTheme.fullPath, json, img2, img3, "", false);
5252
}
5353
}
5454
}
@@ -232,7 +232,7 @@ public static void WriteName (string path, string name)
232232
File.WriteAllText (CLI.pathToFileNew, json);
233233
else
234234
{
235-
Helper.UpdateZip (path, json, null, true, null, true);
235+
Helper.UpdateZip (path, json, null, true, null, true, "", false);
236236
}
237237
}
238238

Yuki Theme.Core/OldThemeFormat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ public static void SaveXML (Image img2, Image img3, bool wantToKeep, bool iszip,
262262
string txml = doc.OuterXml;
263263
if (iszip)
264264
{
265-
Helper.UpdateZip (themePath, txml, img2, wantToKeep, img3, wantToKeep, "theme.xshd");
265+
Helper.UpdateZip (themePath, txml, img2, wantToKeep, img3, wantToKeep, "theme.xshd", true);
266266
} else
267267
{
268-
Helper.Zip (themePath, txml, img2, img3, "theme.xshd");
268+
Helper.Zip (themePath, txml, img2, img3, "theme.xshd", true);
269269
}
270270
}
271271
}

Yuki Theme.Core/Parsers/DokiThemeParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ public override void finishParsing (string path)
629629
node.AppendChild (doc.CreateComment ("hasSticker:" + stick.Item1.ToString ()));
630630
}
631631

632-
Helper.Zip (outname, doc.OuterXml, wallp.Item2, stick.Item2);
632+
Helper.Zip (outname, doc.OuterXml, wallp.Item2, stick.Item2, "", true);
633633
}
634634
}
635635

Yuki Theme.Core/Parsers/MainParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static void Parse (string path, MForm form = null, bool ask = true, bool
9090
Image sticker = null;
9191
if (isWallpaperExist) wallpaper = Image.FromFile (Path.Combine (directory, "background.png"));
9292
if (isStickerExist) sticker = Image.FromFile (Path.Combine (directory, "sticker.png"));
93-
Helper.Zip (pathef, content, wallpaper, sticker, "theme.xshd");
93+
Helper.Zip (pathef, content, wallpaper, sticker, "theme.xshd", true);
9494
} else
9595
{
9696
File.Copy (path, pathef, true);

0 commit comments

Comments
 (0)