Пример #1
0
        private void Shell_FileSaved(object sender, Shell.FileSavedEventArgs e)
        {
            try
            {
                var options = ProbeToolsPackage.Instance.EditorOptions;
                if (!options.DisableBackgroundScan)
                {
                    var fileContext = FileContextUtil.GetFileContextFromFileName(e.FileName);
                    if (ProbeEnvironment.CurrentAppSettings.FileExistsInApp(e.FileName))
                    {
                        if (fileContext != FileContext.Include && !FileContextUtil.IsLocalizedFile(e.FileName))
                        {
                            Log.Debug("Scanner detected a saved file: {0}", e.FileName);

                            EnqueueChangedFile(e.FileName);
                        }
                        else
                        {
                            Log.Debug("Scanner detected an include file was saved: {0}", e.FileName);

                            EnqueueFilesDependentOnInclude(e.FileName);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteEx(ex);
            }
        }
Пример #2
0
        private void ProcessSourceDir(FFApp app, string dir, List <ScanInfo> scanList)
        {
            try
            {
                foreach (var fileName in Directory.GetFiles(dir))
                {
                    if (!FileContextUtil.IsLocalizedFile(fileName))
                    {
                        var fileContext = FileContextUtil.GetFileContextFromFileName(fileName);
                        switch (fileContext)
                        {
                        case FileContext.Include:
                            // Ignore include files.
                            break;

                        case FileContext.Dictionary:
                            // Deep scan for dictionary only; no exports produced.
                            scanList.Add(new ScanInfo {
                                fileName = fileName, mode = FFScanMode.Deep
                            });
                            break;

                        case FileContext.Function:
                        case FileContext.ClientClass:
                        case FileContext.NeutralClass:
                        case FileContext.ServerClass:
                        case FileContext.ServerProgram:
                            // Files that export global functions must be scanned twice:
                            // First for the exports before everything else, then again for the deep info.
                            scanList.Add(new ScanInfo {
                                fileName = fileName, mode = FFScanMode.Exports
                            });
                            scanList.Add(new ScanInfo {
                                fileName = fileName, mode = FFScanMode.Deep
                            });
                            break;

                        default:
                            scanList.Add(new ScanInfo {
                                fileName = fileName, mode = FFScanMode.Deep
                            });
                            break;
                        }
                    }
                }

                foreach (var subDir in Directory.GetDirectories(dir))
                {
                    ProcessSourceDir(app, subDir, scanList);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, string.Format("Exception when scanning directory '{0}' for functions.", dir));
            }
        }
Пример #3
0
        private void ProcessFile(FFDatabase db, FFApp app, ScanInfo scan)
        {
            try
            {
                if (!File.Exists(scan.fileName))
                {
                    return;
                }
                if (FileContextUtil.IsLocalizedFile(scan.fileName))
                {
                    return;
                }

                var fileContext = CodeModel.FileContextUtil.GetFileContextFromFileName(scan.fileName);
                if (fileContext == FileContext.Include)
                {
                    return;
                }

                DateTime modified;
                if (!app.TryGetFileDate(scan.fileName, out modified))
                {
                    modified = DateTime.MinValue;
                }

                var fileModified = File.GetLastWriteTime(scan.fileName);
                if (!scan.forceScan)
                {
                    if (modified != DateTime.MinValue && fileModified.Subtract(modified).TotalSeconds < 1.0)
                    {
                        return;
                    }
                }

                var ffFile = app.GetFileForScan(db, scan.fileName);

                Log.Debug("Processing file: {0} (modified={1}, last modified={2})", scan.fileName, fileModified, modified);
                if (scan.mode == FFScanMode.Exports)
                {
                    ProbeToolsPackage.Instance.SetStatusText(string.Format("DkTools background scanning file: {0} (exports only)", scan.fileName));
                }
                else
                {
                    ProbeToolsPackage.Instance.SetStatusText(string.Format("DkTools background scanning file: {0}", scan.fileName));
                }

                var fileTitle = Path.GetFileNameWithoutExtension(scan.fileName);

                var defProvider = new CodeModel.DefinitionProvider(_appSettings, scan.fileName);

                var fileContent = File.ReadAllText(scan.fileName);
                var fileStore   = new CodeModel.FileStore();

                var merger = new FileMerger();
                merger.MergeFile(_appSettings, scan.fileName, null, false, true);
                var includeDependencies = (from f in merger.FileNames
                                           select new Preprocessor.IncludeDependency(f, false, true, merger.GetFileContent(f))).ToArray();

                var model = fileStore.CreatePreprocessedModel(_appSettings, merger.MergedContent, scan.fileName, false, string.Concat("Function file processing: ", scan.fileName), includeDependencies);

                var className = fileContext.IsClass() ? Path.GetFileNameWithoutExtension(scan.fileName) : null;
                var classList = new List <FFClass>();
                var funcList  = new List <FFFunction>();

                using (var txn = db.BeginTransaction())
                {
                    ffFile.UpdateFromModel(model, db, fileStore, fileModified, scan.mode);
                    txn.Commit();
                }

                if (ffFile.Visible)
                {
                    app.OnVisibleFileChanged(ffFile);
                }
                else
                {
                    app.OnInvisibleFileChanged(ffFile);
                }

#if DEBUG
                FFDatabase.DumpMemoryStats();
#endif
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Exception when background processing function name: {0} (mode: {1})", scan.fileName, scan.mode);
            }
        }