internal LocalDirectory GetLocalDirectory(string path) { if (path.Length > 1 && path.EndsWith("/")) { path = path.Substring(0, path.Length - 1); } var parts = path.Split('/'); if (parts.Length < 3) { return((LocalDirectory)GetDirectory(path)); } return(core.FileSystem.UseConnection(delegate(IDbConnection connection) { var query = "SELECT * FROM directoryitems WHERE type = 'D' AND full_path = @full_path LIMIT 1"; var command = connection.CreateCommand(); command.CommandText = query; core.FileSystem.AddParameter(command, "@full_path", path); var data = core.FileSystem.ExecuteDataSet(command); if (data.Tables[0].Rows.Count > 0) { return LocalDirectory.FromDataRow(this, data.Tables[0].Rows[0]); } return null; })); }
public SearchResultInfo SearchFiles(string query) { string sql; IDbCommand command; DataSet ds; int x; SearchResultInfo result; var directories = new List <string>(); var files = new List <SharedFileListing>(); result = new SearchResultInfo(); var queryNode = UserQueryParser.Parse(query, FieldSet); var queryFragment = queryNode.ToSql(FieldSet); var sb = new StringBuilder(); sb.Append("SELECT * FROM directoryitems WHERE "); sb.Append(queryFragment); sb.AppendFormat(" LIMIT {0}", MAX_RESULTS); UseConnection(delegate(IDbConnection connection) { command = connection.CreateCommand(); command.CommandText = sb.ToString(); ds = ExecuteDataSet(command); for (x = 0; x < ds.Tables[0].Rows.Count; x++) { if (ds.Tables[0].Rows[x]["type"].ToString() == "F") { files.Add(new SharedFileListing(LocalFile.FromDataRow(core.FileSystem, ds.Tables[0].Rows[x]), false)); } else { var dir = LocalDirectory.FromDataRow(this, ds.Tables[0].Rows[x]); // FIXME: Ugly: Remove '/local' from begining of path var path = "/" + string.Join("/", dir.FullPath.Split('/').Slice(2)); directories.Add(path); } } }); result.Files = files.ToArray(); result.Directories = directories.ToArray(); return(result); }