Here is the complete solution to the problem including some special cases for an easy start.
With analogy to the integrating factor method from ODEs it seems natural to rearrange
\begin{align*}
\mathrm{d}X_t = (a(t)X_t+ b(t)) \mathrm{d}t + (g(t)X_t+ h(t))\mathrm{d}B_t
\end{align*}
to the form
\begin{align*}\mathrm{d}X_t - X_t \left( a(t)\mathrm{d}t+g(t)\mathrm{d}B_t\right) = b(t) \mathrm{d}t + h(t)\mathrm{d}B_t .\end{align*}
Now we want to find a "nice" stochastic process $Z_t$ such that
\begin{align*}( \star) \ \ \ \mathrm{d}(X_tZ_t) =& Z_t\mathrm{d}X_t \underbrace{- Z_tX_t \left( a(t)\mathrm{d}t+g(t)\mathrm{d}B_t\right)}_{X_t\mathrm{d}Z_t + \mathrm{d}X_t\mathrm{d}Z_t} \\ =& Z_t(b(t)\mathrm{d}t + h(t)\mathrm{d}B_t).\end{align*}
Assume that $Z_t$ is an Itô process such that
$$\mathrm{d}Z_t = f_1(t, Z_t)\mathrm{d}t + f_2(t, Z_t)\mathrm{d}B_t , \ \ Z_0 = 1.$$
Let us apply Itô's product formula to $\mathrm{d}(X_tZ_t)$ we obtain that
\begin{align*}\mathrm{d}(X_tZ_t) =& Z_t \mathrm{d}X_t + X_t \mathrm{d}Z_t + \mathrm{d}X_t \mathrm{d}Z_t \\ ( \star \star) \ \ \ \ \qquad = & Z_t\mathrm{d}X_t + X_t \left( f_1(t, Z_t)\mathrm{d}t + f_2(t, Z_t)\mathrm{d}B_t \right) + (g(t)X_t + h(t))f_2(t, Z_t) \mathrm{d}t.\end{align*}
Comparing the above with the right hand-side of $(\star)$ we arrive at
\begin{align*}- Z_tX_t \left( a(t)\mathrm{d}t+g(t)\mathrm{d}B_t\right) = X_t \left( f_1(t, Z_t)\mathrm{d}t + f_2(t, Z_t)\mathrm{d}B_t \right) + (g(t)X_t + h(t))f_2(t, Z_t) \mathrm{d}t \end{align*}
and thus
\begin{align*} -Z_tX_tg(t)\mathrm{d}B_t &= X_t f_2(t, Z_t)\mathrm{d}B_t \\
-Z_tX_ta(t)\mathrm{d}t &= \big(X_tf_1(t, Z_t)+(X(t)g(t)+h(t))f_2(t,Z_t)\big)\mathrm{d}t.\end{align*}
From the first equation we can deduce that $f_2(t, Z_t) = -Z_tg(t)$ and so the second one converts to
$$-Z_tX_ta(t)\mathrm{d}t = \big(X_tf_1(t, Z_t)-Z_tg(t)(X(t)g(t)+h(t))\big)\mathrm{d}t,$$
and so
$$ Z_t (-X_ta(t)+X(t)g^2(t)+g(t)h(t)) \mathrm{d}t = X_tf_1(t, Z_t)\mathrm{d}t.$$
Hence,
$$f_1(t, Z_t) = Z_t(-a(t)+g^2(t)+X_t^{-1}g(t)h(t)).$$
However, we want $Z_t$ to be free of $X_t$ for that we consider two cases
CASE 1. $g(t) \neq 0$, $h(t)=0$
Then $Z_t$ would satisfy
$$\mathrm{d}Z_t = Z_t(-a(t)+g^2(t))\mathrm{d}t -Z_t g(t)\mathrm{d}B_t , \ \ Z_0 = 1$$
(We solve the above SDE by a standard trick involving Ito's formula, that is, first we divide by $Z_t$ to obtain the expression for $Z_t^{-1}\mathrm{d}Z_t$ and then derive the expression $\mathrm{d}(\ln(Z_t))$)
and so $$Z_t = \exp\left( \int_0^t\left( \frac{1}{2}g^2(s) - a(s)\right) \mathrm{d}s - \int_0^t g(s)\mathrm{d}B_s\right).$$
This is the integrating factor which you obtained, and it is not the correct one if $h(t) \neq 0$.
If we continue then we obtain
\begin{align*}\mathrm{d}(Z_tX_t) =& Z_tb(t)\mathrm{d}t
\\ Z_tX_t =& X_0 + \int_0^t Z_sb(s) \mathrm{d}s\\
X_t =& X_0Z_t^{-1}+ Z_t^{-1}\int_0^t Z_sb(s) \mathrm{d}s\\
X_t =& \exp\left( \int_0^t\left( a(s) - \frac{1}{2}g^2(s) \right) \mathrm{d}s + \int_0^t g(s)\mathrm{d}B_s\right) \\ &\cdot \left(X_0+ \int_0^{t} b(s)\exp\left( \int_0^s\left( \frac{1}{2}g^2(r) - a(r)\right) \mathrm{d}r - \int_0^s g(r)\mathrm{d}B_r\right)\mathrm{d}s\right).
\end{align*}
CASE 2. $g(t) = 0$, $h(t) \neq 0$
Then $(Z_t)$ satisfies
$$\mathrm{d}Z_t = -a(t)Z_t\mathrm{d}t, \ \quad Z_0 =1 $$
and so
$$Z_t = \exp\left( -\int_0^t a(s)\mathrm{d}s\right).$$
Therefore,
\begin{align*}\mathrm{d}(X_tZ_t) =& Z_tb(t)\mathrm{d}t+ Z_t h(t)\mathrm{d}B_t
\\ X_tZ_t =& X_0 + \int_0^t Z_sb(s) \mathrm{d}s + \int_0^t Z_sb(s) \mathrm{d}B_s\\
X_t = & X_0Z_t^{-1}+ Z_t^{-1}\left( \int_0^t Z_sb(s) \mathrm{d}s + \int_0^t Z_sb(s) \mathrm{d}B_s\right) \\
X_t = & X_0 e^{ \int_0^t a(s)\mathrm{d}s}\\ &+ e^{ \int_0^t a(s)\mathrm{d}s}\left( \int_0^t e^{ -\int_0^s a(r)\mathrm{d}r}b(s) \mathrm{d}s + \int_0^t e^{ -\int_0^s a(r)\mathrm{d}r}b(s) \mathrm{d}B_s\right).
\end{align*}
The general case
So far we were not able to find the solution for the general case, to find it we need to modify and rearrange our initial equation in a slightly different way.
Let write the SDE for $(X_t)$ as follows
\begin{align*}\mathrm{d}X_t = (a(t)X_t + b(t)+g(t)h(t) - g(t)h(t))\mathrm{d}t + (g(t)X_t+h(t))\mathrm{d}B_t
\end{align*}
after rearranging we have
\begin{align*}\mathrm{d}X_t - \left((a(t)X_t+g(t)h(t))\mathrm{d}t+ g(t)X_t\mathrm{d}B_t\right)= (b(t)- g(t)h(t))\mathrm{d}t + h(t)\mathrm{d}B_t
\end{align*}
Now let ($Z_t$) be an Ito process that satisfies
$$\mathrm{d}Z_t = f_1(t, Z_t)\mathrm{d}t + f_2(t, Z_t)\mathrm{d}B_t , \ \ Z_0 = 1.$$
After multiplying our SDE by $Z_t$ we obtain
\begin{align*}Z_t\mathrm{d}X_t - Z_t\left((a(t)X_t+g(t)h(t))\mathrm{d}t+ g(t)X_t\mathrm{d}B_t\right)= Z_t \left((b(t)- g(t)h(t))\mathrm{d}t + h(t)\mathrm{d}B_t\right)
\end{align*}
Applying Ito product formula to $X_tZ_t$ we get
$$ \mathrm{d}(X_tZ_t) = Z_t\mathrm{d}X_t + X_t\mathrm{d}Z_t+ \mathrm{d}X_t\mathrm{d}Z_t,$$
we want to have
\begin{align*}X_t\mathrm{d}Z_t+ \mathrm{d}X_t\mathrm{d}Z_t = - Z_t\left((a(t)X_t+g(t)h(t))\mathrm{d}t+ g(t)X_t\mathrm{d}B_t\right)\end{align*}
The LHS equals to
\begin{align*}X_t\left(f_1(t, Z_t)\mathrm{d}t + f_2(t, Z_t)\mathrm{d}B_t \right)+ (g(t)X_t+h(t))f_2(t, Z_t)\mathrm{d}t.\end{align*}
We compare with the RHS
\begin{align*}X_t\left(f_1(t, Z_t)\mathrm{d}t + f_2(t, Z_t)\mathrm{d}B_t \right)+ (g(t)X_t+h(t))f_2(t, Z_t)\mathrm{d}t = - Z_t\left((a(t)X_t+g(t)h(t))\mathrm{d}t+ g(t)X_t\mathrm{d}B_t\right)\end{align*}
and conclude that $f_2(t, Z_t) = -g(t)Z_t$. Now
\begin{align*}X_t\left(f_1(t, Z_t)\mathrm{d}t -g(t)Z_t\mathrm{d}B_t \right)- (g(t)X_t+h(t))g(t)Z_t\mathrm{d}t = - Z_t\left((a(t)X_t+g(t)h(t))\mathrm{d}t+ g(t)X_t\mathrm{d}B_t\right)\end{align*}
simplifies to
\begin{align*}X_tf_1(t, Z_t)\mathrm{d}t -g(t)^2Z_tX_t\mathrm{d}t = - a(t)Z_tX_t\mathrm{d}t\end{align*}
and so
\begin{align*}X_tf_1(t, Z_t)\mathrm{d}t = X_t\left( (g(t)^2- a(t))Z_t\right)\mathrm{d}t\end{align*}
let us conclude that
$$ f_1(Z_t, t) = (-a(t)+g(t)^2)Z_t.$$
Thus $$\mathrm{d}Z_t = (-a(t)+g^2(t))Z_t \mathrm{d}t - g(t)Z_t\mathrm{d}B_t,$$
you can see the explicit form of $Z_t$ in Case 1 and
$$\mathrm{d}(Z_tX_t) = (b(t)-h(t)g(t))Z_t\mathrm{d}t + h(t)Z_t\mathrm{d}B_t.$$
Using Ito's lemma we can show that $(Y_t):= (Z_t^{-1})$ is an Ito process such that it satisfies
$$ \mathrm{d}Y_t = a(t)Y_t \mathrm{d}t + g(t)Y_t\mathrm{d}B_t,\ \ Y_0 = 1$$
it has an explicit form
$$ Y_t = \exp\left(\int_0^t (a(s)-\frac{1}{2}g^2(s)) \mathrm{d}s +\int_0^t g(s)\mathrm{d}B_s\right).$$
Finally, we see that
\begin{align*}\mathrm{d}(Z_tX_t) =& (b(t)-h(t)g(t))Z_t\mathrm{d}t + h(t)Z_t\mathrm{d}B_t \end{align*}
yields
\begin{align*}Z_tX_t =& Z_0X_0 + \int_0^t (b(s)-h(s)g(s))Z_s\mathrm{d}s + \int_0^t h(s)Z_s\mathrm{d}B_s \end{align*}
Hence, we have the explicit solution
\begin{align*}X_t =& Z_0X_0Y_t + Y_t\left(\int_0^t (b(s)-h(s)g(s))Z_s\mathrm{d}s + \int_0^t h(s)Z_s\mathrm{d}B_s\right). \end{align*}
The reason $\ln(x)$ is chosen is this:
(Note: where I say $B_{t}$ I mean Brownian motion, which you denoted in your question as $W_{t}$)
The SDE you provided is one of the few we can explicitly solve. I'll talk about Geometric Brownian Motion (GBM) $dX_{t} = \mu X_{t} \,dt + \sigma X_{t} \,dB_{t}$, but as you mentioned in your question, your case is the same when $\mu$ becomes a function of $t$.
You can "multiply" the stochastic differential equation (SDE) in its differential form by $\frac{1}{X_{t}}$ to get $$\frac{1}{X_{t}}dX_{t} = \frac{1}{X_{t}}\mu X_{t} \,dt + \frac{1}{X_{t}}\sigma X_{t} \,dB_{t} $$
and this simplifies to $$ \frac{1}{X_{t}}dX_{t} = \mu \,dt + \sigma \,dB_{t}.$$
Notice that the right hand side no longer depends on $X_{t}$. Now recall Ito's formula for a $C^{2,1}$ function $f(t,x)$ ($C^{2,1}$ means $f$ is twice differentiable in $x$ and once differentiable in $t$). Ito's formula tells us if $X_{t}$ satisfies the previous SDE, then $f(t,X_{t})$ will satisfy:
$$d(f(t,X_{t})) = \frac{\partial f}{\partial t}(t,X_{t}) \,dt + \frac{\partial f}{\partial x}(t,X{t}) \,dX_{t} + \frac{1}{2} \frac{\partial^{2} f}{\partial x^{2}}(t,X_{t}) \,d[X]_{t}$$
where $[X]_{t}$ is the quadratic variation process of $X_{t}$. Notice that in the SDE given to us by Ito's formula, one of the terms on the right hand size is $\frac{\partial f}{\partial x}(t,X{t}) \,dX_{t}$. This almost looks like our $\frac{1}{X_{t}} \,dX_{t}$, which was the left hand side of our original SDE. If we can choose $f(t,X_{t})$ wisely such that these are equal (i.e., such that $\frac{\partial f}{\partial x}(t,X{t})= \frac{1}{X_{t}}$, then we can solve this special SDE.
Hopefully you see that we should have $f(t,x) = \ln(x)$ for the above equality to hold. Okay, so since $f$ doesn't depend on $t$, let's call it $f(x)$ to save space. Substituting this $f$ into Ito's formula above gives:
$$d(\ln(X_{t})) = 0 \,dt + \frac{1}{X_{t}} \,dX_{t} - \frac{1}{2} \frac{1}{X_{t}^2} \,d[X]_{t}$$
Hmm... on the right hand side there is conveniently a $\frac{1}{X_{t}} \,dX_{t}$ (which was the whole point! That's why we choose $f$ as we did) and we have an SDE for this already. We have that $\frac{1}{X_{t}}dX_{t} = \mu \,dt + \sigma \,dB_{t}$.
Okay, so solving for $\frac{1}{X_{t}}\,dX_{t}$ in the Ito's formula SDE gives
$$\frac{1}{X_{t}} \,dX_{t} =d(\ln(X_{t})) + \frac{1}{2} \frac{1}{X_{t}^2} \,d[X]_{t} $$
and this allows us to set the right hand side of the above equal to $\mu \,dt + \sigma \,dB_{t}$. So we have $$d(\ln(X_{t})) + \frac{1}{2} \frac{1}{X_{t}^2} \,d[X]_{t} = \mu \,dt + \sigma \,dB_{t}. $$
What is $d[X]_{t}$? If you do the computation, you get $\sigma^{2} X_{t}^{2} \,dt$, so that our equation becomes $$d(\ln(X_{t})) + \frac{1}{2} \sigma^{2} \,dt = \mu \,dt + \sigma \,dB_{t}. $$
This simplifies to $$\ln(X_{t}) = \ln(X_{0}) + \int \limits_{0}^{t}(\mu - \frac{1}{2} \sigma^{2}) \,dt + \int \limits_{0}^{t}\sigma \,dB_{t} $$
so that $X_{t} = X_{0}e^{\int \limits_{0}^{t}(\mu - \frac{1}{2} \sigma^{2}) \,dt + \int \limits_{0}^{t}\sigma \,dB_{t}}$.
Best Answer
Actually, there is nothing left to do. From
$$dZ_t = b \exp \left( \frac{c^2}{2} t - c W_t \right) \, dt$$
it follows that
$$Z_t = \underbrace{Z_0}_{0} + b \int_0^t \exp \left( \frac{c^2}{2} s - c W_s \right) \, ds.$$
Hence,
$$X_t = Y_t \cdot Z_t = b \exp \left(- \frac{c^2}{2} t+c W_t \right) \cdot \int_0^t \exp \left( \frac{c^2}{2} s - c W_s \right) \, ds.$$