Exemple #1
0
 public RelativeProfilesEnumerator(string profileType)
 {
     _path = IOTools.Combine(
         Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), profileType);
     _path = IOTools.Combine(_path, "Profiles");
     Reset();
 }
Exemple #2
0
        private static void MoveDirectory(string dest, IResource folder, IResource targetResource)
        {
            string source = folder.GetPropText(_propDirectory);

            Directory.Move(source, dest);
            folder.BeginUpdate();
            try
            {
                folder.SetProp(_propDirectory, dest);
                folder.SetProp(_propParentFolder, targetResource);
            }
            finally
            {
                folder.EndUpdate();
            }
            foreach (IResource file in folder.GetLinksTo(null, _propParentFolder).ValidResources)
            {
                if (file.Type != _folderResourceType)
                {
                    file.SetProp(_propDirectory, dest);
                }
                else
                {
                    string name = file.GetPropText(_propDirectory).Replace(source, null).Trim('/', '\\');
                    file.SetProp(_propDirectory, IOTools.Combine(dest, name));
                }
            }
        }
Exemple #3
0
        private static string GetDefaultBackupPath(string dbPath)
        {
            string backupPath;

            backupPath = IOTools.Combine(dbPath, "backup");
            if (!Directory.Exists(backupPath))
            {
                Directory.CreateDirectory(backupPath);
            }
            return(backupPath);
        }
Exemple #4
0
        private void LoadLogPath()
        {
            string logPath = RegUtil.LogPath;

            if (logPath == null)
            {
                string basePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                logPath = IOTools.Combine(IOTools.Combine(basePath, @"JetBrains\Omea"), "logs");
            }
            _edtLogPath.Text = logPath;
        }
Exemple #5
0
        public Database(DBStructure dbStructure)
        {
            _dbStructure = dbStructure;
            int databaseCacheSize = 0x20000;

            if (ICore.Instance != null)
            {
                databaseCacheSize = Core.SettingStore.ReadInt("Omea", "DatabaseCacheSize", 2048 * 1024);
            }
            _bfs = new BlobFileSystem(
                IOTools.Combine(Path, Name) + ".BlobFileSystem.dbUtil", databaseCacheSize >> 3, 256);
            _tracer = new Tracer("(DBUtils) Database - " + Name);
        }
Exemple #6
0
        public MozillaProfile(string path)
        {
            _name = null;
            _path = path;
            DirectoryInfo di = IOTools.GetParent(path);

            if (di != null)
            {
                di = IOTools.GetParent(IOTools.GetFullName(di));
            }
            string firefoxDir = IOTools.Combine(Environment.GetFolderPath(
                                                    Environment.SpecialFolder.ApplicationData), @"Mozilla\Firefox");
            string profileDir = IOTools.GetFileName(path);

            if (di != null)
            {
                if (String.Compare(di.Name, "Firefox", true) == 0)
                {
                    firefoxDir = IOTools.GetFullName(di);
                }
                else if (String.Compare(di.Name, "Profiles", true) == 0)
                {
                    _name      = di.Name + " - " + profileDir; // Mozilla
                    firefoxDir = null;
                }
            }
            if (firefoxDir != null)
            {
                Ini.IniFile profilesIni = new IniFile(IOTools.Combine(firefoxDir, "profiles.ini"));
                for (int i = 0; ; ++i)
                {
                    string profile = "Profile" + i;
                    string dir     = profilesIni.ReadString(profile, "Path");
                    if (dir == null || dir.Length == 0)
                    {
                        break;
                    }
                    if (profilesIni.ReadBool(profile, "IsRelative", false))
                    {
                        dir = IOTools.Combine(firefoxDir, dir).Replace('/', '\\');
                    }
                    if (String.Compare(dir, path, true) == 0)
                    {
                        _name = "Firefox - " + profilesIni.ReadString(profile, "Name");
                        break;
                    }
                }
            }
        }
Exemple #7
0
        public void Rename(IResource res, string newName)
        {
            string        fullname    = GetResourceFullname(res);
            DirectoryInfo di          = IOTools.GetParent(fullname);
            string        newFullname = IOTools.Combine(IOTools.GetFullName(di), newName);

            if (res.Type == "Folder")
            {
                IOTools.MoveDirectory(fullname, newFullname);
            }
            else
            {
                IOTools.MoveFile(fullname, newFullname + ".url");
            }
        }
Exemple #8
0
        /**
         * Gets full name of IE folder or favorite
         */
        public string GetResourceFullname(IResource res)
        {
            Guard.NullArgument(res, "res");
            IResource parent = res;
            IResource ieRoot = _bookmarkservice.GetProfileRoot(this);

            if (ieRoot != null)
            {
                Stack parents = new Stack();
                for ( ; ;)
                {
                    if (parent == ieRoot)
                    {
                        string fullName = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
                        while (parents.Count > 0)
                        {
                            res      = (IResource)parents.Pop();
                            fullName = IOTools.Combine(fullName, res.DisplayName);
                        }
                        if (fullName.IndexOfAny(InvalidNameChars) >= 0)
                        {
                            foreach (char invalidChar in Path.InvalidPathChars)
                            {
                                fullName = fullName.Replace(invalidChar, '-');
                            }
                        }
                        fullName = fullName.Replace("https://", null);
                        fullName = fullName.Replace("http://", null);
                        fullName = fullName.Replace("ftp://", null);
                        fullName = fullName.Replace("file://", null);
                        fullName = fullName.Replace("://", null);
                        if (res.Type != "Folder")
                        {
                            fullName += ".url";
                        }
                        return(fullName);
                    }
                    if ((parent = BookmarkService.GetParent(parent)) == null)
                    {
                        break;
                    }
                    parents.Push(res);
                    res = parent;
                }
            }
            return(string.Empty);
        }
Exemple #9
0
        /// <summary>
        /// Returns path to the existing file with opera bookmarks, otherwise returns empty string.
        /// </summary>
        public static string OperaBookmarksPath()
        {
            if (_bookmarksPath != null)
            {
                return(_bookmarksPath);
            }
            _bookmarksPath = string.Empty;
            string operaPath = IOTools.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Opera");

            if (operaPath.Length > 0 && Directory.Exists(operaPath))
            {
                DirectoryInfo[] directories = IOTools.GetDirectories(operaPath, "Opera*");
                if (directories != null && directories.Length > 0)
                {
                    for (int i = directories.Length - 1; i >= 0; --i)
                    {
                        operaPath = IOTools.Combine(directories[i].FullName, "Profile");
                        if (operaPath.Length == 0 || operaPath == "Profile" || !Directory.Exists(operaPath))
                        {
                            continue;
                        }
                        operaPath = IOTools.Combine(operaPath, _settingsFileName);
                        if (!File.Exists(operaPath))
                        {
                            continue;
                        }
                        IniFile opera6ini = new IniFile(operaPath);
                        operaPath = opera6ini.ReadString("User Prefs", "Hot List File Ver2", string.Empty).TrimEnd('\\');
                        if (operaPath.Length > 0 && File.Exists(operaPath))
                        {
                            _bookmarksPath = operaPath;
                            break;
                        }
                    }
                }
            }
            return(_bookmarksPath);
        }
Exemple #10
0
 /**
  * performs renaming of a directory updating all its sub-directories
  */
 public void RenameDirectory(IResource folder, string name, string fullname)
 {
     if (!Core.ResourceStore.IsOwnerThread())
     {
         _resourceAP.RunUniqueJob("Renaming directory",
                                  new RenameDirectoryDelegate(RenameDirectory), folder, name, fullname);
     }
     else
     {
         folder.BeginUpdate();
         try
         {
             folder.SetProp(Core.Props.Name, name);
             folder.SetProp(FileProxy._propDirectory, fullname);
         }
         finally
         {
             folder.EndUpdate();
         }
         foreach (IResource res in folder.GetLinksTo(null, FileProxy._propParentFolder))
         {
             if (res.Type != FileProxy._folderResourceType)
             {
                 res.SetProp(FileProxy._propDirectory, fullname);
             }
             else
             {
                 string folderName     = res.GetPropText(Core.Props.Name);
                 string folderFullName = IOTools.Combine(fullname, folderName);
                 if (folderFullName.Length > 0)
                 {
                     RenameDirectory(res, folderName, folderFullName);
                 }
             }
         }
     }
 }
Exemple #11
0
        public string GetCookies(string url)
        {
            MozillaProfile activeProfile = MozillaProfiles.GetProfile(_profileName);
            string         cookiesFile   = IOTools.Combine(activeProfile.Path, "cookies.txt");
            DateTime       ftime         = IOTools.GetFileLastWriteTime(cookiesFile);

            if (ftime > _lastCookiesFileTime)
            {
                _cookies.Clear();
                using (StreamReader reader = new StreamReader(cookiesFile))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.Length == 0 || line.StartsWith("#"))
                        {
                            continue;
                        }
                        string[] cookieProps = line.Split('\t');
                        if (cookieProps.Length > 6)
                        {
                            string cookie = cookieProps[5] + '=' + cookieProps[6];
                            string domain = cookieProps[0];
                            if (domain.StartsWith("."))
                            {
                                SetUrlCookie(domain.TrimStart('.'), cookieProps[2], cookie);
                                domain = "www" + domain;
                            }
                            SetUrlCookie(domain, cookieProps[2], cookie);
                        }
                    }
                }
                _lastCookiesFileTime = ftime;
            }
            return((string)_cookies[url]);
        }
Exemple #12
0
        public void Move(IResource res, IResource parent, IResource oldParent)
        {
            string newFolder = GetResourceFullname(parent);
            string oldFolder = GetResourceFullname(oldParent);
            string name      = res.GetPropText(Core.Props.Name);

            if (res.Type != "Folder")
            {
                name += ".url";
            }
            if (newFolder != oldFolder && name.Length > 0)
            {
                string oldPath = IOTools.Combine(oldFolder, name);
                string newPath = IOTools.Combine(newFolder, name);
                if (res.Type == "Folder")
                {
                    IOTools.MoveDirectory(oldPath, newPath);
                }
                else
                {
                    IOTools.MoveFile(oldPath, newPath);
                }
            }
        }
Exemple #13
0
 /**
  * returns full name of a file by resource
  */
 public string GetFullName(IResource file)
 {
     return(IOTools.Combine(
                file.GetPropText(FileProxy._propDirectory), file.GetPropText(Core.Props.Name)));
 }
Exemple #14
0
        private void RunRepair()
        {
            string dbPath = null;

            string[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {
                if (args [1] == "-?" || args [1] == "/?")
                {
                    ShowHelp();
                    return;
                }
                string arg = args [1].ToLower();
                if ((arg == "-workdir" || arg == "/workdir") && args.Length > 2)
                {
                    dbPath = args [2];
                    if (args.Length > 3)
                    {
                        ProcessArgument(args [3]);
                    }
                }
                else
                {
                    ProcessArgument(arg);
                }
            }

            if (dbPath == null)
            {
                dbPath = RegUtil.DatabasePath;
                if (dbPath == null)
                {
                    dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                          "JetBrains\\Omea");
                }
            }

            OMEnv.WorkDir       = dbPath;
            MyPalStorage.DBPath = Path.Combine(OMEnv.WorkDir, "db");
            _ini = new IniFile(Path.Combine(OMEnv.WorkDir, "OmniaMea.ini"));

            Console.WriteLine("Processing database in " + dbPath);

            bool  omniaMeaIsNotRun;
            Mutex omniaMeaMux = new Mutex(true, "OmniaMeaMutex", out omniaMeaIsNotRun);

            try
            {
                if (!omniaMeaIsNotRun && !_ignoreMutex)
                {
                    Console.WriteLine("Omea is currently running. Please close Omea before running DBRepair.");
                    return;
                }

                if (_deleteIndex)
                {
                    DeleteIndex();
                }
                else if (_deleteTextIndex)
                {
                    DeleteFiles(OMEnv.WorkDir, "_*");
                }
                else if (_backup)
                {
                    string backupPath = _ini.ReadString("ResourceStore", "BackupPath", string.Empty);
                    if (backupPath.Length > 0)
                    {
                        Console.Write("Database backup in progress...");
                        MyPalStorage.BackupDatabase(IOTools.Combine(backupPath, MyPalStorage._dbBackupFile));
                        Console.WriteLine("\r                               \rDatabase backup done.");
                    }
                    else
                    {
                        Console.WriteLine("Backup path is not set. Run Omea, in Options | Paths set the path.");
                    }
                }
                else if (_restore)
                {
                    string backupPath = _ini.ReadString("ResourceStore", "BackupPath", string.Empty);
                    if (backupPath.Length > 0)
                    {
                        Console.Write("Restoring database from backup...");
                        MyPalStorage.RestoreFromBackup(IOTools.Combine(backupPath, MyPalStorage._dbBackupFile));
                        Console.WriteLine("\r                                  \rDatabase restored from backup.");
                    }
                    else
                    {
                        Console.WriteLine("Backup path is not set. Run Omea, in Options | Paths set the path.");
                    }
                }
                else
                {
                    if (!_textAnalyze || _lowCheck)
                    {
                        ProcessDB();
                    }
                    else
                    {
                        try
                        {
                            ProcessTextIndex(OMEnv.WorkDir + "\\_term.index");
                        }
                        catch (FormatException exc_)
                        {
                            Console.Error.WriteLine(exc_.Message);
                        }
                    }
                }
            }
            finally
            {
                omniaMeaMux.Close();
            }
            if (!_dump && !_deleteIndex)
            {
                Console.WriteLine("Press Enter to continue...");
                Console.ReadLine();
            }
        }
Exemple #15
0
 public AbsoluteFirefoxProfilesEnumerator()
 {
     _path = IOTools.Combine(Environment.GetFolderPath(
                                 Environment.SpecialFolder.ApplicationData), @"Mozilla\Firefox\profiles.ini");
     Reset();
 }
Exemple #16
0
        /**
         * If the source of the specified resource is a file, returns the name
         * of that file. If it's a different resource, saves the stream of the
         * resource to a temporary file and returns the name of that file.
         */

        public string GetSourceFile(IResource fileResource)
        {
            #region Preconditions
            if (fileResource == null)
            {
                throw new ArgumentNullException("fileResource", "FileTypes -- Input resource is null or empty.");
            }
            #endregion Preconditions

            IResource sourceResource = GetSource(fileResource);
            string    filename       = fileResource.GetPropText(Core.Props.Name);
            if (sourceResource == null)
            {
                return(IOTools.Combine(fileResource.GetPropText("Directory"), filename));
            }
            if (sourceResource.Type == "FileFolder")
            {
                return(IOTools.Combine(sourceResource.GetPropText("Directory"), filename));
            }
            Stream source = GetStream(fileResource);
            if (source == null)
            {
                return(IOTools.Combine(fileResource.GetPropText("Directory"), filename));
            }
            string tempDir = GetUniqueTempDirectory();
            filename = null;
            if (fileResource.HasProp(Core.Props.Name))
            {
                string name = fileResource.GetStringProp(Core.Props.Name);
                int    pos  = name.LastIndexOf("\\");
                if (pos >= 0)
                {
                    name = name.Substring(pos + 1);
                }
                if (name.IndexOfAny(Path.InvalidPathChars) < 0)
                {
                    filename = name;
                }
            }
            if (filename == null)
            {
                filename = _randomizer.NextDouble().ToString().Substring(2);
            }

            string tempFileName = Path.Combine(tempDir, filename);
            Stream target       = IOTools.CreateFile(tempFileName);
            if (target != null)
            {
                try
                {
                    try
                    {
                        CopyStream(source, target);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Error copying stream for file resource of type " + fileResource.Type +
                                            " and source resource of type " + sourceResource.Type, ex);
                    }
                    return(tempFileName);
                }
                finally
                {
                    source.Close();
                    target.Close();
                }
            }
            return(null);
        }
Exemple #17
0
        public void Drop(IResource targetResource, IDataObject data, DragDropEffects allowedEffect, int keyState)
        {
            IResourceList droppedResources = data.GetData(typeof(IResourceList)) as IResourceList;

            if (droppedResources != null && targetResource.Type == _folderResourceType)
            {
                string directory = targetResource.GetPropText(_propDirectory);

                try
                {
                    foreach (IResource file in droppedResources)
                    {
                        string droppedName = file.GetPropText(Core.Props.Name);
                        string dest        = Path.Combine(directory, droppedName);

                        if (file.Type == _folderResourceType)
                        {
                            if ((keyState & 8) != 0)
                            {
                                // copy files
                                FileInfo[] fileInfos = IOTools.GetFiles(file.GetPropText(_propDirectory));
                                if (fileInfos != null)
                                {
                                    if (Directory.Exists(dest) || IOTools.CreateDirectory(dest) != null)
                                    {
                                        foreach (FileInfo fileInfo in fileInfos)
                                        {
                                            string path = IOTools.GetFullName(fileInfo);
                                            if (path.Length > 0)
                                            {
                                                File.Copy(path, IOTools.Combine(dest, IOTools.GetFileName(path)));
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Core.ResourceAP.RunUniqueJob("Moving directory",
                                                             new MoveDirectoryDelegate(MoveDirectory), dest, file, targetResource);
                            }
                        }
                        else
                        {
                            string source = Path.Combine(file.GetPropText(_propDirectory), droppedName);
                            if ((keyState & 8) != 0)
                            {
                                File.Copy(source, dest, false);
                            }
                            else
                            {
                                Core.ResourceAP.RunUniqueJob("Moving file",
                                                             new MoveFileDelegate(MoveFile), source, dest, directory, file, targetResource);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(Core.MainWindow, GetExceptionMessage(e),
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }