From 63dedff1464b458e92cfbbd895a40616a2c1fdae Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Wed, 9 Sep 2015 13:52:20 +0200 Subject: [PATCH] added function to test a dub project validity valid for Coedit = only JSON --- src/ce_dubproject.pas | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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.