Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add handling for moved manga files.

  • Loading branch information...
commit 1bd89793d8f34efd84d9249f5d72e8bd6e240d6a 1 parent b876bae
@a-fung authored
View
29 source/aspnetserver/Manga.cs
@@ -243,6 +243,15 @@ public static Manga GetByPath(string path)
return null;
}
+ private static Manga[] GetSameFileName(int cid, string path)
+ {
+ string fileName = Database.Quote(path.Substring(path.LastIndexOf("\\")));
+ fileName = fileName.Substring(1, fileName.Length - 2).Replace("\\", "\\\\").Replace("%", "\\%");
+ string where = "`cid`=" + Database.Quote(cid.ToString()) + " AND `path` LIKE '%" + fileName + "'";
+
+ return GetMangas(where);
+ }
+
private static Manga[] GetMangas(string where)
{
string additionalWhere = "`id` IN (SELECT `mid` FROM `meta`)";
@@ -486,6 +495,21 @@ public void Save()
{
Id = Database.InsertAndReturnId("manga", data);
Meta.Save();
+
+ // Check if this manga is moved from another path
+ foreach (Manga manga in Manga.GetSameFileName(ParentCollectionId, MangaPath))
+ {
+ if (manga.Id != Id && manga.ParentCollectionId == ParentCollectionId && manga.Size == Size && manga.NumberOfPages == manga.NumberOfPages && manga.IsFileMissing())
+ {
+ View = manga.View;
+ Title = manga.Title;
+ Meta.Copy(manga.Meta);
+ UpdateTags(manga.GetTags());
+ Save();
+ manga.Delete();
+ break;
+ }
+ }
}
else
{
@@ -510,6 +534,11 @@ public void Save()
}
}
+ public bool IsFileMissing()
+ {
+ return !File.Exists(MangaPath);
+ }
+
public MangaListItemJson ToMangaListItemJson()
{
MangaListItemJson obj = new MangaListItemJson();
View
10 source/aspnetserver/MangaMeta.cs
@@ -137,5 +137,15 @@ public static string[] GetPublishers()
{
return Database.GetDistinctStringValues("meta", "publisher");
}
+
+ public void Copy(MangaMeta other)
+ {
+ Author = other.Author;
+ Volume = other.Volume;
+ Series = other.Series;
+ Year = other.Year;
+ Publisher = other.Publisher;
+ Save();
+ }
}
}
View
28 source/haxe/afung/mangaWeb3/server/Manga.hx
@@ -206,6 +206,15 @@ class Manga
return null;
}
+ private static function GetSameFileName(cid:Int, path:String):Array<Manga>
+ {
+ var fileName:String = Database.Quote(path.substr(path.lastIndexOf("/")));
+ fileName = StringTools.replace(StringTools.replace(fileName.substr(1, fileName.length - 2), "\\", "\\\\"), "%", "\\%");
+ var where:String = "`cid`=" + Database.Quote(Std.string(cid)) + " AND `path` COLLATE utf8_bin LIKE '%" + fileName + "'";
+
+ return GetMangas(where);
+ }
+
private static function GetMangas(where:String):Array<Manga>
{
var additionalWhere:String = "`id` IN (SELECT `mid` FROM `meta`)";
@@ -454,6 +463,20 @@ class Manga
{
Id = Database.InsertAndReturnId("manga", data);
Meta.Save();
+
+ for (manga in Manga.GetSameFileName(ParentCollectionId, MangaPath))
+ {
+ if (manga.Id != Id && manga.ParentCollectionId == ParentCollectionId && manga.Size == Size && manga.NumberOfPages == manga.NumberOfPages && manga.IsFileMissing())
+ {
+ View = manga.View;
+ Title = manga.Title;
+ Meta.Copy(manga.Meta);
+ UpdateTags(manga.GetTags());
+ Save();
+ manga.Delete();
+ break;
+ }
+ }
}
else
{
@@ -477,6 +500,11 @@ class Manga
Database.Replace("mangadimensions", data);
}
}
+
+ public function IsFileMissing():Bool
+ {
+ return !FileSystem.exists(MangaPath);
+ }
public function ToMangaListItemJson():MangaListItemJson
{
View
10 source/haxe/afung/mangaWeb3/server/MangaMeta.hx
@@ -110,4 +110,14 @@ class MangaMeta
{
return Database.GetDistinctStringValues("meta", "publisher");
}
+
+ public function Copy(other:MangaMeta):Void
+ {
+ Author = other.Author;
+ Volume = other.Volume;
+ Series = other.Series;
+ Year = other.Year;
+ Publisher = other.Publisher;
+ Save();
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.