public static string GetInstalledVersion(LoveType type) { if (type == LoveType.Love2D) { var exePath = Path.Combine(Settings.Default.Path_Love, "love.exe"); var version = FileVersionInfo.GetVersionInfo(exePath); return(version.FileVersion); } else if (type == LoveType.Lovr) { var exePath = Path.Combine(Settings.Default.Path_Lovr, "lovr.exe"); var startInfo = new ProcessStartInfo(); startInfo.FileName = exePath; startInfo.Arguments = "--version"; startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; var proc = Process.Start(startInfo); string version = proc.StandardOutput.ReadToEnd(); var match = Regex.Match(version, @"^LOVR ([^\s]+) \(.*\)"); if (!match.Success) { return("???"); } return("v" + match.Groups[1].Value); } return("???"); }
public static bool SetLove(LoveType loveType, ImgInfo info) { try { Picture picModel = db.Queryable <Picture>().Where(o => o.Id == info.Id).First(); Love love = db.Queryable <Love>().Where(o => o.PictureId == info.Id).First(); if (picModel == null || love == null) //目前仅考虑第一次收藏 { SetTagLove(loveType, info); } if (picModel == null) { picModel = ToPicture(info); db.Insertable(picModel).ExecuteCommand(); } love = new Love() { PictureId = info.Id, Time = DateTime.Now, Type = (int)loveType }; db.Saveable(love).ExecuteCommand(); return(true); } catch (Exception ex) { LogHelper.WriteLog(ex.Message, EnumLogLevel.Error); return(false); } }
/// <summary> /// 分页获取收藏(喜欢)的壁纸 /// </summary> /// <param name="loveType"></param> /// <param name="start"></param> /// <param name="count"></param> /// <returns></returns> public static ImageListTotal GetLoveList(LoveType loveType, int start, int count, bool orderDesc = false) { ImageListTotal total = new ImageListTotal(); var query = db.Queryable <Picture, Love>((p, l) => new object[] { JoinType.Inner, p.Id == l.PictureId }) .Where((p, l) => l.Type == (int)loveType) .OrderByIF(!orderDesc, (p, l) => l.Time, OrderByType.Asc) .OrderByIF(orderDesc, (p, l) => l.Time, OrderByType.Desc) .Select((p, l) => new ImgInfo() { class_id = p.Type, id = p.Id.ToString(), url = p.Url, tag = p.Tag }); total.total = query.Count(); total.data = query.Skip(start).Take(count).ToList(); return(total); }
/// <summary> /// 目前仅考虑第一次评分或者第一次收藏 /// </summary> /// <param name="loveType"></param> /// <param name="info"></param> /// <returns></returns> private static bool SetTagLove(LoveType loveType, ImgInfo info) { try { if (loveType == LoveType.Love) { List <string> tags = info.GetTagList(); List <TagRecord> tagRecords = db.Queryable <TagRecord>().Where(o => tags.Contains(o.TagName)).ToList(); foreach (var tag in tags) { if (tag == "全部")//不考虑“全部”标签 { continue; } TagRecord tagRecord = tagRecords.Find(it => it.TagName == tag); if (tagRecord == null) { tagRecord = new TagRecord(); tagRecord.TagName = tag; tagRecord.RecordCount = 1; tagRecord.ScoreSum = 0; db.Insertable(tagRecord).ExecuteCommand(); } else { tagRecord.RecordCount++; db.Updateable(tagRecord).UpdateColumns(o => new { o.RecordCount }).ExecuteCommand(); } } } return(true); } catch (Exception ex) { LogHelper.WriteLog(ex.Message, EnumLogLevel.Error); return(false); } }
public ProjectInfo(string path) { m_path = path.Trim('/', '\\'); var moonFiles = Directory.GetFiles(m_path, "*.moon", SearchOption.AllDirectories); m_moonscript = (moonFiles.Length > 0); var infoPath = GetInfoPath(); if (File.Exists(infoPath)) { Hashtable obj = (Hashtable)Json.JsonDecode(File.ReadAllText(infoPath)); if (obj.ContainsKey("name")) { m_name = (string)obj["name"]; } if (obj.ContainsKey("author")) { m_author = (string)obj["author"]; } if (obj.ContainsKey("bundle-identifier")) { m_bundleIdentifier = (string)obj["bundle-identifier"]; } if (obj.ContainsKey("type")) { m_type = (LoveType)Enum.Parse(typeof(LoveType), (string)obj["type"], true); } if (obj.ContainsKey("love-version")) { m_loveVersion = (string)obj["love-version"]; } if (obj.ContainsKey("icon-file")) { m_iconFile = (string)obj["icon-file"]; } } if (m_name == "") { m_name = Path.GetFileName(m_path); } if (m_author == "") { m_author = "Unknown"; } if (m_bundleIdentifier == "") { m_bundleIdentifier = "com.example.game"; } if (m_loveVersion == "") { m_loveVersion = LoveVersion.GetInstalledVersion(m_type); } }