Exemplo n.º 1
0
    public override void InitPage()
    {
        using (DbManager mgr = new DbManager())
        {
            foreach (Library l in mgr.Query <Library>("SELECT * FROM library WHERE userid = '" + CurrentUser.UserID + "'"))
            {
                existing.Items.Add(new ListItem(l.Name, l.ID.ToString()));
            }
        }


        HttpCookie c = Request.Cookies["edits"];

        if (c != null)
        {
            List <string> list = c.Value.Split(',').ToList();
            if (list.Count == 0)
            {
                warning.Text      += "Your current library is empty.";
                saveButton.Visible = false;
            }

            foreach (string s in list.ToList())
            {
                EditInfo e = new EditInfo();
                if (!e.Load(s.ToInt(), CurrentUser))
                {
                    list.Remove(s);
                    warning.Text   += "Invalid edit id " + s + "<br />";
                    warning.Visible = true;
                    list.Remove(s);
                }

                if (!e.Public)
                {
                    list.Remove(s);
                    warning.Text   += e.Name + " is not public, cannot add to pack. <br />";
                    warning.Visible = true;
                    list.Remove(s);
                }

                if (e.UserID != CurrentUser.UserID)
                {
                    warning.Visible = true;
                    warning.Text   += e.Name + " is not your edit, cannot add to pack. <br />";
                    list.Remove(s);
                }
            }

            c.Value = list.ToDelimitedString(",");
            Context.Response.Cookies.Add(c);
        }
    }
Exemplo n.º 2
0
    public override void InitPage()
    {
        string id   = Request.Params["id"];
        string type = Request.Params["type"];

        string[] s      = type.Split('|');
        string   region = s[0];
        string   format = s[1];

        if (string.IsNullOrEmpty(id))
        {
            HttpCookie c = Request.Cookies["edits"];
            if (c != null)
            {
                ZipFile zFile = new ZipFile();
                foreach (string i in c.Value.Split(','))
                {
                    if (i.IsInt())
                    {
                        EditInfo e = new EditInfo();
                        if (e.Load(i.ToInt(), CurrentUser))
                        {
                            if (!e.Public)
                            {
                                if (CurrentUser != null)
                                {
                                    if (CurrentUser.UserID != e.UserID)
                                    {
                                        continue;
                                    }
                                }
                            }

                            e.Downloads++;
                            e.Save();
                            switch (format)
                            {
                            case "DAT":
                                zFile.AddEntry(e.Name + ".DAT", File.ReadAllBytes(Server.MapPath("/dats/" + region + "/" + e.ID + ".DAT")));
                                break;

                            case "ZIP":
                                zFile.AddEntry(e.Name + ".DAT", File.ReadAllBytes(Server.MapPath("/dats/" + region + "/" + e.ID + ".DAT")));
                                break;

                            case "SM":
                                zFile.AddEntry(e.SongTitle + ".sm", File.ReadAllBytes(Server.MapPath("/sims/" + e.ID + ".sm")));
                                break;
                            }
                        }
                    }
                }

                string fileName = "/temp/" + DateTime.Now.Ticks + ".zip";
                zFile.Save(Server.MapPath(fileName));
                if (format != "DAT")
                {
                    ReturnFile(fileName, region);
                }
                else
                {
                    ReturnFile(WebConverter.ConvertLibrary(Server.MapPath(fileName), region == "U" ? 1 : 2), region);
                }
                return;
            }
        }
        else
        {
            Library l = new Library();
            l.Load(id.ToInt());
            ZipFile zFile = new ZipFile();
            foreach (int i in l.EditList)
            {
                EditInfo e = new EditInfo();
                if (e.Load(i, CurrentUser))
                {
                    if (!e.Public)
                    {
                        if (CurrentUser != null)
                        {
                            if (CurrentUser.UserID != e.UserID)
                            {
                                continue;
                            }
                        }
                    }

                    switch (format)
                    {
                    case "DAT":
                        zFile.AddEntry(e.Name + ".DAT", File.ReadAllBytes(Server.MapPath("/dats/" + region + "/" + e.ID + ".DAT")));
                        break;

                    case "ZIP":
                        zFile.AddEntry(e.Name + ".DAT", File.ReadAllBytes(Server.MapPath("/dats/" + region + "/" + e.ID + ".DAT")));
                        break;

                    case "SM":
                        zFile.AddEntry(e.SongTitle + ".sm", File.ReadAllBytes(Server.MapPath("/sims/" + e.ID + ".sm")));
                        break;
                    }
                }
            }

            string fileName = "/temp/" + DateTime.Now.Ticks + ".zip";
            zFile.Save(Server.MapPath(fileName));
            if (format != "DAT")
            {
                ReturnFile(fileName, region);
            }
            else
            {
                ReturnFile(WebConverter.ConvertLibrary(Server.MapPath(fileName), region == "U" ? 1 : 2), region);
            }
        }

        message.Text = "Invalid file request.";
    }