diff --git a/src/ce_dubproject.pas b/src/ce_dubproject.pas index d6cddd2b..bb6d7858 100644 --- a/src/ce_dubproject.pas +++ b/src/ce_dubproject.pas @@ -56,9 +56,12 @@ type property json: TJSONObject read fJson; end; - // these 9 built types alway exist + // these 9 built types always exist TDubBuildType = (plain, debug, release, unittest, docs, ddox, profile, cov, unittestcov); + // returns true iffilename is a valid dub project. Only json format is supported. + function isValidDubProject(const filename: string): boolean; + const DubBuiltTypeName: array[TDubBuildType] of string = ('plain', 'debug', 'release', @@ -320,5 +323,30 @@ begin result := false; end; +function isValidDubProject(const filename: string): boolean; +var + maybe: TCEDubProject; +begin + result := true; + // avoid the project to notify the observers, current project is not replaced + EntitiesConnector.beginUpdate; + maybe := TCEDubProject.create(nil); + EntitiesConnector.removeSubject(maybe); + try + try + maybe.loadFromFile(filename); + if maybe.json = nil then + result := false + else if maybe.json.Find('name') = nil then + result := false; + except + result := false; + end; + finally + maybe.Free; + EntitiesConnector.endUpdate; + end; +end; + end.