CopyFolder() публичный статический Метод

public static CopyFolder ( string sourceFolder, string destFolder ) : void
sourceFolder string
destFolder string
Результат void
Пример #1
0
        private bool Save()
        {
            if (!CheckStep1())
            {
                return(false);
            }

            string err = "";

            int nosoundinterval;

            if (!int.TryParse(txtNoSound.Text, out nosoundinterval))
            {
                err += LocRm.GetString("Validate_Microphone_NoSound") + Environment.NewLine;
            }
            int soundinterval;

            if (!int.TryParse(txtSound.Text, out soundinterval))
            {
                err += LocRm.GetString("Validate_Microphone_Sound") + Environment.NewLine;
            }


            if (txtBuffer.Text.Length < 1 || txtInactiveRecord.Text.Length < 1 ||
                txtMaxRecordTime.Text.Length < 1)
            {
                err += LocRm.GetString("Validate_Camera_RecordingSettings") + Environment.NewLine;
            }

            if (err != "")
            {
                MessageBox.Show(err, LocRm.GetString("Error"));
                return(false);
            }


            VolumeLevel.Micobject.settings.buffer         = Convert.ToInt32(txtBuffer.Value);
            VolumeLevel.Micobject.recorder.inactiverecord = Convert.ToInt32(txtInactiveRecord.Value);
            VolumeLevel.Micobject.recorder.maxrecordtime  = Convert.ToInt32(txtMaxRecordTime.Value);

            VolumeLevel.Micobject.name = txtMicrophoneName.Text.Trim();

            VolumeLevel.Micobject.alerts.active = chkSound.Checked;

            VolumeLevel.Micobject.alerts.mode = "sound";
            if (rdoNoMovement.Checked)
            {
                VolumeLevel.Micobject.alerts.mode = "nosound";
            }
            VolumeLevel.Micobject.detector.nosoundinterval = nosoundinterval;
            VolumeLevel.Micobject.detector.soundinterval   = soundinterval;

            VolumeLevel.Micobject.schedule.active = chkSchedule.Checked;
            VolumeLevel.Micobject.width           = VolumeLevel.Width;
            VolumeLevel.Micobject.height          = VolumeLevel.Height;

            VolumeLevel.Micobject.settings.active         = chkActive.Checked;
            VolumeLevel.Micobject.detector.recordondetect = rdoRecordDetect.Checked;
            VolumeLevel.Micobject.detector.recordonalert  = rdoRecordAlert.Checked;
            VolumeLevel.Micobject.recorder.minrecordtime  = (int)numMinRecord.Value;

            VolumeLevel.Micobject.settings.accessgroups = txtAccessGroups.Text;
            VolumeLevel.Micobject.settings.messaging    = chkMessaging.Checked;


            if (txtDirectory.Text.Trim() == "")
            {
                txtDirectory.Text = MainForm.RandomString(5);
            }

            var md     = (ListItem)ddlMediaDirectory.SelectedItem;
            var newind = Convert.ToInt32(md.Value);

            string olddir = Helper.GetMediaDirectory(1, VolumeLevel.Micobject.id) + "video\\" + VolumeLevel.Micobject.directory + "\\";

            bool needsFileRefresh = (VolumeLevel.Micobject.directory != txtDirectory.Text || VolumeLevel.Micobject.settings.directoryIndex != newind);

            int tempidx = VolumeLevel.Micobject.settings.directoryIndex;

            VolumeLevel.Micobject.settings.directoryIndex = newind;

            string newdir = Helper.GetMediaDirectory(1, VolumeLevel.Micobject.id) + "video\\" + txtDirectory.Text + "\\";

            if (IsNew)
            {
                try
                {
                    if (!Directory.Exists(newdir))
                    {
                        Directory.CreateDirectory(newdir);
                    }
                    else
                    {
                        switch (
                            MessageBox.Show(this,
                                            LocRm.GetString("Validate_Directory_Exists"),
                                            LocRm.GetString("Confirm"), MessageBoxButtons.YesNoCancel))
                        {
                        case DialogResult.Yes:
                            Directory.Delete(newdir, true);
                            Directory.CreateDirectory(newdir);
                            break;

                        case DialogResult.Cancel:
                            VolumeLevel.Micobject.settings.directoryIndex = tempidx;
                            return(false);

                        case DialogResult.No:
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, LocRm.GetString("Validate_Directory_String") + Environment.NewLine + ex.Message);
                    VolumeLevel.Micobject.settings.directoryIndex = tempidx;
                    return(false);
                }
            }
            else
            {
                if (newdir != olddir)
                {
                    try
                    {
                        if (!Directory.Exists(newdir))
                        {
                            if (Directory.Exists(olddir))
                            {
                                Helper.CopyFolder(olddir, newdir);
                            }
                            else
                            {
                                Directory.CreateDirectory(newdir);
                            }
                        }
                        else
                        {
                            switch (
                                MessageBox.Show(this,
                                                LocRm.GetString("Validate_Directory_Exists"),
                                                LocRm.GetString("Confirm"), MessageBoxButtons.YesNoCancel))
                            {
                            case DialogResult.Yes:
                                if (Directory.Exists(olddir))
                                {
                                    Helper.CopyFolder(olddir, newdir);
                                }
                                else
                                {
                                    Directory.Delete(newdir, true);
                                    Directory.CreateDirectory(newdir);
                                }
                                break;

                            case DialogResult.Cancel:
                                VolumeLevel.Micobject.settings.directoryIndex = tempidx;
                                return(false);

                            case DialogResult.No:
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, LocRm.GetString("Validate_Directory_String") + Environment.NewLine + ex.Message);
                        VolumeLevel.Micobject.settings.directoryIndex = tempidx;
                        return(false);
                    }
                }
            }


            VolumeLevel.Micobject.directory        = txtDirectory.Text;
            VolumeLevel.Micobject.recorder.trigger = ((ListItem)ddlTriggerRecording.SelectedItem).Value;

            SetStorageManagement();

            MainForm.NeedsSync = true;

            if (needsFileRefresh)
            {
                VolumeLevel.GenerateFileList();
                MainForm.NeedsMediaRebuild = true;
                MainForm.NeedsMediaRefresh = Helper.Now;
            }
            return(true);
        }