Fix INCREDIBLY stupid Windows bug (files named "con.*" are illegal!)

This commit is contained in:
Craig Everett 2020-01-23 23:37:14 +09:00
parent b60a0e182f
commit 96b6027942
11 changed files with 58 additions and 45 deletions

View File

@ -90,8 +90,10 @@ initialize(P = #project{type = lib, id = none}) ->
initialize(P = #project{id = none}) -> initialize(P = #project{id = none}) ->
ID = {_, Name, _} = ask_package_id(), ID = {_, Name, _} = ask_package_id(),
initialize(P#project{id = ID, appmod = Name}); initialize(P#project{id = ID, appmod = Name});
initialize(P = #project{prefix = none}) -> initialize(P = #project{type = app, id = {_, Name, _}, prefix = none}) ->
initialize(P#project{prefix = ask_prefix()}); initialize(P#project{prefix = ask_prefix(Name)});
initialize(P = #project{type = gui, id = {_, Name, _}, prefix = none}) ->
initialize(P#project{prefix = ask_prefix(Name)});
initialize(P = #project{type = app, appmod = none}) -> initialize(P = #project{type = app, appmod = none}) ->
initialize(P#project{appmod = ask_appmod()}); initialize(P#project{appmod = ask_appmod()});
initialize(P = #project{type = cli, appmod = none}) -> initialize(P = #project{type = cli, appmod = none}) ->
@ -1199,8 +1201,10 @@ create(P = #project{type = lib, id = none}) ->
create(P = #project{id = none}) -> create(P = #project{id = none}) ->
ID = {_, AppMod, _} = ask_package_id(), ID = {_, AppMod, _} = ask_package_id(),
create(P#project{id = ID, appmod = AppMod}); create(P#project{id = ID, appmod = AppMod});
create(P = #project{prefix = none}) -> create(P = #project{type = app, id = {_, Name, _}, prefix = none}) ->
create(P#project{prefix = ask_prefix()}); create(P#project{prefix = ask_prefix(Name)});
create(P = #project{type = gui, id = {_, Name, _}, prefix = none}) ->
create(P#project{prefix = ask_prefix(Name)});
create(P = #project{type = app, appmod = none}) -> create(P = #project{type = app, appmod = none}) ->
create(P#project{appmod = ask_appmod()}); create(P#project{appmod = ask_appmod()});
create(P = #project{type = gui, appmod = none}) -> create(P = #project{type = gui, appmod = none}) ->
@ -1733,20 +1737,29 @@ ask_package_id3(Realm, Name) ->
end. end.
-spec ask_prefix() -> string(). -spec ask_prefix(zx:name()) -> string().
%% @private %% @private
%% Get a valid module prefix to use as a namespace for new modules. %% Get a valid module prefix to use as a namespace for new modules.
ask_prefix() -> ask_prefix(Name) ->
Default =
case string:split(Name, "_", all) of
Name -> Name;
Parts -> lists:reverse(lists:map(fun erlang:hd/1, Parts))
end,
Instructions = Instructions =
"~nPICKING A PREFIX~n" "~nPICKING A PREFIX~n"
"Most projects use a prefix with a trailing underscore to namespace their " "projects use a prefix with a trailing underscore as module namespaces.~n"
"modules. For example, example_server uses the module prefix \"es_\" " "Names are usually either the project name (if it is short), or an "
"internally.~n" "abbreviation of the project name.~n"
"This is optional.~n", "For example, example_server uses the module prefix \"es\", so many files "
case zx_tty:get_input(Instructions, [], "[ENTER] to leave blank") of "in the project are named things like \"es_client\".~n"
"Enter the prefix you would like to use below (or enter for the generated "
"default).~n",
ok = io:format(Instructions),
case zx_tty:get_input("[\"~ts\"]", [Default]) of
"" -> "" ->
""; Default;
String -> String ->
case zx_lib:valid_lower0_9(String) of case zx_lib:valid_lower0_9(String) of
true -> true ->
@ -1754,7 +1767,7 @@ ask_prefix() ->
false -> false ->
Message = "The string \"~ts\" isn't valid. Try \"[a-z0-9_]*\".~n", Message = "The string \"~ts\" isn't valid. Try \"[a-z0-9_]*\".~n",
ok = io:format(Message, [String]), ok = io:format(Message, [String]),
ask_prefix() ask_prefix(Name)
end end
end. end.

View File

@ -64,7 +64,7 @@ start(PortNum) ->
%% See: http://erlang.org/doc/apps/kernel/application.html %% See: http://erlang.org/doc/apps/kernel/application.html
start(normal, _Args) -> start(normal, _Args) ->
*PREFIX*sup:start_link(). *PREFIX*_sup:start_link().
-spec stop(term()) -> ok. -spec stop(term()) -> ok.

View File

@ -13,7 +13,7 @@
%%% http://erlang.org/doc/design_principles/spec_proc.html %%% http://erlang.org/doc/design_principles/spec_proc.html
%%% @end %%% @end
-module(*PREFIX*client). -module(*PREFIX*_client).
-vsn("〘*VERSION*〙"). -vsn("〘*VERSION*〙").
*AUTHOR* *AUTHOR*
*COPYRIGHT* *COPYRIGHT*

View File

@ -9,7 +9,7 @@
%%% OTP should take care of for us. %%% OTP should take care of for us.
%%% @end %%% @end
-module(*PREFIX*client_man). -module(*PREFIX*_client_man).
-vsn("〘*VERSION*〙"). -vsn("〘*VERSION*〙").
-behavior(gen_server). -behavior(gen_server).
*AUTHOR* *AUTHOR*

View File

@ -13,7 +13,7 @@
%%% http://erlang.org/doc/design_principles/sup_princ.html#id79244 %%% http://erlang.org/doc/design_principles/sup_princ.html#id79244
%%% @end %%% @end
-module(*PREFIX*client_sup). -module(*PREFIX*_client_sup).
-vsn("〘*VERSION*〙"). -vsn("〘*VERSION*〙").
-behaviour(supervisor). -behaviour(supervisor).
*AUTHOR* *AUTHOR*
@ -35,8 +35,8 @@
| {shutdown, term()} | {shutdown, term()}
| term(). | term().
%% @private %% @private
%% Spawns the first listener at the request of the *PREFIX*client_man when es:listen/1 %% Spawns the first listener at the request of the *PREFIX*_client_man when es:listen/1
%% is called, or the next listener at the request of the currently listening *PREFIX*client %% is called, or the next listener at the request of the currently listening *PREFIX*_client
%% when a connection is made. %% when a connection is made.
%% %%
%% Error conditions, supervision strategies and other important issues are %% Error conditions, supervision strategies and other important issues are
@ -61,10 +61,10 @@ start_link() ->
init(none) -> init(none) ->
RestartStrategy = {simple_one_for_one, 1, 60}, RestartStrategy = {simple_one_for_one, 1, 60},
Client = {*PREFIX*client, Client = {*PREFIX*_client,
{*PREFIX*client, start_link, []}, {*PREFIX*_client, start_link, []},
temporary, temporary,
brutal_kill, brutal_kill,
worker, worker,
[*PREFIX*client]}, [*PREFIX*_client]},
{ok, {RestartStrategy, [Client]}}. {ok, {RestartStrategy, [Client]}}.

View File

@ -3,12 +3,12 @@
%%% %%%
%%% This is the service-level supervisor of the system. It is the parent of both the %%% This is the service-level supervisor of the system. It is the parent of both the
%%% client connection handlers and the client manager (which manages the client %%% client connection handlers and the client manager (which manages the client
%%% connection handlers). This is the child of *PREFIX*sup. %%% connection handlers). This is the child of *PREFIX*_sup.
%%% %%%
%%% See: http://erlang.org/doc/apps/kernel/application.html %%% See: http://erlang.org/doc/apps/kernel/application.html
%%% @end %%% @end
-module(*PREFIX*clients). -module(*PREFIX*_clients).
-vsn("〘*VERSION*〙"). -vsn("〘*VERSION*〙").
-behavior(supervisor). -behavior(supervisor).
*AUTHOR* *AUTHOR*
@ -32,17 +32,17 @@ start_link() ->
init(none) -> init(none) ->
RestartStrategy = {rest_for_one, 1, 60}, RestartStrategy = {rest_for_one, 1, 60},
ClientSup = {*PREFIX*client_sup, ClientSup = {*PREFIX*_client_sup,
{*PREFIX*client_sup, start_link, []}, {*PREFIX*_client_sup, start_link, []},
permanent, permanent,
5000, 5000,
supervisor, supervisor,
[*PREFIX*client_sup]}, [*PREFIX*_client_sup]},
ClientMan = {*PREFIX*client_man, ClientMan = {*PREFIX*_client_man,
{*PREFIX*client_man, start_link, []}, {*PREFIX*_client_man, start_link, []},
permanent, permanent,
5000, 5000,
worker, worker,
[*PREFIX*client_man]}, [*PREFIX*_client_man]},
Children = [ClientSup, ClientMan], Children = [ClientSup, ClientMan],
{ok, {RestartStrategy, Children}}. {ok, {RestartStrategy, Children}}.

View File

@ -11,7 +11,7 @@
%%% See: http://zxq9.com/archives/1311 %%% See: http://zxq9.com/archives/1311
%%% @end %%% @end
-module(*PREFIX*sup). -module(*PREFIX*_sup).
-vsn("〘*VERSION*〙"). -vsn("〘*VERSION*〙").
-behaviour(supervisor). -behaviour(supervisor).
*AUTHOR* *AUTHOR*
@ -36,11 +36,11 @@ start_link() ->
init([]) -> init([]) ->
RestartStrategy = {one_for_one, 1, 60}, RestartStrategy = {one_for_one, 1, 60},
Clients = {*PREFIX*clients, Clients = {*PREFIX*_clients,
{*PREFIX*clients, start_link, []}, {*PREFIX*_clients, start_link, []},
permanent, permanent,
5000, 5000,
supervisor, supervisor,
[*PREFIX*clients]}, [*PREFIX*_clients]},
Children = [Clients], Children = [Clients],
{ok, {RestartStrategy, Children}}. {ok, {RestartStrategy, Children}}.

View File

@ -28,7 +28,7 @@
%% See: http://erlang.org/doc/apps/kernel/application.html %% See: http://erlang.org/doc/apps/kernel/application.html
start(normal, _Args) -> start(normal, _Args) ->
*PREFIX*sup:start_link(). *PREFIX*_sup:start_link().
-spec stop(term()) -> ok. -spec stop(term()) -> ok.

View File

@ -4,7 +4,7 @@
%%% This process is a in charge of maintaining the program's state. %%% This process is a in charge of maintaining the program's state.
%%% @end %%% @end
-module(*PREFIX*con). -module(*PREFIX*_con).
-vsn("〘*VERSION*〙"). -vsn("〘*VERSION*〙").
*AUTHOR* *AUTHOR*
*COPYRIGHT* *COPYRIGHT*
@ -46,7 +46,7 @@ stop() ->
| {shutdown, term()} | {shutdown, term()}
| term(). | term().
%% @private %% @private
%% Called by *PREFIX*sup. %% Called by *PREFIX*_sup.
start_link() -> start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, none, []). gen_server:start_link({local, ?MODULE}, ?MODULE, none, []).
@ -56,11 +56,11 @@ start_link() ->
init(none) -> init(none) ->
ok = log(info, "Starting"), ok = log(info, "Starting"),
Window = *PREFIX*gui:start_link("Hello, WX!"), Window = *PREFIX*_gui:start_link("Hello, WX!"),
ok = log(info, "Window: ~p", [Window]), ok = log(info, "Window: ~p", [Window]),
State = #s{window = Window}, State = #s{window = Window},
ArgV = zx_daemon:argv(), ArgV = zx_daemon:argv(),
ok = *PREFIX*gui:show(ArgV), ok = *PREFIX*_gui:show(ArgV),
{ok, State}. {ok, State}.

View File

@ -6,7 +6,7 @@
%%% Reference: http://erlang.org/doc/man/wx_object.html %%% Reference: http://erlang.org/doc/man/wx_object.html
%%% @end %%% @end
-module(*PREFIX*gui). -module(*PREFIX*_gui).
-vsn("〘*VERSION*〙"). -vsn("〘*VERSION*〙").
*AUTHOR* *AUTHOR*
*COPYRIGHT* *COPYRIGHT*
@ -113,7 +113,7 @@ handle_info(Unexpected, State) ->
%% See: http://erlang.org/doc/man/gen_server.html#Module:handle_info-2 %% See: http://erlang.org/doc/man/gen_server.html#Module:handle_info-2
handle_event(#wx{event = #wxClose{}}, State = #s{frame = Frame}) -> handle_event(#wx{event = #wxClose{}}, State = #s{frame = Frame}) ->
ok = *PREFIX*con:stop(), ok = *PREFIX*_con:stop(),
ok = wxWindow:destroy(Frame), ok = wxWindow:destroy(Frame),
{noreply, State}; {noreply, State};
handle_event(Event, State) -> handle_event(Event, State) ->

View File

@ -11,7 +11,7 @@
%%% See: http://zxq9.com/archives/1311 %%% See: http://zxq9.com/archives/1311
%%% @end %%% @end
-module(*PREFIX*sup). -module(*PREFIX*_sup).
-vsn("〘*VERSION*〙"). -vsn("〘*VERSION*〙").
-behaviour(supervisor). -behaviour(supervisor).
*AUTHOR* *AUTHOR*
@ -36,11 +36,11 @@ start_link() ->
init([]) -> init([]) ->
RestartStrategy = {one_for_one, 0, 60}, RestartStrategy = {one_for_one, 0, 60},
Clients = {*PREFIX*con, Clients = {*PREFIX*_con,
{*PREFIX*con, start_link, []}, {*PREFIX*_con, start_link, []},
permanent, permanent,
5000, 5000,
worker, worker,
[*PREFIX*con]}, [*PREFIX*_con]},
Children = [Clients], Children = [Clients],
{ok, {RestartStrategy, Children}}. {ok, {RestartStrategy, Children}}.