Example #1
0
        public FileInfo Select(ReplacedFile id, FileInfo outTo = null)
        {
            var output = outTo ?? new FileInfo(id.FilePath);

            var actDir     = Path.Combine(root.FullName, id.ActNo.ToString());
            var targetFile = Path.Combine(actDir, id.Id.ToString());

            File.Delete(output.FullName);
            File.Copy(targetFile, output.FullName);

            return(output);
        }
Example #2
0
        public void Insert(string filepath, string hash, Delegate invoker, params object[] param)
        {
            //置換対象のファイルが読み取り専用の場合はエラー
            if (File.GetAttributes(filepath).HasFlag(FileAttributes.ReadOnly))
            {
                throw new IOException("読み取り専用です");
            }

            var key = new ReplacedFile()
            {
                ActNo            = actNo,
                Id               = replaceList.Count,
                FilePath         = filepath,
                ReplacedFileHash = hash
            };
            var entityPath = Path.Combine(actDir.FullName, key.Id.ToString());

            replaceList.Add(key);
            File.Copy(filepath, entityPath);

            try
            {
                invoker.DynamicInvoke(param);
                if (replaceList.Count > 1)
                {
                    actFileWriter.Write('\n');
                }
                actFileWriter.Write(key.ToString());
                actFileWriter.Flush();
            }
            catch (TargetInvocationException e)
            {
                replaceList.RemoveAt(replaceList.Count - 1);
                File.Delete(entityPath);
                throw e.InnerException;
            }
            catch (Exception e)
            {
                replaceList.RemoveAt(replaceList.Count - 1);
                File.Delete(entityPath);
                throw e;
            }
        }
Example #3
0
        public void DeleteAct()
        {
            if (this.actFileWriter != null)
            {
                actFileWriter.Close();
            }

            var actDir  = Path.Combine(root.FullName, actNo.ToString());
            var actInfo = Path.Combine(root.FullName, actNo.ToString() + ".info");

            Util.DeleteDir(actDir);
            File.Delete(actInfo);

            this.actNo = actNo - 1;

            if (HasStore)
            {
                this.actDir  = new DirectoryInfo(Path.Combine(root.FullName, actNo.ToString()));
                this.actFile = new FileInfo(Path.Combine(root.FullName, actNo.ToString() + ".info"));

                var replaceListTxt = File.ReadAllText(this.actFile.FullName, new UTF8Encoding());
                if (replaceListTxt.Length != 0)
                {
                    this.replaceList = replaceListTxt.Split('\n').Select(s => ReplacedFile.ValueOf(s)).ToList();
                }
                else
                {
                    this.replaceList = new List <ReplacedFile>();
                }

                this.actFileWriter = new StreamWriter(
                    new FileStream(this.actFile.FullName, FileMode.Append),
                    new UTF8Encoding(),
                    1024 * 5);
            }
        }