private void AddScreenshots(Model model)
		{
			string dirpath = Server.MapPath(string.Format("~/svn/{0}/{1}", model.User.Login, model.Name));
			if (Directory.Exists(dirpath)) {
				int cnt = 0;
				int len = 5;
				StringBuilder sb = new StringBuilder();


				sb.AppendLine("<table>");
				
				/*string icon = dirpath + "/icon.png";
				if (File.Exists(icon) && new FileInfo(icon).Length > 20000) {
					sb.AppendLine("<tr>");
					string url = string.Format("svn/{0}/{1}/icon.png", model.User.Login, model.Name);
					sb.AppendFormat("<td><a href='{0}'><img src='{0}' class='thumbScreenshot'/></a></td>\n", url);
					cnt++;
				}*/

				
				foreach (string s in Directory.GetFiles(dirpath, "*.jpg")) {
					if (cnt%len == 0) sb.AppendLine("<tr>");

					string url = string.Format("svn/{0}/{1}/{2}", model.User.Login, model.Name, Path.GetFileName(s));

					sb.AppendFormat("<td><a href='{0}'><img src='{0}' class='thumbScreenshot'/></a></td>\n", url);

					if (cnt%len == len - 1) sb.AppendLine("</tr>");
					cnt++;
				}

				if (Directory.Exists(dirpath + "/screenshots")) {
					foreach (string s in Directory.GetFiles(dirpath + "/screenshots")) {
						if (cnt%len == 0) sb.AppendLine("<tr>");

						string url = string.Format("svn/{0}/{1}/screenshots/{2}", model.User.Login, model.Name, Path.GetFileName(s));

						sb.AppendFormat("<td><a href='{0}'><img src='{0}' class='thumbScreenshot'/></a></td>\n", url);

						if (cnt%len == len - 1) sb.AppendLine("</tr>");
						cnt++;
					}
				}
				if (cnt % len != len) sb.AppendLine("</tr>");
				sb.AppendLine("</table>");
				Literal1.Text = sb.ToString();
			}
		}
		private void FillCandidates(Model model)
		{
			StringBuilder sb = new StringBuilder();
			sb.Append("<table><tr>");
			ddCandidates.Items.Clear();
			foreach (Candidate x in model.Candidates) {
				ddCandidates.Items.Add(new ListItem(x.Unit.Game.Shortcut + " "  + x.Unit.Code, x.UnitID.ToString()));
				sb.AppendFormat("<td><a href='UnitDetail.aspx?UnitID={0}'><img src='unitpics/{1}.png'/><br/>{2} {1}</a></td>", x.UnitID, x.Unit.Code, x.Unit.Game.Shortcut);
			}
			sb.Append("</tr></table>");
			litCandidates.Text = sb.ToString();
		}
		private void UpdateLicenseLink(Model model) {
			var lic = Global.Db.Licenses.SingleOrDefault(x => x.LicenseID == int.Parse(ddLicense.SelectedValue));
			if (lic != null) {
				hlLicense.Text = lic.Name;
				string licFile = string.Format("svn/{0}/{1}/license.txt", model.User.Login, model.Name);
				if (File.Exists(Server.MapPath(licFile))) {
					hlLicense.NavigateUrl = licFile;
				} else hlLicense.NavigateUrl = lic.DefaultUrl;
			}
		}
		public void Update()
		{
			bool modelsAdded = false;
			lock (HttpContext.Current.Application) {
                if (true)
                { // hack RunCmd("up svn") > 1 && (ConfigurationManager.AppSettings["BlockSvn"] == null)
					DirectoryInfo root = new DirectoryInfo(repoPath);
					foreach (DirectoryInfo usdir in root.GetDirectories().Where(x => x.Name != ".svn")) {
						User u = Global.Db.Users.SingleOrDefault(x => x.Login == usdir.Name);
						if (u != null) {
							List<string> currentModels = new List<string>();
							foreach (DirectoryInfo modeldir in usdir.GetDirectories().Where(x => x.Name != ".svn")) {
								currentModels.Add(modeldir.Name);

								Model m = u.Models.SingleOrDefault(x => x.Name == modeldir.Name);
								if (m != null) {
									DateTime lastWrite = modeldir.LastWriteTimeUtc;
									foreach (DateTime tim in modeldir.GetFiles().Select(x => x.LastWriteTimeUtc)) if (tim > lastWrite) lastWrite = tim;
									if (Math.Abs(lastWrite.Subtract(m.Modified).TotalMinutes) > 3 || m.IsDeleted) {
										Global.AddEvent(EventType.ModelUpdated, null, null, m.ModelID, null, u.UserID);
										m.Modified = lastWrite;
										m.IsDeleted = false;
										m.UpdateIcon();
										UpdateEvents(m.ModelID);
										Global.Db.SubmitChanges();
									}
								} else {
									m = new Model {AuthorUserID = u.UserID, Name = modeldir.Name, Modified = modeldir.LastWriteTimeUtc};
									modelsAdded = true;
									Global.Db.Models.InsertOnSubmit(m);
									Global.Db.SubmitChanges();
									Global.AddEvent(EventType.ModelAdded, null, null, m.ModelID, null, u.UserID);
									Global.Db.SubmitChanges();
									m.UpdateIcon();
									UpdateEvents(m.ModelID);
									Global.Db.SubmitChanges();
								}

							}

							foreach (Model m in u.Models.Where(x => !x.IsDeleted && !currentModels.Contains(x.Name))) {
								m.IsDeleted = true;
								Global.AddEvent(EventType.ModelDeleted, null, null, m.ModelID, null, u.UserID);
							}

							Global.Db.SubmitChanges();
						}
					}
				}
				if (modelsAdded) new ForumController().MakeModelPosts();
			}
		}