예제 #1
0
        private static bool Backup()
        {
            Console.WriteLine("Backup current version.");

            bool result = true;

            try
            {
                string backupPath = Path.Combine(mDestinationPath, BACKUPFILE);
                if (File.Exists(backupPath))
                {
                    File.Delete(backupPath);
                }

                using (ZipArchive archive = ZipArchive.Create())
                {
                    archive.AddAllFromDirectory(mDestinationPath);
                    archive.SaveTo(backupPath, CompressionType.Deflate);
                }

                #region old code

                ////if (File.Exists(Path.Combine(DestinationPath, KSPMODADMINFILE + BACKUPEXTENSION)))
                ////    File.Delete(Path.Combine(DestinationPath, KSPMODADMINFILE + BACKUPEXTENSION));
                ////File.Copy(Path.Combine(DestinationPath, KSPMODADMINFILE), Path.Combine(DestinationPath, KSPMODADMINFILE + BACKUPEXTENSION));

                ////if (File.Exists(Path.Combine(DestinationPath, SHARPCOMPRESSFILE + BACKUPEXTENSION)))
                ////    File.Delete(Path.Combine(DestinationPath, SHARPCOMPRESSFILE + BACKUPEXTENSION));
                ////File.Copy(Path.Combine(DestinationPath, SHARPCOMPRESSFILE), Path.Combine(DestinationPath, SHARPCOMPRESSFILE + BACKUPEXTENSION));

                ////if (File.Exists(Path.Combine(DestinationPath, BACKUPFILE)))
                ////    File.Delete(Path.Combine(DestinationPath, BACKUPFILE));

                ////using (var zip = ZipArchive.Create())
                ////{
                ////    zip.AddEntry(KSPMODADMINFILE, Path.Combine(DestinationPath, KSPMODADMINFILE));
                ////    zip.AddEntry(SHARPCOMPRESSFILE, Path.Combine(DestinationPath, SHARPCOMPRESSFILE));
                ////    zip.SaveTo(Path.Combine(DestinationPath, BACKUPFILE), CompressionType.None);
                ////}
                #endregion
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Error during backup: {0}", ex.Message));
                Console.WriteLine("Update aborted!");
                Console.ReadKey();
                result = false;
            }

            return(result);
        }
예제 #2
0
파일: ZipHelper.cs 프로젝트: laulunsi/cms
 /// <summary>
 /// 压缩并保存
 /// </summary>
 /// <param name="directionPath"></param>
 /// <param name="savePath"></param>
 /// <returns></returns>
 public static void ZipAndSave(string directionPath, string savePath, string dirName = null)
 {
     if (dirName == null)
     {
         ZipArchive zip = ZipArchive.Create();
         zip.AddAllFromDirectory(directionPath);
         zip.SaveTo(savePath, CompressionType.None);
         zip.Dispose();
     }
     else
     {
         using (Stream zip = File.OpenWrite(directionPath))
             using (var zipWriter = WriterFactory.Open(zip, ArchiveType.Zip, CompressionType.None))
             {
                 DirectoryInfo dir = new DirectoryInfo(directionPath);
                 Explore(dir, zipWriter, dirName, dir.FullName);
             }
     }
 }
예제 #3
0
파일: ZipHelper.cs 프로젝트: laulunsi/cms
        /// <summary>
        /// 压缩并返回字节数组
        /// </summary>
        /// <param name="directionPath"></param>
        /// <returns></returns>
        public static byte[] Compress(string directionPath, string dirName = null)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                if (dirName == null)
                {
                    ZipArchive zip = ZipArchive.Create();
                    zip.AddAllFromDirectory(directionPath);
                    zip.SaveTo(ms, CompressionType.None);
                    zip.Dispose();
                }
                else
                {
                    using (var zipWriter = WriterFactory.Open(ms, ArchiveType.Zip, CompressionType.None))
                    {
                        DirectoryInfo dir = new DirectoryInfo(directionPath);
                        Explore(dir, zipWriter, dirName, dir.FullName);
                    }
                }

                return(ms.ToArray());
            }
        }
예제 #4
0
        public static string Generate(string oggPath, string songID, string songName, string artist, double bpm, string songEndEvent, string author, int offset)
        {
            HandleCache.CheckSaveFolderValid();

            var workFolder = Path.Combine(Application.streamingAssetsPath, "Ogg2Audica");


            string audicaTemplate = Path.Combine(workFolder, ".AudicaTemplate/");

            Encoding encoding = Encoding.GetEncoding("UTF-8");


            //We need to modify the BPM of the song.mid contained in the template audica to match whatever this is.
            File.Delete(Path.Combine(workFolder, "song.mid"));
            MidiFile songMidi = MidiFile.Read(Path.Combine(workFolder, "songtemplate.mid"));

            float oneMinuteInMicroseconds = 60000000f;

            songMidi.ReplaceTempoMap(TempoMap.Create(new Tempo((long)(oneMinuteInMicroseconds / bpm))));
            songMidi.Write(Path.Combine(workFolder, "song.mid"), true, MidiFileFormat.MultiTrack);


            //Generates the mogg into song.mogg, which is moved to the .AudicaTemplate
            File.Delete(Path.Combine(workFolder, "song.mogg"));

            Process          ogg2mogg  = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
            startInfo.FileName    = Path.Combine(workFolder, "ogg2mogg.exe");

            string args = $"\"{oggPath}\" \"{workFolder}/song.mogg\"";

            startInfo.Arguments       = args;
            startInfo.UseShellExecute = false;

            ogg2mogg.StartInfo = startInfo;
            ogg2mogg.Start();

            ogg2mogg.WaitForExit();


            //Make the song.desc file;
            File.Delete(Path.Combine(workFolder, "song.desc"));
            SongDesc songDesc = JsonUtility.FromJson <SongDesc>(File.ReadAllText(Path.Combine(workFolder, "songtemplate.desc")));

            songDesc.songID       = songID;
            songDesc.title        = songName;
            songDesc.artist       = artist;
            songDesc.tempo        = (float)bpm;
            songDesc.songEndEvent = songEndEvent;
            songDesc.author       = author;
            songDesc.offset       = offset;
            File.WriteAllText(Path.Combine(workFolder, "song.desc"), JsonUtility.ToJson(songDesc, true));


            //Create the actual audica file and save it to the /saves/ folder
            using (ZipArchive archive = ZipArchive.Create()) {
                archive.AddAllFromDirectory(audicaTemplate);
                archive.AddEntry("song.desc", Path.Combine(workFolder, "song.desc"));
                archive.AddEntry("song.mid", Path.Combine(workFolder, "song.mid"));
                archive.AddEntry("song.mogg", Path.Combine(workFolder, "song.mogg"));


                archive.SaveTo(Path.Combine(Application.dataPath, "saves", songID + ".audica"), SharpCompress.Common.CompressionType.None);
            }

            return(Path.Combine(Application.dataPath, "saves", songID + ".audica"));

            /*
             *
             *      HandleCache.CheckSaveFolderValid();
             *
             *      System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
             *      ProcessStartInfo startInfo = new ProcessStartInfo();
             *      startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
             *      startInfo.FileName = Path.Combine(ogg2AudicaFolder, "Ogg2Audica.exe");
             *
             *      startInfo.Arguments = System.String.Format("\"{0}\" \"{1}\" \"{2}\" \"{3}\" \"{4}\" \"{5}\" \"{6}\" \"{7}\"", oggPath, songID, songName, artist, bpm, songEndEvent, mapper, offset);
             *      startInfo.UseShellExecute = true;
             *      startInfo.WorkingDirectory = ogg2AudicaFolder;
             *
             *      myProcess.StartInfo = startInfo;
             *
             *      myProcess.Start();
             *
             *      myProcess.WaitForExit();
             *
             *      File.Move(Path.Combine(ogg2AudicaFolder, "out.audica"), Path.Combine(Application.dataPath, "saves", songID + ".audica"));
             *
             *
             *      return Path.Combine(Application.dataPath, "saves", songID + ".audica");
             */
        }
예제 #5
0
        public static string Generate(string oggPath, float moggSongVol, string songID, string songName, string artist, double bpm, string songEndEvent, string author, int offset, string midiPath, string artPath)
        {
            HandleCache.CheckSaveFolderValid();

            var workFolder = Path.Combine(Application.streamingAssetsPath, "Ogg2Audica");


            string audicaTemplate = Path.Combine(workFolder, "AudicaTemplate/");

            Encoding encoding = Encoding.GetEncoding("UTF-8");

            //Album art
            File.Delete(Path.Combine(workFolder, "song.png"));
            if (!string.IsNullOrEmpty(artPath))
            {
                UnityEngine.Debug.Log("Album art found");
                File.Copy(artPath, Path.Combine(workFolder, "song.png"));
            }

            //We need to modify the BPM of the song.mid contained in the template audica to match whatever this is.
            File.Delete(Path.Combine(workFolder, "song.mid"));
            File.Copy(midiPath, Path.Combine(workFolder, "song.mid"));

            //Generates the mogg into song.mogg, which is moved to the AudicaTemplate
            File.Delete(Path.Combine(workFolder, "song.mogg"));

            Process          ogg2mogg  = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;

            startInfo.FileName = Path.Combine(workFolder, "ogg2mogg.exe");

            if ((Application.platform == RuntimePlatform.LinuxEditor) || (Application.platform == RuntimePlatform.LinuxPlayer))
            {
                startInfo.FileName = Path.Combine(workFolder, "ogg2mogg");
            }

            if ((Application.platform == RuntimePlatform.OSXEditor) || (Application.platform == RuntimePlatform.OSXPlayer))
            {
                startInfo.FileName = Path.Combine(workFolder, "ogg2moggOSX");
            }

            string args = $"\"{oggPath}\" \"{workFolder}/song.mogg\"";

            startInfo.Arguments       = args;
            startInfo.UseShellExecute = false;

            ogg2mogg.StartInfo = startInfo;
            ogg2mogg.Start();

            ogg2mogg.WaitForExit();

            //Set the song.moggsong volume
            var moggpath         = Path.Combine(workFolder, "song.moggsong");
            var moggsongTemplate = Path.Combine(workFolder, "MoggsongTemplate", "song.moggsong");

            File.Delete(moggpath);
            File.Copy(moggsongTemplate, moggpath);
            File.WriteAllText(moggpath, File.ReadAllText(moggpath).Replace("-5", moggSongVol.ToString("n2")));

            //Make the song.desc file;
            File.Delete(Path.Combine(workFolder, "song.desc"));
            SongDesc songDesc = JsonUtility.FromJson <SongDesc>(File.ReadAllText(Path.Combine(workFolder, "songtemplate.desc")));

            songDesc.songID = songID;
            songDesc.title  = songName;
            songDesc.artist = artist;
            if (!string.IsNullOrEmpty(artPath))
            {
                songDesc.albumArt = "song.png";
            }
            songDesc.tempo        = (float)bpm;
            songDesc.songEndEvent = songEndEvent;
            songDesc.author       = author;
            songDesc.offset       = offset;
            File.WriteAllText(Path.Combine(workFolder, "song.desc"), Newtonsoft.Json.JsonConvert.SerializeObject(songDesc, Newtonsoft.Json.Formatting.Indented));

            /*File.Delete(Path.Combine(workFolder, "modifiers.json"));
             * ModifierList modifierList = new ModifierList();
             * modifierList.modifiers = ModifierHandler.instance.modifiers;
             * File.WriteAllText(Path.Combine(workFolder, "modifiers.json"), JsonUtility.ToJson(modifierList, true));
             */
            File.Create(Path.Combine(workFolder, "modifiers.json"));
            //Create the actual audica file and save it to the /saves/ folder
            using (ZipArchive archive = ZipArchive.Create()) {
                archive.AddAllFromDirectory(audicaTemplate);
                archive.AddEntry("song.desc", Path.Combine(workFolder, "song.desc"));
                archive.AddEntry("song.mid", Path.Combine(workFolder, "song.mid"));
                archive.AddEntry("song.mogg", Path.Combine(workFolder, "song.mogg"));
                archive.AddEntry("song.moggsong", Path.Combine(workFolder, "song.moggsong"));
                if (!string.IsNullOrEmpty(artPath))
                {
                    archive.AddEntry("song.png", Path.Combine(workFolder, "song.png"));
                }

                archive.SaveTo(Path.Combine(Application.dataPath, @"../", "saves", songID + ".audica"), SharpCompress.Common.CompressionType.None);
            }

            return(Path.Combine(Application.dataPath, @"../", "saves", songID + ".audica"));

            /*
             *
             *      HandleCache.CheckSaveFolderValid(); 59.6, 57.8
             *
             *      System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
             *      ProcessStartInfo startInfo = new ProcessStartInfo();
             *      startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
             *      startInfo.FileName = Path.Combine(ogg2AudicaFolder, "Ogg2Audica.exe");
             *
             *      startInfo.Arguments = System.String.Format("\"{0}\" \"{1}\" \"{2}\" \"{3}\" \"{4}\" \"{5}\" \"{6}\" \"{7}\"", oggPath, songID, songName, artist, bpm, songEndEvent, mapper, offset);
             *      startInfo.UseShellExecute = true;
             *      startInfo.WorkingDirectory = ogg2AudicaFolder;
             *
             *      myProcess.StartInfo = startInfo;
             *
             *      myProcess.Start();
             *
             *      myProcess.WaitForExit();
             *
             *      File.Move(Path.Combine(ogg2AudicaFolder, "out.audica"), Path.Combine(Application.dataPath, "saves", songID + ".audica"));
             *
             *
             *      return Path.Combine(Application.dataPath, "saves", songID + ".audica");
             */
        }