Example #1
0
        static CCProcess()
        {
            // find the service process
            Process serviceProcess = null;
            CCPath  pathCurDir     = new CCPath(Environment.CurrentDirectory.Replace(Path.DirectorySeparatorChar, '/'));
            int     score          = 0;

            // if there are multiple shred host services, guess the one with more common path components
            foreach (Process process in Process.GetProcessesByName(SERVICE_PROCESS_NAME))
            {
                try
                {
                    string processDir      = Path.GetDirectoryName(process.MainModule.FileName);
                    CCPath pathProcessDir  = new CCPath(processDir.Replace(Path.DirectorySeparatorChar, '/'));
                    int    scoreProcessDir = pathCurDir.GetCommonPath(pathProcessDir).Segments.Count;
                    if (scoreProcessDir > score)
                    {
                        score          = scoreProcessDir;
                        serviceProcess = process;
                    }
                }
                catch (Exception) {}
            }

            if (serviceProcess != null)
            {
                Service = new CCProcess(serviceProcess);
            }
            else
            {
                Service = new CCProcess(Process.GetCurrentProcess());
                Platform.Log(LogLevel.Warn, "DevTools couldn't find the service process.");
            }
        }
Example #2
0
        /// <summary>
        /// Returns a new <see cref="CCPath"/> object obtained by appending <paramref name="other"/> path
        /// to this path.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public CCPath Append(CCPath other)
        {
            List <PathSegment> combined = new List <PathSegment>(_segments);

            combined.AddRange(other.Segments);

            return(new CCPath(combined));
        }
Example #3
0
        /// <summary>
        /// Returns true if this path starts with <paramref name="other"/>.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool StartsWith(CCPath other)
        {
            // if other path is longer, then this path can't possibly "start with" it
            if (other.Segments.Count > _segments.Count)
            {
                return(false);
            }

            // check that segments are equal up to length of other path
            for (int i = 0; i < other.Segments.Count; i++)
            {
                if (!Equals(_segments[i], other.Segments[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #4
0
        /// <summary>
        /// Returns a new <see cref="CCPath"/> object representing the longest common path
        /// between this object and <paramref name="other"/>.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public CCPath GetCommonPath(CCPath other)
        {
            List <PathSegment> commonPath = new List <PathSegment>();

            for (int i = 0; i < Math.Min(_segments.Count, other.Segments.Count); i++)
            {
                if (_segments[i] == other.Segments[i])
                {
                    commonPath.Add(_segments[i]);
                }
                else
                {
                    break;                     // must break as soon as paths differ
                }
            }

            return(new CCPath(commonPath));
        }