Section 38. The order of the commissioner, duly issued under section thirty-five, shall authorize the petitioner to do all acts necessary to be done in compliance therewith; and if it is shown that the petitioner has substantially complied with such order, no indictment shall be maintained for the flowage of, or injury to, the ways mentioned in such order, which may be caused by the dam.