예제 #1
0
        public string method_0(string originalPath)
        {
            StringBuilder stringBuilder = new StringBuilder(512);
            int           capacity      = stringBuilder.Capacity;

            if (originalPath.Length > 2 && originalPath[1] == ':')
            {
                char chr = originalPath[0];
                if ((chr >= 'a' && chr <= 'z' || chr >= 'A' && chr <= 'Z') && Upload.WNetGetConnection(originalPath.Substring(0, 2), stringBuilder, ref capacity) == 0)
                {
                    DirectoryInfo directoryInfo = new DirectoryInfo(originalPath);
                    string        str           = Path.GetFullPath(originalPath).Substring(Path.GetPathRoot(originalPath).Length);
                    return(Path.Combine(stringBuilder.ToString().TrimEnd(new char[0]), str));
                }
            }
            return(originalPath);
        }
예제 #2
0
        private void RunUpload()
        {
            this.Filter = string.Empty;
            using (RPM_FileExt rPMFileExt = new RPM_FileExt())
            {
                List <FileExt> fileExtensions = rPMFileExt.GetFileExtensions();
                int            num2           = 0;
                if (fileExtensions.Count <= 0)
                {
                    this.Filter = ".DAT,.GPS,.EXIF";
                }
                else
                {
                    foreach (FileExt fileExtension in fileExtensions)
                    {
                        if (num2 <= 0)
                        {
                            Upload upload1 = this;
                            upload1.Filter = string.Concat(upload1.Filter, fileExtension.Ext);
                        }
                        else
                        {
                            Upload upload2 = this;
                            upload2.Filter = string.Concat(upload2.Filter, ",", fileExtension.Ext);
                        }
                        num2++;
                    }
                }
                if (!this.Filter.Contains(".GPS"))
                {
                    Upload upload3 = this;
                    upload3.Filter = string.Concat(upload3.Filter, ",.GPS");
                }
                if (!this.Filter.Contains(".DAT"))
                {
                    Upload upload4 = this;
                    upload4.Filter = string.Concat(upload4.Filter, ",.DAT");
                }
                if (!this.Filter.Contains(".EXIF"))
                {
                    Upload upload5 = this;
                    upload5.Filter = string.Concat(upload5.Filter, ",.EXIF");
                }
            }
            if (this.FileNames == null)
            {
                if (string.IsNullOrEmpty(this.SourcePath))
                {
                    return;
                }
                this.fileEntries = Directory.GetFiles(this.SourcePath);
            }
            else if ((int)this.FileNames.Length > 0)
            {
                this.fileEntries = this.FileNames;
            }
            this.FileList.Clear();
            string[] strArrays  = this.Filter.Split(new char[] { ',' });
            string[] strArrays1 = this.fileEntries;
            for (int i = 0; i < (int)strArrays1.Length; i++)
            {
                string str   = strArrays1[i];
                bool   flag  = false;
                string upper = Path.GetExtension(str).ToUpper();
                if ((int)strArrays.Length > 0)
                {
                    string[] strArrays2 = strArrays;
                    int      num3       = 0;
                    while (num3 < (int)strArrays2.Length)
                    {
                        string str1 = strArrays2[num3];
                        if (string.IsNullOrEmpty(str1) || !upper.Equals(str1.ToUpper()))
                        {
                            num3++;
                        }
                        else
                        {
                            flag = true;
                            goto Label0;
                        }
                    }
                }
Label0:
                if (!flag)
                {
                    this.FileList.Add(str, false);
                }
            }
            HashAlgorithm sHA1 = HashAlgorithms.SHA1;

            switch (Global.DefaultHashAlgorithm)
            {
            case HASH_ALGORITHM.MD5:
            {
                sHA1 = HashAlgorithms.MD5;
                break;
            }

            case HASH_ALGORITHM.SHA1:
            {
                sHA1 = HashAlgorithms.SHA1;
                break;
            }

            case HASH_ALGORITHM.SHA256:
            {
                sHA1 = HashAlgorithms.SHA256;
                break;
            }

            case HASH_ALGORITHM.SHA384:
            {
                sHA1 = HashAlgorithms.SHA384;
                break;
            }

            case HASH_ALGORITHM.SHA512:
            {
                sHA1 = HashAlgorithms.SHA512;
                break;
            }

            case HASH_ALGORITHM.RIPEMD160:
            {
                sHA1 = HashAlgorithms.RIPEMD160;
                break;
            }
            }
            this.progBar.Maximum = this.FileList.Count;
            Image thumbnailImage = Resources.folder;

            this.i = 0;
            foreach (KeyValuePair <string, bool> fileList in this.FileList)
            {
                string   key      = fileList.Key;
                FileInfo fileInfo = new FileInfo(key);
                base.BeginInvoke(new MethodInvoker(() => {
                    try
                    {
                        vProgressBar u003cu003e4_this = this.progBar;
                        Upload upload          = this;
                        int num                = upload.i + 1;
                        int num1               = num;
                        upload.i               = num;
                        u003cu003e4_this.Value = num1;
                        this.lblStatus.Text    = "Uploading...";
                        this.lblFileCount.Text = string.Format("{0} of {1}", this.i, this.FileList.Count);
                        this.lblFileName.Text  = string.Format("{0} • {1}", Path.GetFileName(fileList.Key), Utilities.BytesToString(fileInfo.Length));
                    }
                    catch (Exception exception)
                    {
                        this.CancelFlag = true;
                    }
                }));
                if (!File.Exists(key))
                {
                    continue;
                }
                FileData fileDatum = new FileData();
                try
                {
                    string extension = Path.GetExtension(key);
                    if (!this.IsRawName)
                    {
                        fileDatum.FileName = Guid.NewGuid().ToString();
                    }
                    else
                    {
                        fileDatum.FileName = Path.GetFileNameWithoutExtension(key);
                    }
                    fileDatum.OriginalFileName = Path.GetFileNameWithoutExtension(key);
                    fileDatum.FileExt          = extension;
                    fileDatum.FileHashCode     = "Pending...";
                    fileDatum.FileSize         = fileInfo.Length;
                    fileDatum.FileTimestamp    = fileInfo.LastWriteTime;
                    this.TimeStamp             = fileDatum.FileTimestamp.ToString();
                    fileDatum.Server           = this.Server;
                    fileDatum.RelativePath     = this.RelativePath;
                    fileDatum.IsDat            = fileList.Value;
                    MemoryStream memoryStream = new MemoryStream();
                    (new FFMpegConverter()).GetVideoThumbnail(key, memoryStream);
                    Image image = Image.FromStream(memoryStream);
                    thumbnailImage       = image.GetThumbnailImage(220, 130, null, IntPtr.Zero);
                    this.picBox.SizeMode = PictureBoxSizeMode.StretchImage;
                    this.picBox.Image    = (Image)thumbnailImage.Clone();
                    fileDatum.Thumbnail  = (Image)thumbnailImage.Clone();
                }
                catch (Exception exception1)
                {
                    string upper1 = Path.GetExtension(key).ToUpper();
                    string str2   = upper1;
                    if (upper1 != null)
                    {
                        switch (str2)
                        {
                        case ".WAV":
                        {
                            fileDatum.Thumbnail  = Utilities.resizeImage(48, 48, Resources.audio);
                            this.picBox.SizeMode = PictureBoxSizeMode.CenterImage;
                            this.picBox.Image    = fileDatum.Thumbnail;
                            goto Label1;
                        }

                        case ".JPG":
                        case ".BMP":
                        case ".GIF":
                        case ".TIF":
                        case ".PNG":
                        {
                            Image image1 = Image.FromFile(key);
                            fileDatum.Thumbnail  = image1.GetThumbnailImage(220, 130, null, IntPtr.Zero);
                            this.picBox.SizeMode = PictureBoxSizeMode.StretchImage;
                            this.picBox.Image    = fileDatum.Thumbnail;
                            goto Label1;
                        }
                        }
                    }
                    Icon winLogo = SystemIcons.WinLogo;
                    fileDatum.Thumbnail  = Utilities.resizeImage(48, 48, Icon.ExtractAssociatedIcon(key).ToBitmap());
                    this.picBox.SizeMode = PictureBoxSizeMode.CenterImage;
                    this.picBox.Image    = fileDatum.Thumbnail;
                    //TODO : goto
                    Label1 :;
                }
                this.picBox.Invalidate();
                string str3 = Path.Combine(this.TargetPath, string.Concat(fileDatum.FileName, fileDatum.FileExt));
                this.Callback(this, new CmdEventArgs(fileDatum));
                string str4 = str3;
                try
                {
                    if (!File.Exists(str3))
                    {
                        this.progFile.Value = 0;
                        this.progFile.Text  = string.Empty;
                        this.FileCount++;
                        this.CopyFileWithProgress(key, str3);
                        string   empty      = string.Empty;
                        string[] strArrays3 = strArrays;
                        for (int j = 0; j < (int)strArrays3.Length; j++)
                        {
                            string str5 = strArrays3[j];
                            string str6 = Path.Combine(Path.GetDirectoryName(key), string.Concat(Path.GetFileNameWithoutExtension(key), str5));
                            if (File.Exists(str6))
                            {
                                this.progFile.Value = 0;
                                this.progFile.Text  = string.Empty;
                                base.BeginInvoke(new MethodInvoker(() => this.lblFileName.Text = Path.GetFileName(Path.GetFileName(str6))));
                                str3  = Path.Combine(this.TargetPath, string.Concat(fileDatum.FileName, str5));
                                empty = str5;
                                this.SourceFileName = str6;
                                this.TargetFileName = str3;
                                this.CopyFileWithProgress(str6, str3);
                            }
                        }
                        FileInfo fileInfo1 = new FileInfo(str4);
                        if (!(fileDatum.FileSize != fileInfo1.Length | this.CancelFlag))
                        {
                            using (RPM_DataFile rPMDataFile = new RPM_DataFile())
                            {
                                DataFile dataFile = new DataFile()
                                {
                                    AccountId          = this.AccountID,
                                    Classification     = "Unclassified",
                                    FileAddedTimestamp = new DateTime?(DateTime.Now),
                                    FileExtension      = fileDatum.FileExt,
                                    FileExtension2     = empty,
                                    HashAlgorithm      = Global.DefaultHashAlgorithm,
                                    FileHashCode       = Hash.GetHashFromFile(str3, sHA1),
                                    FileSize           = fileDatum.FileSize,
                                    FileTimestamp      = new DateTime?(fileDatum.FileTimestamp),
                                    GPS              = "",
                                    IsEncrypted      = new bool?(false),
                                    IsPurged         = new bool?(false),
                                    OriginalFileName = fileDatum.OriginalFileName,
                                    PurgeFileName    = "",
                                    Rating           = 0,
                                    Security         = SECURITY.UNCLASSIFIED,
                                    SetName          = ""
                                };
                                if (!string.IsNullOrEmpty(this.SETID))
                                {
                                    dataFile.SetName = this.SETID;
                                    object[] originalFileName = new object[] { dataFile.OriginalFileName, fileDatum.FileName, dataFile.FileExtension, this.SETID };
                                    Global.Log("SET COPY", string.Format("Copy File: {0} -> {1}{2} into SET ID {3}", originalFileName));
                                }
                                dataFile.ShortDesc      = string.Concat(fileDatum.OriginalFileName, fileDatum.FileExt);
                                dataFile.StoredFileName = fileDatum.FileName;
                                dataFile.Thumbnail      = Utilities.ImageToByte(fileDatum.Thumbnail);
                                dataFile.TrackingID     = Guid.Empty;
                                dataFile.UNCName        = this.UNCRoot;
                                dataFile.UNCPath        = this.DataPath;
                                dataFile.MachineName    = this.MachineName;
                                dataFile.MachineAccount = this.MachineAccount;
                                dataFile.UserDomain     = this.MachineDomain;
                                dataFile.SourcePath     = Path.GetDirectoryName(key);
                                //TODO: Метод был изменен на свойство
                                dataFile.LoginID = Global.LoginIDName;
                                rPMDataFile.SaveUpdate(dataFile);
                                rPMDataFile.Save();
                            }
                        }
                        else
                        {
                            Global.Log("UPLOAD_FAIL", string.Format("Upload failed for {0} / Cancel upload.", this.SourceFileName));
                            if (File.Exists(str3))
                            {
                                File.Delete(str3);
                            }
                        }
                    }
                }
                catch
                {
                }
                Thread.Sleep(250);
                if (this.CancelFlag)
                {
                    break;
                }
            }
            base.BeginInvoke(new MethodInvoker(() => {
                try
                {
                    this.ShowTimestamp    = false;
                    this.lblFileName.Text = string.Empty;
                    this.picBox.Image     = Resources.check64;
                    this.lblStatus.Text   = "Upload Complete";
                    this.lblFileName.Text = string.Empty;
                    this.progFile.Value   = 0;
                    this.progBar.Value    = 0;
                    this.progFile.Invalidate();
                    this.progBar.Invalidate();
                    this.UploadCompleteCallback();
                }
                catch (Exception exception)
                {
                    this.UploadCompleteCallback();
                }
            }));
        }