예제 #1
0
        /// <summary>
        /// It collect the uploadable files into param  GDUploader variable and
        /// it collect the unnecessary files into global deletableFiles variable.
        /// </summary>
        /// <param name="uploader"></param>
        /// <param name="localFolder"></param>
        /// <param name="driveFolder"></param>
        private void CollectUpSynchronizerData(GDUploader uploader, string localFolder, string driveFolder)
        {
            string parentId = ConvertGDFolderToGDParentId(driveFolder);
            List <Google.Apis.Drive.v3.Data.File> unnecessaryFiles = getGDFiles(parentId).ToList();
            List <string> files = getLocalFiles(localFolder);

            foreach (string path in files)
            {
                if (!exceptionLocalFiles.Contains(path))
                {
                    string fileName = GetFileName(path);
                    Google.Apis.Drive.v3.Data.File gDFile;

                    if (Directory.Exists(path))
                    {
                        gDFile = searchGDFile(unnecessaryFiles, fileName);
                        if (gDFile != null && gDFile.MimeType == "application/vnd.google-apps.folder")
                        {
                            unnecessaryFiles.Remove(gDFile);
                        }

                        CollectUpSynchronizerData(uploader, path, driveFolder + "\\" + fileName);
                    }
                    else
                    {
                        gDFile = searchGDFile(unnecessaryFiles, fileName + ".zip");

                        if (gDFile != null && System.IO.File.GetLastWriteTime(path) <= gDFile.ModifiedTime.Value)
                        {
                            unnecessaryFiles.Remove(gDFile);
                        }
                        else
                        {
                            string zipFile = path + ".zip";
                            using (ZipFile zip = new ZipFile(zipFile))
                            {
                                zip.Password = zipPassword;
                                zip.AddFile(path, "");
                                zip.Save();

                                uploader.Add(new UploadableFile(zipFile, driveFolder));
                            }
                        }
                    }
                }
            }

            foreach (Google.Apis.Drive.v3.Data.File unnecessaryFile in unnecessaryFiles)
            {
                AddToDeletableFile(unnecessaryFile.Id);
            }
        }
예제 #2
0
        /// <summary>
        /// It collect the uploadable files into param  GDUploader variable and
        /// it collect the unnecessary files into global deletableFiles variable.
        /// </summary>
        /// <param name="uploader"></param>
        /// <param name="localFolder"></param>
        /// <param name="driveFolder"></param>
        private void CollectUpSynchronizerData(GDUploader uploader, string localFolder, IEnumerable <string> localFiles, string driveFolder)
        {
            foreach (string path in localFiles)
            {
                if (!exceptionLocalFiles.Contains(path) && path.StartsWith(localFolder))
                {
                    string currentDrivePath = driveFolder + path.Substring(localFolder.Length);

                    if (Directory.Exists(path))
                    {
                        CollectUpSynchronizerData(uploader, path, currentDrivePath);
                    }
                    else
                    {
                        string currentDriveFolder = currentDrivePath.Substring(0, currentDrivePath.LastIndexOf('\\'));
                        string parentId           = ConvertGDFolderToGDParentId(currentDriveFolder);
                        string fileName           = GetFileName(path);

                        if (parentId != null)
                        {
                            string fileId = GetGDFileId(fileName + ".zip", parentId);

                            if (fileId != null)
                            {
                                AddToDeletableFile(fileId);
                            }
                        }

                        string zipFile = path + ".zip";
                        using (ZipFile zip = new ZipFile(zipFile))
                        {
                            zip.Password = zipPassword;
                            zip.AddFile(path, "");
                            zip.Save();

                            uploader.Add(new UploadableFile(zipFile, currentDriveFolder));
                        }
                    }
                }
            }
        }