Exemplo n.º 1
0
        public static bool archiveCompetition()
        {
            string archiveDirectory = DataManager.getAbsolutePath(DataManager.Settings.ArchiveDirectory);

            if (!Directory.Exists(archiveDirectory))
            {
                Directory.CreateDirectory(archiveDirectory);
            }

            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.InitialDirectory = archiveDirectory;
            dlg.FileName         = Competition.Name;
            dlg.DefaultExt       = ".comp";
            dlg.Filter           = "Competition File (*.comp)|*.comp";

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                FileInfo saveFile = new FileInfo(dlg.FileName);
                string   fileName = saveFile.Name.Substring(0, saveFile.Name.IndexOf(saveFile.Extension));

                Competition oldComp = _competition;
                oldComp.Name = fileName;
                oldComp.Save();
                _competition = new Competition();
                triggerCompetitionChanged();

                string tempFolder = saveFile.Directory + @"\" + fileName;
                if (Directory.Exists(tempFolder))
                {
                    Directory.Delete(tempFolder, true);
                }
                Directory.CreateDirectory(tempFolder);

                string imagesDirectory = DataManager.getAbsolutePath(DataManager.Settings.ImageDirectory);
                Directory.Move(imagesDirectory, tempFolder + @"\" + DataManager.Settings.ImageDirectory);               //move images folder to zip folder

                File.Move(getAbsolutePath(Competition.DefaltFileName), tempFolder + @"\" + Competition.DefaltFileName); //move competition file to zip folder

                //string startPath = @"c:\example\start";
                //string zipPath = @"c:\example\result.zip";
                //string extractPath = @"c:\example\extract";

                ZipFile.CreateFromDirectory(tempFolder, saveFile.FullName);

                Directory.Delete(tempFolder, true);

                _competition = Competition.Load();
                triggerCompetitionChanged();
                //ZipFile.ExtractToDirectory(zipPath, extractPath);
            }

            return(result == true);
        }
Exemplo n.º 2
0
 public static void saveSettings()
 {
     _settings.Save();
     _competition.Save();
 }