public ActionResult Image(string filename)
        {
            var _client = new DropNetClient(accessKey, secretAccessKey, userTokenKey, userSecretKey);
            var file = _client.GetFile("/Public/Images/" + filename);

            return File(file, Common.GetMimeType(filename));
        }
Ejemplo n.º 2
0
        private void getButton_Click(object sender, RoutedEventArgs e)
        {
            var d = new FolderBrowserDialog();

            if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                byte[] data = _client.GetFile(getText.Text);
                File.WriteAllBytes(System.IO.Path.Combine(d.SelectedPath, getText.Text), data);
            }
        }
        public string DownloadSerializationAsset(string tagName)
        {
            var client = new DropNetClient(_dropBoxSettings.ApiKey, _dropBoxSettings.ApiSecret, _dropBoxSettings.AccessToken);
            client.UseSandbox = true;
            string artifactPath = String.Format("/Artifacts/{0}/{1}", tagName, ZIP_FILE_NAME);
            var file = client.GetFile(artifactPath);
            string tempFile = Directory.GetCurrentDirectory() + "\\" + ZIP_FILE_NAME;
            File.WriteAllBytes(tempFile, file);

            return tempFile;
        }
        //
        // GET: /DropBox/
        public ActionResult File(string id)
        {
            string filename = db.Files.Where(e => e.Location == id).Select(e => e.Name).FirstOrDefault();

            if (string.IsNullOrEmpty(filename))
                return Content("");

            var _client = new DropNetClient(accessKey, secretAccessKey, userTokenKey, userSecretKey);
            var file = _client.GetFile("/Public/Files/" + filename);

            Response.AddHeader("Content-Disposition", "attachment; filename=\""+ filename +"\"");

            return File(file, Common.GetMimeType(filename));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Download user's all the sharing-info files
        /// </summary>
        /// <param pathFullName="userID">user's dropbox id</param>
        /// <returns></returns>
        public List <SharingInfo> Download(String userID)
        {
            String             sharingFileDir  = String.Format("/{0}", userID);
            StringBuilder      sharingFilePath = new StringBuilder();
            MetaData           metadatas       = this.Client.GetMetaData(sharingFileDir, false, false);
            List <SharingInfo> sharingInfoList = new List <SharingInfo>();

            if (metadatas != null)
            {
                foreach (MetaData sharingFile in metadatas.Contents)
                {
                    if (sharingFile.Name == PKM.PKFileName)
                    {
                        continue;
                    }
                    sharingFilePath.Clear();
                    String sharingFileDropboxPath = sharingFilePath.AppendFormat("{0}/{1}", sharingFileDir, sharingFile.Name).ToString();
                    try
                    {
                        Byte[]   sharingInfoBytes;// = this.Client.Download( sharingFileDropboxPath );
                        MetaData files = this.Client.GetMetaData(sharingFileDropboxPath, false, false);
                        if (files == null || files.Is_Dir == true ||
                            files.Is_Deleted || files.Bytes == 0)
                        {
                            sharingInfoBytes = null;
                        }
                        else
                        {
                            sharingInfoBytes = Client.GetFile(sharingFileDropboxPath);
                            MemoryStream    ms   = new MemoryStream(sharingInfoBytes);
                            BinaryFormatter bfer = new BinaryFormatter();
                            sharingInfoList.Add((SecuruStik.Protocal.SharingInfo)bfer.Deserialize(ms));

                            Client.Delete(sharingFileDropboxPath);
                        }
                    }
                    catch (System.Exception) { }
                }
            }
            return(sharingInfoList);
        }
Ejemplo n.º 6
0
        public static void filesync()
        {
            //Testing Connection

            if (!LauncherHelper.TestConnection())
                return;

            if (String.IsNullOrEmpty(Properties.Settings.Default.DropBoxUserToken))
            {

                syncAcc(false);

            }

            DropNetClient dbClient = new DropNetClient(Program.Config.AppKey, Program.Config.AppSecret, Properties.Settings.Default.DropBoxUserToken, Properties.Settings.Default.DropBoxUserSecret);

            #if DEBUG
            dbClient.UseSandbox = true;
            #endif

            DropNet.Models.MetaData meta;

            try
            {
                meta = dbClient.GetMetaData("/");
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.StackTrace + "\n maybe your account is not in the Dropbox Dev group for this App");
                return;
            }

            List<string> filelist = new List<string>();

            if (!Directory.Exists(Program.Config.LauncherDir + "/deck/"))
            {
                Directory.CreateDirectory(Program.Config.LauncherDir + "/deck/");
            }

            if (!Directory.Exists(Program.Config.LauncherDir + "/replay/"))
            {
                Directory.CreateDirectory(Program.Config.LauncherDir + "/replay/");
            }

            foreach (string item in Directory.GetFiles(Program.Config.LauncherDir + "/deck/"))
            {
                filelist.Add(item);
            }

            foreach (string item in Directory.GetFiles(Program.Config.LauncherDir + "/replay/"))
            {
                filelist.Add(item);
            }

            foreach (DropNet.Models.MetaData file in meta.Contents)
            {

                if (Path.GetExtension(file.Name) == ".ydk")
                {

                    if (File.Exists(Program.Config.LauncherDir + "/deck/" + file.Name))
                    {
                        if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + "/deck/" + file.Name)) < 0)
                        {
                            FileStream fs = new FileStream(Program.Config.LauncherDir + "/deck/" + file.Name, FileMode.Create);
                            fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                            fs.Close();
                        }
                        else if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + "/deck/" + file.Name)) > 0)
                        {
                            FileStream fs = File.OpenRead(Program.Config.LauncherDir + "/deck/" + file.Name);
                            byte[] upfile = new byte[fs.Length];
                            fs.Read(upfile, 0, upfile.Length);
                            fs.Close();
                            dbClient.UploadFile("/", file.Name, upfile);
                        }
                    }
                    else
                    {
                        FileStream fs = new FileStream(Program.Config.LauncherDir + "/deck/" + file.Name, FileMode.Create);
                        fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                        fs.Close();
                    }

                }
                else if (Path.GetExtension(file.Name) == ".yrp")
                {

                    if (File.Exists(Program.Config.LauncherDir + "/replay/" + file.Name))
                    {
                        if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + "/deck/" + file.Name)) < 0)
                        {
                            FileStream fs = new FileStream(Program.Config.LauncherDir + "/replay/" + file.Name, FileMode.Create);
                            fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                            fs.Close();
                        }
                        else if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + "/deck/" + file.Name)) > 0)
                        {
                            FileStream fs = File.OpenRead(Program.Config.LauncherDir + "/replay/" + file.Name);
                            byte[] upfile = new byte[fs.Length];
                            fs.Read(upfile, 0, upfile.Length);
                            fs.Close();
                            dbClient.UploadFile("/", file.Name, upfile);
                        }
                    }
                    else
                    {
                        FileStream fs = new FileStream(Program.Config.LauncherDir + "/replay/" + file.Name, FileMode.Create);
                        fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                        fs.Close();
                    }

                }

            }

            if (filelist.Count > meta.Contents.Count)
            {
                foreach (string file in filelist)
                {
                    if (Path.GetExtension(file) == ".ydk")
                    {
                        FileStream fs = File.OpenRead(Program.Config.LauncherDir + "/deck/" + Path.GetFileName(file));
                        byte[] upfile = new byte[fs.Length];
                        fs.Read(upfile, 0, upfile.Length);
                        fs.Close();
                        dbClient.UploadFile("/", Path.GetFileName(file), upfile);
                    }
                    else if (Path.GetExtension(file) == ".yrp")
                    {
                        FileStream fs = File.OpenRead(Program.Config.LauncherDir + "/replay/" + Path.GetFileName(file));
                        byte[] upfile = new byte[fs.Length];
                        fs.Read(upfile, 0, upfile.Length);
                        fs.Close();
                        dbClient.UploadFile("/", Path.GetFileName(file), upfile);
                    }

                }

            }

            //MessageBox.Show("yeah!!");
        }
        private FileContentResult CreateBigThumbNail(int newWidth, string path)
        {
            var _client = new DropNetClient(accessKey, secretAccessKey, userTokenKey, userSecretKey);
            var _file = _client.GetFile(path);
            MemoryStream myStream = new MemoryStream();
            myStream.Write(_file, 0, _file.Length);
            using (Bitmap originalImage = new Bitmap(myStream))
            {
                int width = newWidth;
                int height = (originalImage.Height * newWidth) / originalImage.Width;
                Bitmap thumbnail = new Bitmap(width, height);
                using (Graphics g = Graphics.FromImage((System.Drawing.Image)thumbnail))
                    g.DrawImage(originalImage, 0, 0, width, height);

                ImageConverter converter = new ImageConverter();
                return File((byte[])converter.ConvertTo(thumbnail, typeof(byte[])), Common.GetMimeType(path));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// This method does all the dirty work for you (syncs any folder with db)
        /// </summary>
        /// <param name="folder">the folder you want to sync</param>
        private static void syncFolder(string folder)
        {
            DropNetClient dbClient = new DropNetClient(Program.Config.AppKey, Program.Config.AppSecret, Properties.Settings.Default.DropBoxUserToken, Properties.Settings.Default.DropBoxUserSecret);

            #if DEBUG
            dbClient.UseSandbox = true;
            Program.Config.LauncherDir = "C:/Program Files (x86)/DevPro/";
            #endif

            DropNet.Models.MetaData meta;

            try
            {

                meta = dbClient.GetMetaData("/" + folder);
            }
            catch (Exception exc)
            {
                try
                {
                    dbClient.CreateFolder("/" + folder);
                    meta = dbClient.GetMetaData("/" + folder);
                }
                catch (Exception)
                {
                    MessageBox.Show(exc.StackTrace + "\n maybe your account is not in the Dropbox Dev group for this App");
                    return;
                }

            }

            List<string> filelist = new List<string>();
            List<string> dirlist = new List<string>();
            //Program.Config.LauncherDir + "/" +
            if (!Directory.Exists(Program.Config.LauncherDir + folder))
            {
                Directory.CreateDirectory(Program.Config.LauncherDir + folder);
            }

            foreach (string item in Directory.GetFiles(Program.Config.LauncherDir + folder))
            {
                filelist.Add(item);
            }

            foreach (string item in Directory.GetDirectories(Program.Config.LauncherDir + folder))
            {
                dirlist.Add(item);
            }

            if (filelist.Count == 0 && dirlist.Count != 0)
            {
                foreach (string item in dirlist)
                {
                    syncFolder(folder + Path.GetFileNameWithoutExtension(item) + "/");
                    return;
                }
            }

            foreach (DropNet.Models.MetaData file in meta.Contents)
            {

                if (File.Exists(Program.Config.LauncherDir + folder + file.Name))
                {
                    if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + folder + file.Name)) < 0)
                    {
                        FileStream fs = new FileStream(Program.Config.LauncherDir + folder + file.Name, FileMode.Create);
                        fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                        fs.Close();
                    }
                    else if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + folder + file.Name)) > 0)
                    {
                        FileStream fs = File.OpenRead(Program.Config.LauncherDir + folder + file.Name);
                        byte[] upfile = new byte[fs.Length];
                        fs.Read(upfile, 0, upfile.Length);
                        fs.Close();
                        dbClient.UploadFile("/" + folder, file.Name, upfile);
                    }
                }
                else
                {
                    FileStream fs = new FileStream(Program.Config.LauncherDir + folder + file.Name, FileMode.Create);
                    fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                    fs.Close();
                }

            }

            if (filelist.Count + dirlist.Count > meta.Contents.Count)
            {

                foreach (string file in filelist)
                {

                    FileStream fs = File.OpenRead(Program.Config.LauncherDir + folder + Path.GetFileName(file));
                    byte[] upfile = new byte[fs.Length];
                    fs.Read(upfile, 0, upfile.Length);
                    fs.Close();
                    dbClient.UploadFile("/" + folder, Path.GetFileName(file), upfile);

                }
            }
        }