예제 #1
0
        public static string GetRecycleByPath(string s)
        {
            string name = System.IO.File.Exists(s) ? System.IO.Path.GetFileName(s) : new System.IO.DirectoryInfo(s).Name;
            string dst  = CfgPath.GetRecycleName(name);

            return(dst);
        }
예제 #2
0
        /// <summary>
        /// 打开文件
        /// </summary>
        /// <param name="file"></param>
        public static void OpenFile(string file)
        {
            if (IsNoteFile(file))
            {
                string wordpad = CfgPath.GetWordPadExeFile();
                Process.Start(wordpad, file);
                return;
            }

            Logger.D("StartFile {0} ", file);
            if (!PathHelper.IsValidUri(file))
            {
                Logger.E("Start File ERROR,File isn't valid!~");
                return;
            }

            UpdateAccessTime(file);
            if (File.Exists(file))
            {
                //之所以搞下面这么复杂的流程,是因为zte的一个文档安全软件导致Process.Start(file);报错
                //最终原因貌似与观察文件变更有关系,现在在文件变更过程通过定时器来触发,似乎就没有问题了。
                Logger.D("StartFile {0} is valid", file);

                Process p = Process.Start(file);

                return;
            }
            else
            {
                Process.Start(file);
            }
        }
예제 #3
0
 public static void MoveToRecycle(string f)
 {
     if (File.Exists(f))
     {
         File.Move(f, CfgPath.GetRecycleByPath(f));
     }
 }
예제 #4
0
 public void OnFileChanged(object sender, FileSystemEventArgs e)
 {
     Logger.I("OnFileChanged {0} - {1}", e.FullPath, e.ChangeType);
     if (!CfgPath.NeedSkipByUri(e.FullPath))
     {
         Push(e);
     }
 }
예제 #5
0
 /// <summary>
 /// 打开Tag所在的目录
 /// </summary>
 /// <param name="title"></param>
 public static void OpenExplorerByTag(string title)
 {
     if (title != null)
     {
         string tag = title;
         string dir = CfgPath.GetDirByTag(tag, true);//打开目录,现在创建
         Logger.D("OpenTagDir {0} {1}", tag, dir);
         Process.Start(dir);
     }
 }
예제 #6
0
        private static void TryOpenTagFile(string title, string postfix)
        {
            if (title != null && postfix != null)
            {
                string tag  = title;
                string file = CfgPath.GetFileByTag(tag, postfix);//file可能为null
                //string file = System.IO.Path.Combine(MyPath.DocRoot, tag + GConfig.DefaultPostfix);

                //如果文件已经存在,直接打开
                if (file != null && File.Exists(file))
                {
                    System.Diagnostics.Process.Start(file);
                }
                else
                {
                    //如果文件不存在,尝试在其他路径上查找
                    string[] files  = Directory.GetFiles(CfgPath.DocDir, tag + "." + postfix);
                    string   dir    = CfgPath.GetDirByTag(tag); //如果目录不存在,就不要再这儿创建了。
                    string[] files2 = null;

                    if (Directory.Exists(dir))
                    {
                        files2 = Directory.GetFiles(dir, tag + "." + postfix);
                    }

                    if (files.Length > 0)
                    {
                        file = files[0];
                        System.Diagnostics.Process.Start(file);
                    }
                    else if (files2 != null && files2.Length > 0)
                    {
                        file = files2[0];
                        System.Diagnostics.Process.Start(file);
                    }
                    else // 否则新建一个文件
                    {
                        if (File.Exists(TemplateHelper.GetTemplateByExtension(postfix)))
                        {
                            File.Copy(TemplateHelper.GetTemplateByExtension(postfix), file);
                        }
                        else
                        {
                            File.Create(file).Close();
                        }
                        //db.AddTagFile(tag, file, tag);
                        System.Diagnostics.Process.Start(file);
                    }
                }
            }
        }
예제 #7
0
        public void Run()
        {
            string src = CfgPath.GetDirByTag(Tag);//删除目录,不需要再这儿创建目录

            if (Directory.Exists(src))
            {
                string dst = CfgPath.GetRecycleName(Tag);
                try
                {
                    Directory.Move(src, dst);
                }
                catch (Exception e)
                {
                    Logger.E(e);
                }
            }
        }
예제 #8
0
        public static string GetTemplateFileByTag(string tag, string dotPostfix)
        {
            string file        = CfgPath.GetFileByTag(tag, "note" + dotPostfix, true);//这儿保证目录创建,并且file不为null
            string tmplateFile = TemplateHelper.GetTemplateByExtension(dotPostfix);

            if (!File.Exists(file) && File.Exists(tmplateFile))
            {
                File.Copy(tmplateFile, file);
            }
            if (File.Exists(file))
            {
                return(file);
            }
            else
            {
                return(null);
            }
        }
예제 #9
0
 public static string[] MapFilesToTagDir(string [] srcs, string currentTag)
 {
     string[] dsts = new string[srcs.Length];
     for (int i = 0; i < srcs.Length; i++)
     {
         string s = srcs[i];
         if (PathHelper.IsValidWebLink(s))
         {
             dsts[i] = s;
         }
         else
         {
             System.Diagnostics.Debug.Assert(PathHelper.IsValidFS(s));
             string n = Path.GetFileName(s);
             string d = Path.Combine(CfgPath.GetDirByTag(currentTag, true), n);//如果目录不存在,现在创建
             dsts[i] = d;
         }
     }
     return(dsts);
 }
예제 #10
0
        private bool CanProcessNow(FileSystemEventArgs e)
        {
            switch (e.ChangeType)
            {
            case WatcherChangeTypes.Created:
            case WatcherChangeTypes.Renamed:
                return
                    ((
                         File.Exists(e.FullPath) &&
                         CfgPath.CheckAccess(e.FullPath)
                         ) ||
                     (
                         Directory.Exists(e.FullPath)
                     ));

            case WatcherChangeTypes.Deleted:
                return(!File.Exists(e.FullPath) &&
                       !Directory.Exists(e.FullPath));
            }

            return(false);
        }
예제 #11
0
        /// <summary>
        /// 下载url文件,。
        /// </summary>
        /// <param name="url"></param>
        /// <param name="fileDst"></param>
        public static void Download(string url, string tag, string title)
        {
            if (PathHelper.IsValidHttp(url))
            {
                string d = CfgPath.GetDirByTag(tag, true);
                if (string.IsNullOrEmpty(title))
                {
                    title = SearchResultItem.GetTitle(url);
                }
                if (string.IsNullOrEmpty(title))
                {
                    return;
                }


                title = CfgPath.FormatPathName(title);

                string file = Path.Combine(d, title + ".note.pdf");
                string cmd  = string.Format(@"""{0}"" ""{1}"" ""{2}""",
                                            CfgPath.DownlodPdfCmd(), url, file);
                PathHelper.RunCmd(cmd);
            }
        }