Generalized first law of thermodynamics for black holes in spacetimes which are not asymptotically flat